NASA Keypath Module
New Age Keypath Traversal Technology. Traverse and manipulate Objects with ease using the newfangled string dot notation all the kids are raving about!
Installation
npm install nasa-keypath
or include index.js
in your browser.
Utilization
References
var keypath = require('nasa-keypath');
var on = {
users: [
{ _id: '290682069820139', password: 'something-unique' },
{ _id: '908164718613492', password: 'something-unique', admin: true }
],
count: {
total: 2,
admins: 1
}
};
This code has no real meaning, only to show the power of what keypath can do.
Functional
keypath.remove(on, 'users.[].password');
keypath.set(on, 'users.[].activated', true);
keypath.get(on, 'users.0.admin');
keypath.get(on, 'users.[].admin', true);
keypath.get(on, 'count.admins');
keypath.set(on, 'count', keypath.get(on, 'users').length);
OOP
var path = keypath(on);
path.remove('users.[].password');
path.set('users.[].activated', true);
path.get('users.0.admin');
path.get('users.[].admin', true);
path.get('count.admins');
path.set('count', path.get('users').length);