expand-value
v1.0.0
Published
Expand deeply nested values from an object, with support for advanced features.
Downloads
25
Maintainers
Readme
expand-value
Expand deeply nested values from an object, with support for advanced features.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install
Install with npm (requires Node.js >=14):
$ npm install --save expand-value
Usage
Similar to get-value and dot-prop (and passes all of the get-value
unit tests), but supports more complex expressions for accessing deeply nested properties. For example, this library is used by Dry for resolving values in expressions in user-defined templates.
const expand = require('expand-value');
const data = { user: { name: 'Brian' }, key: 'name' };
console.log(expand(data, 'user.name')) //=> 'Brian'
console.log(expand(data, 'user["name"]')) //=> 'Brian'
console.log(expand(data, 'user[key]')) //=> 'Brian'
console.log(expand({ foo: { bar: { baz: 'correct' } } }, 'foo["bar"].baz')); //=> 'correct'
.parse
const { parse } = require('expand-value);
const { ast } = parse('a.b.c');
console.log(ast);
// results in
{
type: 'root',
nodes: [
{ type: 'ident', value: 'a' },
{ type: 'separator', value: '.' },
{ type: 'ident', value: 'b' },
{ type: 'separator', value: '.' },
{ type: 'ident', value: 'c' }
]
}
About
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Author
Jon Schlinkert
License
Copyright © 2021, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on July 20, 2021.