Skip to content

Map

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.)

K

V

ReadonlyMap<K, V>

ReadonlyMap<K, V>


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.

V

A extends unknown[]

DefaultMap<PtrHash, V, A>

Entity

A

V


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.

V

Map<PtrHash, V>

Entity

V

void


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"],
]);

K

V

ReadonlyMap<K, V>

ReadonlyMap<V, K>


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.

V

Map<PtrHash, V>

Entity

V

void


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.

K extends string | number | symbol

V

Record<K, V>

ReadonlyMap<K, V>


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.

K extends string | number | symbol

V

Record<K, V>

ReadonlyMap<K, V>


sumMap(map): number

Defined in: packages/isaacscript-common/src/functions/map.ts:130

Helper function to sum every value in a map together.

ReadonlyMap<unknown, number>

number