alapa
Version:
A cutting-edge web development framework designed to revolutionize the way developers build modern web applications.
65 lines (64 loc) • 1.8 kB
TypeScript
/**
* A generic map class that maps keys of type K to values of type V.
*
* @template K - The type of keys (string, number, or symbol).
* @template V - The type of values.
*/
export declare class Map<K extends string | number | symbol, V> {
private items;
/**
* Creates a new Map with optional initial key-value pairs.
*
* @param initialItems - An optional object of initial key-value pairs.
*/
constructor(initialItems?: {
[key in K]: V;
});
/**
* Adds a key-value pair to the map.
*
* @param key - The key to add.
* @param value - The value associated with the key.
*/
add(key: K, value: V): void;
/**
* Retrieves the value associated with the given key.
*
* @param key - The key whose value to retrieve.
* @returns The value associated with the key, or undefined if the key does not exist.
*/
get(key: K): V | undefined;
/**
* Removes a key-value pair from the map.
*
* @param key - The key to remove.
* @returns True if the key was removed, false if the key was not found.
*/
remove(key: K): boolean;
/**
* Retrieves all keys in the map.
*
* @returns An array of keys.
*/
keys(): K[];
/**
* Retrieves all values in the map.
*
* @returns An array of values.
*/
values(): V[];
/**
* Retrieves all key-value pairs in the map as an array of tuples.
*
* @returns An array of tuples where each tuple contains a key and its corresponding value.
*/
getAll(): [K, V][];
/**
* Merges another map into this map.
*
* @param otherMap - The map or object to merge into this map.
*/
addAll(otherMap: Map<K, V> | {
[key in K]: V;
}): void;
}