Skip to content

gbenvenuti/cherrypick

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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, 'greetings:hello things.whatsits:stuff');

->

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

About

cherrypick props off an object

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%