@ngard/tiny-pick

1.0.0 • Public • Published

tiny-pick

source bundle size build status license

A minimal utility equivalent to lodash.pick. For when every byte counts!


lodash.pick: bundle size
tiny-pick: bundle size


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' }

Readme

Keywords

Package Sidebar

Install

npm i @ngard/tiny-pick

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

12.2 kB

Total Files

8

Last publish

Collaborators

  • ngard