Skip to main content

Object

Helper functions that have to do with objects.

Functions

objectFilter()

function objectFilter<K, V>(object, predicate): V[]

Defined in: functions/object.ts:16

Helper function to get the values in an object that match an arbitrary condition. Similar to the Array.map method, but works for objects.

This is efficient such that it avoids converting the object values into an array.

Type Parameters

Type Parameter
K extends string | number | symbol
V

Parameters

ParameterType
objectReadonly<Record<K, V>>
predicate(value) => boolean

Returns

V[]


objectToMap()

function objectToMap<K, V>(object): Map<K, V>

Defined in: functions/object.ts:48

Helper function to convert an object to a map.

This is useful when you need to construct a type safe object with the satisfies operator, but then later on you need to query it in a way where you expect the return value to be T or undefined. In this situation, by converting the object to a map, you can avoid unsafe type assertions.

Note that the converted map will only have string keys, due to the nature of JavaScript objects only having string keys under the hood.

Also see the objectToReadonlyMap function.

Type Parameters

Type Parameter
K extends string | number | symbol
V

Parameters

ParameterType
objectRecord<K, V>

Returns

Map<K, V>


objectToReadonlyMap()

function objectToReadonlyMap<K, V>(object): ReadonlyMap<K, V>

Defined in: functions/object.ts:73

Helper function to convert an object to a read-only map.

This is useful when you need to construct a type safe object with the satisfies operator, but then later on you need to query it in a way where you expect the return value to be T or undefined. In this situation, by converting the object to a map, you can avoid unsafe type assertions.

Note that the converted map will only have string keys, due to the nature of JavaScript objects only having string keys under the hood.

Also see the objectToMap function.

Type Parameters

Type Parameter
K extends string | number | symbol
V

Parameters

ParameterType
objectRecord<K, V>

Returns

ReadonlyMap<K, V>


objectToReverseMap()

function objectToReverseMap<K, V>(object): Map<V, K>

Defined in: functions/object.ts:88

Helper function to convert an object to a reverse map.

Note that the converted map will only have string keys, due to the nature of JavaScript objects only having string keys under the hood.

Also see the objectToReverseReadonlyMap function.

Type Parameters

Type Parameter
K extends string | number | symbol
V extends string | number | symbol

Parameters

ParameterType
objectRecord<K, V>

Returns

Map<V, K>


objectToReverseReadonlyMap()

function objectToReverseReadonlyMap<K, V>(object): ReadonlyMap<V, K>

Defined in: functions/object.ts:109

Helper function to convert an object to a reverse read-only map.

Note that the converted map will only have string keys, due to the nature of JavaScript objects only having string keys under the hood.

Also see the objectToReverseMap function.

Type Parameters

Type Parameter
K extends string | number | symbol
V extends string | number | symbol

Parameters

ParameterType
objectRecord<K, V>

Returns

ReadonlyMap<V, K>