You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

object.pickomit

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object.pickomit

Returns a copy of the object based on which object properties are included or excluded.

1.1.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

object.pickomit npm

Returns a copy of the object based on which object properties are included or excluded. If the key has a - in front, it is marked excluded, otherwise it is marked as included. Also can be specified which properties will be included by default.

Install

Install with npm:

$ npm i object.pickomit

Usage

const pickOmit = require('object.pickomit');

To pick or omit, pass the keys as an array:

pickOmit.select({ a: 'a', b: 'b', c: 'c', d: 'd' }, ['a', 'b'])
// pick => { a: 'a', b: 'b' }

pickOmit.select({ a: 'a', b: 'b', c: 'c', d: 'd' }, ['-a', '-b'])
// omit => { c: 'c', d: 'd' }

keys can also be pass as string.

pickOmit.select({ a: 'a', b: 'b', c: 'c', d: 'd' }, 'a b')
// pick => { a: 'a', b: 'b' }

pickOmit.select({ a: 'a', b: 'b', c: 'c', d: 'd' }, '-a -b')
// omit => { c: 'c', d: 'd' }

Throws an error if pick and omit keys are passed together.

pickOmit.select({ a: 'a', b: 'b', c: 'c', d: 'd' }, 'a -b')
// Error: Keys cannot have a mix of inclusion and exclusion.

setDefaultPicks

It sets the keys to be picked by default even if they are not passed as parameters. Keys can be passed as string or arrays as above.

const pickOmit = require('object.pickomit').setDefaultPicks('a b');

pickOmit.select({ a: 'a', b: 'b', c: 'c', d: 'd' }, 'd')
// => { a: 'a', b: 'b', d: 'd' }

If the default pick keys are not wanted to be included, they are passed with a - in front of the key.

pickOmit.select({ a: 'a', b: 'b', c: 'c', d: 'd' }, '-a d')
// => { b: 'b', d: 'd' }

Author

Furkan Işıtan

License

Copyright © 2020, Furkan Işıtan Released under the MIT License.

Keywords

omit

FAQs

Package last updated on 22 Dec 2020

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