Map
Functions
Section titled “Functions”copyMap()
Section titled “copyMap()”copyMap<
K,V>(oldMap):ReadonlyMap<K,V>
Defined in: packages/isaacscript-common/src/functions/map.ts:5
Helper function to copy a map. (You can also use a Map constructor to accomplish this task.)
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”oldMap
Section titled “oldMap”ReadonlyMap<K, V>
Returns
Section titled “Returns”ReadonlyMap<K, V>
defaultMapGetHash()
Section titled “defaultMapGetHash()”defaultMapGetHash<
V,A>(map,entity, …extraArgs):V
Defined in: packages/isaacscript-common/src/functions/map.ts:13
Helper function to get the value from a DefaultMap that corresponds to an entity, assuming that
the map uses PtrHash as an index.
Type Parameters
Section titled “Type Parameters”V
A extends unknown[]
Parameters
Section titled “Parameters”DefaultMap<PtrHash, V, A>
entity
Section titled “entity”Entity
extraArgs
Section titled “extraArgs”…A
Returns
Section titled “Returns”V
defaultMapSetHash()
Section titled “defaultMapSetHash()”defaultMapSetHash<
V>(map,entity,value):void
Defined in: packages/isaacscript-common/src/functions/map.ts:29
Helper function to set a value for a DefaultMap that corresponds to an entity, assuming that
the map uses PtrHash as an index.
Since Map and DefaultMap set values in the same way, this function is simply an alias for the
mapSetHash helper function.
Type Parameters
Section titled “Type Parameters”V
Parameters
Section titled “Parameters”Map<PtrHash, V>
entity
Section titled “entity”Entity
V
Returns
Section titled “Returns”void
getReversedMap()
Section titled “getReversedMap()”getReversedMap<
K,V>(map):ReadonlyMap<V,K>
Defined in: packages/isaacscript-common/src/functions/map.ts:59
Helper function to get a copy of a map with the keys and the values reversed.
For example:
new Map<string, number>([ ["foo", 1], ["bar", 2],]);Would be reversed to:
new Map<number, string>([ [1, "foo"], [2, "bar"],]);Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”ReadonlyMap<K, V>
Returns
Section titled “Returns”ReadonlyMap<V, K>
mapSetHash()
Section titled “mapSetHash()”mapSetHash<
V>(map,entity,value):void
Defined in: packages/isaacscript-common/src/functions/map.ts:75
Helper function to set a value for a DefaultMap that corresponds to an entity, assuming that
the map uses PtrHash as an index.
Type Parameters
Section titled “Type Parameters”V
Parameters
Section titled “Parameters”Map<PtrHash, V>
entity
Section titled “entity”Entity
V
Returns
Section titled “Returns”void
objectToMap()
Section titled “objectToMap()”objectToMap<
K,V>(object):ReadonlyMap<K,V>
Defined in: packages/isaacscript-common/src/functions/map.ts:98
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 map values will be inserted in a random order, due to how pairs works under the
hood.
Also see the objectToReadonlyMap function.
Type Parameters
Section titled “Type Parameters”K extends string | number | symbol
V
Parameters
Section titled “Parameters”object
Section titled “object”Record<K, V>
Returns
Section titled “Returns”ReadonlyMap<K, V>
objectToReadonlyMap()
Section titled “objectToReadonlyMap()”objectToReadonlyMap<
K,V>(object):ReadonlyMap<K,V>
Defined in: packages/isaacscript-common/src/functions/map.ts:123
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 map values will be inserted in a random order, due to how pairs works under the
hood.
Also see the objectToMap function.
Type Parameters
Section titled “Type Parameters”K extends string | number | symbol
V
Parameters
Section titled “Parameters”object
Section titled “object”Record<K, V>
Returns
Section titled “Returns”ReadonlyMap<K, V>
sumMap()
Section titled “sumMap()”sumMap(
map):number
Defined in: packages/isaacscript-common/src/functions/map.ts:130
Helper function to sum every value in a map together.
Parameters
Section titled “Parameters”ReadonlyMap<unknown, number>
Returns
Section titled “Returns”number
