@ngard/tiny-pick
v1.0.0
Published
A minimal-weight utility equivalent to lodash.pick
Downloads
2
Readme
tiny-pick
A minimal utility equivalent to lodash.pick
. For when every byte counts!
Install
npm install @ngard/tiny-pick
Syntax
pick(/* source, key [, key2, ...] */);
Parameters
source
- [Object|Array]
The object whose key/value pairs will be picked.
key [, key2, ...]
- [String|Array<String>]
An array or list of key names.
Returns
An object comprised of the picked key/value pairs.
Example
import { pick } from '@ngard/tiny-pick';
const character = {
name: 'Luke Skywalker',
description: 'whiny Jedi',
planet: 'Tatooine',
system: 'Jabak',
}
const bio = pick(character, 'name', 'description');
// { name: 'Luke Skywalker', description: 'whiny Jedi' }
const address = pick(character, ['planet', 'system']);
// { planet: 'Tatooine', system: 'Jabak' }
/* Picking Arrays */
pick(['a', 'b', 'c'], 0, 2); // { 0: 'a', 2: 'c' }