Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
The pathval npm package is a utility for working with object paths. It allows you to get and set values on an object using a string path, which is useful for accessing deeply nested properties.
Get value from object
This feature allows you to retrieve a value from a nested object using a string path.
{"const pathval = require('pathval');
const obj = { a: { b: { c: 'd' } } };
const value = pathval.get(obj, 'a.b.c');
console.log(value); // Output: 'd'"}
Set value on object
This feature allows you to set a value on a nested object using a string path, creating any necessary sub-objects along the path.
{"const pathval = require('pathval');
const obj = {};
pathval.set(obj, 'a.b.c', 'd');
console.log(obj); // Output: { a: { b: { c: 'd' } } }"}
lodash.get is a method from the Lodash library that retrieves the value at a given path of an object. It is similar to pathval's get functionality but is part of a larger utility library.
dot-prop is a package that allows you to get, set, or delete properties from a nested object using a dot path. It is similar to pathval but also includes delete functionality.
object-path is a package that provides a full set of methods to manage paths on objects, including get, set, push, ensure, and more. It offers a broader feature set compared to pathval.
var props = require('pathval');
Given:
var obj = {
prop1: {
arr: ['a', 'b', 'c']
, str: 'Hello'
}
, prop2: {
arr: [ { nested: 'Universe' } ]
, str: 'Hello again!'
}
}
var arr = [ { foo: 'bar' } ];
Expect:
props.get(obj, 'prop1.str'); // => "Hello"
props.get(obj, 'prop1.arr[2]'); // => "c"
props.get(obj, 'prop2.arr[0].nested'); // => "Universe"
props.get(arr, '[0].foo'); // => "bar"
props.get(undefined, 'doesnt.matter'); // => undefined
props.get({}, 'doesnt.exist'); // => undefined
props.set(obj, 'hello.universe', 'properties');
props.set(obj, 'hello.universe[1].properties', 'galaxy');
props.set(obj, 'hello', 'universe');
props.set(obj, 'hello[0]', 1);
props.set(obj, 'hello[2]', 3);
npm install pathval
$ npm test
$ npm run-script coverage
$ npm run-script test-readme
MIT License
Copyright (c) 2011-2013 Jake Luer jake@alogicalparadox.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Object value retrieval given a string path
The npm package pathval receives a total of 5,966,792 weekly downloads. As such, pathval popularity was classified as popular.
We found that pathval demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
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.