Commit project
This commit is contained in:
parent
28471965a0
commit
3ac017a5ad
1030 changed files with 94062 additions and 0 deletions
33
node_modules/undefsafe/lib/undefsafe.js
generated
vendored
Normal file
33
node_modules/undefsafe/lib/undefsafe.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
function undefsafe(obj, path) {
|
||||
var parts = path.split('.');
|
||||
var key = null;
|
||||
var type = typeof obj;
|
||||
|
||||
// we're dealing with a primative
|
||||
if (type !== 'object' && type !== 'function') {
|
||||
return obj;
|
||||
} else if (path.trim() === '') {
|
||||
return obj;
|
||||
}
|
||||
|
||||
while ((key = parts.shift())) {
|
||||
obj = obj[key];
|
||||
if (obj === undefined || obj === null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we have a null object, make sure it's the one the user was after,
|
||||
// if it's not (i.e. parts has a length) then give undefined back.
|
||||
if (obj === null && parts.length !== 0) {
|
||||
obj = undefined;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = undefsafe;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue