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 import _
_ from 'radashi'
const const options: { mode: string; volume: never; dancing: boolean; snacks: null;}
options = import _
_.shake<{ mode: string; volume: undefined; dancing: boolean; snacks: null;}>(obj: { mode: string; volume: undefined; dancing: boolean; snacks: null;}): { mode: string; volume: never; dancing: boolean; snacks: null;} (+1 overload)export shake
Removes (shakes out) undefined entries from an object. Optional
second argument shakes out values by custom evaluation.
Note that non-enumerable keys are never shaken out.
shake({ mode: string
mode: 'party', volume: undefined
volume: var undefined
undefined, dancing: boolean
dancing: false, snacks: null
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 import _
_ from 'radashi'
const const options: { mode: string; volume: undefined; dancing: boolean; snacks: null;}
options = import _
_.shake<{ mode: string; volume: undefined; dancing: boolean; snacks: null;}>(obj: { mode: string; volume: undefined; dancing: boolean; snacks: null;}, filter: ((value: unknown) => boolean) | undefined): { mode: string; volume: undefined; dancing: boolean; snacks: null;} (+1 overload)export shake
Removes (shakes out) undefined entries from an object. Optional
second argument shakes out values by custom evaluation.
Note that non-enumerable keys are never shaken out.
shake( { mode: string
mode: 'party', volume: undefined
volume: var undefined
undefined, dancing: boolean
dancing: false, snacks: null
snacks: null, }, value: unknown
value => !value: unknown
value,)// => { mode: 'party' }