@rtorcato/js-common / maps
maps
Functions
invertMap()
invertMap<
K,V>(map):Map<V,K>
Defined in: maps/index.ts:6
Inverts a Map (swaps keys and values). If duplicate values exist, later keys overwrite earlier ones.
Type Parameters
K
K
V
V
Parameters
map
Map<K, V>
The map to invert.
Returns
Map<V, K>
The inverted map.
mapValues()
mapValues<
K,V,U>(map,fn):Map<K,U>
Defined in: maps/index.ts:20
Maps the values of a Map using a function.
Type Parameters
K
K
V
V
U
U
Parameters
map
Map<K, V>
The map to map over.
fn
(value, key) => U
The function to apply to each value.
Returns
Map<K, U>
A new map with mapped values.
mergeMaps()
mergeMaps<
K,V>(...maps):Map<K,V>
Defined in: maps/index.ts:33
Merges two or more maps. Later maps overwrite earlier keys.
Type Parameters
K
K
V
V
Parameters
maps
...Map<K, V>[]
The maps to merge.
Returns
Map<K, V>
The merged map.
objectToMap()
objectToMap<
T>(obj):Map<string,any>
Defined in: maps/index.ts:49
Converts an object to a Map.
Type Parameters
T
T extends object
Parameters
obj
T
The object to convert.
Returns
Map<string, any>
The resulting map.
mapToObject()
mapToObject<
V>(map):Record<string,V>
Defined in: maps/index.ts:58
Converts a Map to an object.
Type Parameters
V
V
Parameters
map
Map<string, V>
The map to convert.
Returns
Record<string, V>
The resulting object.