Skip to content

🐒🍞 lodash mixin for deep immutable destructuring with omit

License

Notifications You must be signed in to change notification settings

busterc/lodash-pickapart

Repository files navigation

lodash-pickapart NPM version Build Status Dependency Status Coverage percentage

lodash mixin for deep immutable destructuring with omit

Installation

$ npm install --save lodash-pickapart

Usage

const _ = require('lodash');
require('lodash-pickapart')(_);

// Now Available: _.pickapart(paths, source)
// * paths: String|Array (optional, if source is an Array)
// * source: Object|Array

const payload = { name: 'abc', meta: { token: 123, easy: true } };

const [token, data] = _.pickapart('meta.token', payload);
console.log('=> ', payload);
// => { name: 'abc', meta: { token: 123, easy: true }}
console.log('=> ', token);
// => 123
console.log('=> ', data);
// => { name: 'abc', meta: { easy: true }}

const [is, ez] = _.pickapart(['name', 'meta.easy'], payload);
console.log('=> ', is);
// => 'abc'
console.log('=> ', ez);
// => true

const flavors = ['chocolate', 'vanilla', 'strawberry'];

const [plain, others] = _.pickapart('[1]', flavors);
console.log('=> ', plain);
// => 'vanilla'
console.log('=> ', others);
// => [ 'chocolate', 'strawberry' ]

const [choco, notChoco] = _.pickapart(flavors);

console.log('=> ', choco);
// => 'chocolate'
console.log('=> ', notChoco);
// => [ 'vanilla', 'strawberry' ]

License

ISC © Buster Collings

About

🐒🍞 lodash mixin for deep immutable destructuring with omit

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published