JSPM

get-first

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 209
  • Score
    100M100P100Q81336F
  • License MIT

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.

Package Exports

  • get-first

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (get-first) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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'

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.