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:97

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.

Type Parameters

T

T extends object

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 }

Call Signature

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

Defined in: object.ts:112

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

Type Parameters

T

T extends object

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 }

On this page