Skip to main content

Map

Functions

copyMap

copyMap<K, V>(oldMap): Map<K, V>

Helper function to copy a map. (You can also use a Map constructor to accomplish this task.)

Type parameters

Name
K
V

Parameters

NameType
oldMapReadonlyMap<K, V>

Returns

Map<K, V>

Defined in

packages/isaacscript-common/src/functions/map.ts:6


defaultMapGetHash

defaultMapGetHash<V, A>(map, entity, ...extraArgs): V

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

NameType
VV
Aextends unknown[]

Parameters

NameType
mapDefaultMap<PtrHash, V, A>
entityEntity
...extraArgsA

Returns

V

Defined in

packages/isaacscript-common/src/functions/map.ts:19


defaultMapSetHash

defaultMapSetHash<V>(map, entity, value): void

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

Name
V

Parameters

NameType
mapMap<PtrHash, V>
entityEntity
valueV

Returns

void

Defined in

packages/isaacscript-common/src/functions/map.ts:35


getReversedMap

getReversedMap<K, V>(map): ReadonlyMap<V, K>

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

Name
K
V

Parameters

NameType
mapReadonlyMap<K, V>

Returns

ReadonlyMap<V, K>

Defined in

packages/isaacscript-common/src/functions/map.ts:65


mapSetHash

mapSetHash<V>(map, entity, value): void

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

Name
V

Parameters

NameType
mapMap<PtrHash, V>
entityEntity
valueV

Returns

void

Defined in

packages/isaacscript-common/src/functions/map.ts:81


objectToMap

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

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

NameType
Kextends string | number | symbol
VV

Parameters

NameType
objectRecord<K, V>

Returns

Map<K, V>

Defined in

packages/isaacscript-common/src/functions/map.ts:105


objectToReadonlyMap

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

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

NameType
Kextends string | number | symbol
VV

Parameters

NameType
objectRecord<K, V>

Returns

ReadonlyMap<K, V>

Defined in

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


sumMap

sumMap(map): number

Helper function to sum every value in a map together.

Parameters

NameType
mapReadonlyMap<unknown, number>

Returns

number

Defined in

packages/isaacscript-common/src/functions/map.ts:137