🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

cherrypick

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cherrypick

Cherrypick properties off an object

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

cherrypick

cherrypick props off an object

What

Check out the example

Example

Grab it:

var cherrypick = require('cherrypick');

Use it:

var someObject = {
    a:1,
    b:2,
    c:3
};

var picked = cherrypick(someObject, 'a b');

picked will be:

{
    a:1,
    b:2
}

You can switch to exclude mode by passing true as the second parameter:

var someObject = {
    a:1,
    b:2,
    c:3
};

var picked = cherrypick(someObject, true, 'a b');

picked will be:

{
    c:3
}

You can also pick on dot-notated deeply nested keys:

var someObject = {
    a:1,
    b:2,
    c:3,
    d:{
      e:{
            g:4
        },
        f:{
            h:2
        }
    }
};

var picked = cherrypick(someObject, 'a d.e.g');

And you can change the name of keys using a tuple syntax:

var someObject = {
    hello: 'world',
    things:{
        stuff: 'majigger'
    }
};

var picked = cherrypick(someObject, 'hello:greetings things.stuff:things.whatsits');

->

{
    greetings: 'world',
    things:{
        whatsits: 'majigger'
    }
}

Breaking changes from v1 to v2

the rename/tuple syntax has changed to be much less confusing.

old:

per key: putHere:fromHere

var obj = {a:1,b:2,c:3,d:{e:4}};

t.cherrypick(obj, 'a c g:d.z:e'); -> {a:1, c:3, g:{z:4}}

new:

per path: take.from.here:put.it.here

var obj = {a:1,b:2,c:3,d:{e:4}};

cherrypick(obj, 'a c d.e:g.z'); -> {a:1, c:3, g:{z:4}}

FAQs

Package last updated on 21 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts