mirror of
https://github.com/Raghu-Ch/nodeRestAPI.git
synced 2026-02-10 12:43:02 -05:00
initial commit
This commit is contained in:
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;
|
||||
}
|
||||
Reference in New Issue
Block a user