object.ts

Declarations
#

9 declarations

view source

EMPTY_OBJECT
#

object.ts view source

Record<string | number | symbol, undefined> & object

Frozen empty object with no properties, good for options default values.

is_plain_object
#

object.ts view source

(value: any): boolean

Returns a boolean indicating if value is a plain object, possibly created with Object.create(null). But warning! This fails for some obscure corner cases, use a proper library for weird things.

value

type any

returns

boolean

map_record
#

object.ts view source

<T, K extends string | number, U>(obj: Record<K, T>, mapper: (value: T, key: string) => U): Record<K, U>

Iterated keys in for..in are always returned as strings, so to prevent usage errors the key type of mapper is always a string. Symbols are not enumerable as keys, so they're excluded.

obj

type Record<K, T>

mapper

type (value: T, key: string) => U

returns

Record<K, U>

omit
#

object.ts view source

<T extends Record<K, any>, K extends keyof T>(obj: T, keys: K[]): OmitStrict<T, K>

Creates a new object without the specified keys.

obj

type T

keys

type K[]

returns

OmitStrict<T, K>

omit_undefined
#

pick_by
#

object.ts view source

<T extends Record<K, any>, K extends string | number>(obj: T, should_pick: (value: any, key: K) => boolean): Partial<T>

Creates a new object with properties that pass the should_pick predicate.

obj

type T

should_pick

type (value: any, key: K) => boolean

returns

Partial<T>

reorder
#

object.ts view source

<T extends Record<K, any>, K extends string | number>(obj: T, keys: K[]): T

A more explicit form of {put_this_first: obj.put_this_first, ...obj}.

obj

type T

keys

type K[]

returns

T

transform_empty_object_to_undefined
#

traverse
#

object.ts view source

(obj: any, cb: (key: string, value: any, obj: any) => void): void

Performs a depth-first traversal of an object's enumerable properties, calling cb for every key and value with the current obj context.

obj

- any object with enumerable properties

type any

cb

- receives the key, value, and obj for every enumerable property on obj and its descendents

type (key: string, value: any, obj: any) => void

returns

void

Imported by
#