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
Name | Type |
---|---|
oldMap | ReadonlyMap <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
Name | Type |
---|---|
V | V |
A | extends unknown [] |
Parameters
Name | Type |
---|---|
map | DefaultMap <PtrHash , V , A > |
entity | Entity |
...extraArgs | A |
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
Name | Type |
---|---|
map | Map <PtrHash , V > |
entity | Entity |
value | V |
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
Name | Type |
---|---|
map | ReadonlyMap <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
Name | Type |
---|---|
map | Map <PtrHash , V > |
entity | Entity |
value | V |
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
Name | Type |
---|---|
K | extends string | number | symbol |
V | V |
Parameters
Name | Type |
---|---|
object | Record <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
Name | Type |
---|---|
K | extends string | number | symbol |
V | V |
Parameters
Name | Type |
---|---|
object | Record <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
Name | Type |
---|---|
map | ReadonlyMap <unknown , number > |
Returns
number