
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
object.pickomit
Advanced tools
Returns a copy of the object based on which object properties are included or excluded.
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 with npm:
$ npm i object.pickomit
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.
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' }
Furkan Işıtan
Copyright © 2020, Furkan Işıtan Released under the MIT License.
FAQs
Returns a copy of the object based on which object properties are included or excluded.
We found that object.pickomit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.