Skip to content

Commit

Permalink
Bye bye, SteelToe
Browse files Browse the repository at this point in the history
  • Loading branch information
5outh committed Feb 17, 2015
1 parent 8eb583a commit fbfe379
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -23,8 +23,7 @@
},
"homepage": "https://github.com/5outh/nanoscope",
"dependencies": {
"lodash": "^2.4.1",
"steeltoe": "^1.0.1"
"lodash": "^2.4.1"
},
"devDependencies": {
"chai": "^1.10.0",
Expand Down
19 changes: 6 additions & 13 deletions src/object/PathLens.js
Expand Up @@ -20,7 +20,6 @@
* @private
*/
var _ = require('lodash'),
steelToe = require('steeltoe'),

Lens = require('../base/Lens'),

Expand All @@ -39,24 +38,18 @@ var _ = require('lodash'),
* @returns {Function}
*/
get = function (path, unsafe) {
if (!unsafe) {
// Just use steelToe to safely access element
return function (obj) {
return steelToe(obj).get(path) || null;
};
}

// If unsafe, split the path and follow it without regard for errors.
if (_.isString(path)) {
path = path.split('.');
}

return function (obj) {
_.forEach(path, function (key) {
obj = obj[key];
});
// Accumulation function to produce the final result
var reduction = function (acc, key) {
return unsafe ? acc[key] : (acc && acc[key] || null);
};

return obj;
// Perform the reduction and return the result
return _.reduce(path, reduction, obj);
};
};

Expand Down

0 comments on commit fbfe379

Please sign in to comment.