pick-deep
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/pick-deep package

1.0.0 • Public • Published

pick-deep License npm

Build Status node Test Coverage bitHound Score

One of the smallest (28 sloc) and most effective implementations of object properties deep picking.

Usage

$ npm install pick-deep --save
const pick = require('pick-deep');
 
pick({ a: { b: ['c', 'd'], e: 'f' } }, 'a.b');
pick({ a: { b: ['c', 'd'], e: 'f' } }, ['a.b']);
pick({ a: { b: ['c', 'd'], e: 'f' } }, [['a', 'b']]);
//=> { a: { b: ['c', 'd'] } }
 
pick({ a: { b: ['c', 'd'], e: 'f' }, j: { k: 'l' }, q: { r: ['s', 't'], u: 'w' }}, [['a', 'b'], 'j', 'q.u']);
//=> { a: { b: ['c', 'd'] }, j: { k: 'l' }, q: { u: 'w' }}
 
pick({ a: { b: 'c' } }, 'a.b.c.d');
//=> {}
 
pick({ a: { b: 'c' } }, 'a:b', ':');
//=> { a: { b: 'c' } }

API

pick(obj, paths, [separator])

Params:

  • obj (Object) - Source object.
  • paths (String|Array|Array of Arrays) - String, array or array of arrays with paths.
  • [separator] (String) - . by default.

Related

  • @strikeentco/get - One of the smallest and most effective implementations of getting a nested value from an object.
  • @strikeentco/set - One of the smallest and most effective implementations of setting a nested value on an object.

License

The MIT License (MIT)
Copyright (c) 2018 Alexey Bystrov

Package Sidebar

Install

npm i pick-deep

Weekly Downloads

3,007

Version

1.0.0

License

MIT

Unpacked Size

5.62 kB

Total Files

4

Last publish

Collaborators

  • strikeentco