GuobaGuoba Utils

shake

@guoba-ai/utils / object / shake

Function: shake()

Call Signature

function shake<T>(obj): { [K in string | number | symbol]: Exclude<T[K], undefined> };

Defined in: object.ts:131

Create a new object with matching values removed. Removes undefined values by default. An optional filter can remove values by custom evaluation. Non-enumerable keys are never removed or copied.

Parameters

obj

T

The source object

Returns

{ [K in string | number | symbol]: Exclude<T[K], undefined> }

A new object without undefined values

Example

shake({ a: 1, b: undefined, c: null }) // { a: 1, c: null }

shake({ count: 0, enabled: false, missing: undefined })
// { count: 0, enabled: false }

const source = { a: 1, b: undefined }
shake(source) // { a: 1 }
source // { a: 1, b: undefined }

Call Signature

function shake<T>(obj, filter): T;

Defined in: object.ts:152

Create a new object with values removed by a custom filter.

Parameters

obj

T

The source object

filter

((value) => boolean) | undefined

Function returning true for values to remove

Returns

T

A new object without values matched by the filter

Example

shake({ a: 1, b: 2 }, value => value === 2) // { a: 1 }

shake({ a: null, b: 1 }, value => value === null) // { b: 1 }

shake({ a: 0, b: '' }, value => value === '') // { a: 0 }

On this page