🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

deepdo

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deepdo

Mess with the properties of deeply nested objects.

0.1.2
latest
Source
npm
Version published
Weekly downloads
3
50%
Maintainers
1
Weekly downloads
 
Created
Source

Synopsis

deepdo lets you mess with deeply nested objects.

license - MIT Flattr this

Dependencies

NPM status

API

To support arbitrarily nested properties, keys can be defined as paths using the dot (".") as path separator and the asterisk ("*") as a wildcard to match any property name. If you need to use keys that would normally contain a dot or asterisk, you can escape these characters using the backslash ("\\"), i.e. "\\." and "\\*".

deepdo.pick(keys:Array, source):*

Returns a new object that is a copy of source with only the properties specified in keys.

If source is an array, a new array will be returned instead of an object.

If keys is a string, it will be wrapped in an array automatically.

Examples

var noisyData = {
    success: true,
    data: {
        meta: true,
        secrets: 'interesting'
    },
    lies: 'filthy lies',
};
var whatWeWant = deepdo.pick(['data.secrets', 'lies'], noisyData);
console.log(whatWeWant);
/*
{
    data: {
        secrets: 'interesting'
    },
    lies: 'filthy lies'
}
*/

deepdo.omit(keys:Array, source):*

Returns a new object that is a copy of source without the properties specified in keys.

If source is an array, a new array will be returned instead of an object.

If keys is a string, it will be wrapped in an array automatically.

Examples

var noisyData = {
    success: true,
    data: {
        meta: true,
        secrets: 'interesting'
    },
    lies: 'filthy lies',
};
var whatWeWant = deepdo.omit(['data.meta', 'success'], noisyData);
console.log(whatWeWant);
/*
{
    data: {
        secrets: 'interesting'
    },
    lies: 'filthy lies'
}
*/

deepdo.mutate(map, source):source

Applies the given transformation map on the source and modifies it in-place. Returns the modified source.

The map can be either an object mapping keys to functions that should be executed on each matching property or an array of key/function tuples.

Examples

var thing = {
    names: ['foo', 'bar', 'qux'],
    color: 'blue',
    some: {
        deep: {stuff: 'here'},
        more: {stuff: 'also'}
    }
};
var result = deepdo.mutate({
    'names.*': function (str) {return str.toUpperCase();},
    'color': function () {return 'yellow';},
    'some.*.stuff': function () {return 'chicken';}
}, thing);
console.log(result === thing); // true
console.log(thing);
/*
{
    names: ['FOO', 'BAR', 'QUX'],
    color: 'yellow',
    some: {
        deep: {stuff: 'chicken'},
        more: {stuff: 'chicken'}
    }
}
*/

License

The MIT/Expat license. For more information, see http://pluma.mit-license.org/ or the accompanying LICENSE file.

Keywords

omit

FAQs

Package last updated on 23 Oct 2014

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