Skip to content

shake

Remove unwanted values from an object

120 bytes

Usage

Returns a new object without the properties that are undefined. Note that non-enumerable keys are never shaken out.

import * as _ from 'radashi'
const options = _.shake({
mode: 'party',
volume: undefined,
dancing: false,
snacks: null,
})
// => { mode: 'party', dancing: false, snacks: null }

Custom Condition

If you pass a function as the second argument, only the properties that return false will be included in the result.

import * as _ from 'radashi'
const options = _.shake(
{
mode: 'party',
volume: undefined,
dancing: false,
snacks: null,
},
value => !value,
)
// => { mode: 'party' }