Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Get or set a object values from a keypath string. Supports bracket notation, dot notation, and functions
Get or set a object values from a keypath string. Supports bracket notation, dot notation, and functions
npm install keypather
dot notation, bracket notation, and functions all supported:
var keypath = require('keypather')();
var obj = {
foo: {
bar: {
baz: 'val'
}
}
};
keypath.get(obj, "foo.bar.baz"); // val
keypath.get(obj, "['foo']['bar']['baz']"); // val
var keypath = require('keypather')();
var obj = {
foo: function () {
return function () {
return function () {
return 'val';
};
};
}
};
keypath.get(obj, "foo()()()"); // val
var keypath = require('keypather')();
var obj = {
foo: function () {
return {
bar: {
baz: 'val'
}
};
}
};
keypath.get(obj, "foo()['bar'].baz"); // val
Get returns null for keypaths that do not exist by default,
but can also throw errors with { force: false }
var keypath = require('keypather')(); // equivalent to { force:true }
var obj = {};
keypath.get(obj, "foo.bar.baz"); // null
var keypath = require('keypather')( force: false );
var obj = {};
keypath.get(obj, "foo.bar.baz");
// throw's an error
// Error: Cannot get 'foo' of undefined
mixed notation, dot notation, and bracket notation all supported:
var keypath = require('keypather')();
var obj = {
foo: {
bar: {
baz: 'val'
}
}
}
};
keypath.set(obj, "foo['bar'].baz", 'value'); // value
keypath.set(obj, "foo.bar.baz", 'value'); // value
keypath.set(obj, "['foo']['bar']['baz']", 'value'); // value
Set forces creation by default:
var keypath = require('keypather')(); // equivalent to { force:true }
var obj = {};
keypath.set(obj, "foo.bar.baz", 'val'); // value
// obj = {
// foo: {
// bar: {
// baz: 'val'
// }
// }
// };
var keypath = require('keypather')( force: false );
var obj = {};
keypath.set(obj, "foo.bar.baz", 'val');
// throw's an error
// Error: Cannot get 'foo' of undefined
FAQs
Get or set a deep value using a keypath string. Supports bracket and dot notation
The npm package keypather receives a total of 15,578 weekly downloads. As such, keypather popularity was classified as popular.
We found that keypather demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.