get-first
Pass an array of object paths (e.g. `a.b.c`) and get the first non-undefined value if the property exists, or null if it does not.
Last updated 4 years ago by doowb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install get-first 
SYNC missed versions from official npm registry.

get-first NPM version

Pass an array of object paths (e.g. a.b.c) and get the first non-undefined value if the property exists, or null if it does not.

Install

Install with npm:

$ npm i get-first

Run tests

npm test

Usage

var getFirst = require('get-first');

getFirst({a: 'b'}, 'a');
//=> 'b'

getFirst({a: 'b'}, ['a']);
//=> 'b'

getFirst({a: {b: 'c'}}, 'a.b');
//=> 'c'

getFirst({a: {b: 'c'}}, ['a.b']);
//=> 'c'

getFirst({a: {b: 'c'}, x: {b: 'd'}}, ['a.b', 'x.b']);
//=> 'c'

getFirst({a: {b: 'c'}, x: {b: 'd'}}, ['x.b', 'a.b']);
//=> 'd'

getFirst({a: {b: {c: 'd'}}}, ['a.b', 'x.y.z']);
//=> {c: 'd'}

getFirst({a: {b: {c: 'd'}, e: 'f'}}, ['a.c', 'a.e']);
//=> 'f'

Related

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2016 Jon Schlinkert Released under the MIT license.


This file was generated by verb on January 18, 2016.

Current Tags

  • 0.1.2                                ...           latest (4 years ago)

3 Versions

  • 0.1.2                                ...           4 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (2)
Downloads
Today 1
This Week 1
This Month 7
Last Day 0
Last Week 9
Last Month 45
Dependencies (1)
Dev Dependencies (1)

Copyright 2014 - 2016 © taobao.org |