Skip to content

Commit

Permalink
update code base
Browse files Browse the repository at this point in the history
  • Loading branch information
0xvoidmain committed Dec 2, 2016
1 parent 55d3971 commit b2223bc
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,30 @@ var hasOwnProp = Object.prototype.hasOwnProperty;

function get(obj, path) {
var result = null;
try {
var keys = parsePath(path);
result = obj
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (!result || !hasOwnProp.call(result, key)) {
result = undefined;
break;
}
result = result[key];
var keys = parsePath(path);
result = obj
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (!result || !hasOwnProp.call(result, key)) {
result = undefined;
break;
}
return result;
} catch (ex) {
console.log(ex);
return undefined;
result = result[key];
}
return result;
}

function set(obj, path, value) {
try {
var keys = parsePath(path);
for (var i = 0; i < keys.length - 1; i++) {
var key = keys[i];
if (!hasOwnProp.call(obj, key)) {
return false;
};
obj = obj[key];
}
obj[keys[i]] = value;
return true;
} catch (ex) {
return false;
var keys = parsePath(path);
for (var i = 0; i < keys.length - 1; i++) {
var key = keys[i];
if (!hasOwnProp.call(obj, key)) {
return false;
};
obj = obj[key];
}
obj[keys[i]] = value;
return true;
}

module.exports = {
Expand Down

0 comments on commit b2223bc

Please sign in to comment.