expand-value

1.0.0 • Public • Published

expand-value NPM version NPM monthly downloads NPM total downloads

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 ❤️ 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

Contributing

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 Tests

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
Building docs

(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.

Package Sidebar

Install

npm i expand-value

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

19.6 kB

Total Files

13

Last publish

Collaborators

  • jonschlinkert