isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
74 lines • 3 kB
TypeScript
import type { DefaultMap } from "../classes/DefaultMap";
/** Helper function to copy a map. (You can also use a Map constructor to accomplish this task.) */
export declare function copyMap<K, V>(oldMap: ReadonlyMap<K, V>): Map<K, V>;
/**
* Helper function to get the value from a `DefaultMap` that corresponds to an entity, assuming that
* the map uses `PtrHash` as an index.
*/
export declare function defaultMapGetHash<V, A extends unknown[]>(map: DefaultMap<PtrHash, V, A>, entity: Entity, ...extraArgs: A): V;
/**
* 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.
*/
export declare function defaultMapSetHash<V>(map: Map<PtrHash, V>, entity: Entity, value: V): void;
/**
* Helper function to get a copy of a map with the keys and the values reversed.
*
* For example:
*
* ```ts
* new Map<string, number>([
* ["foo", 1],
* ["bar", 2],
* ]);
* ```
*
* Would be reversed to:
*
* ```ts
* new Map<number, string>([
* [1, "foo"],
* [2, "bar"],
* ]);
* ```
*/
export declare function getReversedMap<K, V>(map: ReadonlyMap<K, V>): ReadonlyMap<V, K>;
/**
* Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
* the map uses `PtrHash` as an index.
*/
export declare function mapSetHash<V>(map: Map<PtrHash, V>, entity: Entity, value: V): void;
/**
* 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.
*/
export declare function objectToMap<K extends string | number | symbol, V>(object: Record<K, V>): 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.
*/
export declare function objectToReadonlyMap<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlyMap<K, V>;
/** Helper function to sum every value in a map together. */
export declare function sumMap(map: ReadonlyMap<unknown, number>): number;
//# sourceMappingURL=map.d.ts.map