@ayonli/jsext
Version:
A JavaScript extension package for building strong and modern applications.
35 lines (34 loc) • 897 B
TypeScript
declare const inverse: unique symbol;
/**
* Bi-directional map, keys and values are unique and map to each other.
*
* @example
* ```ts
* import { BiMap } from "@ayonli/jsext/collections";
*
* const map = new BiMap<string, string>();
*
* map.set("foo", "hello");
* map.set("bar", "world");
*
* console.log(map.get("foo")); // hello
* console.log(map.getKey("world")); // bar
*
* map.delete("foo");
* console.log(map.hasValue("hello")); // false
*
* map.deleteValue("world");
* console.log(map.has("bar")); // false
* ```
*/
export default class BiMap<K, V> extends Map<K, V> {
[inverse]: Map<V, K>;
get [Symbol.toStringTag](): "BiMap";
constructor(iterable?: Iterable<readonly [K, V]> | null);
set(key: K, value: V): this;
getKey(value: V): K | undefined;
hasValue(value: V): boolean;
deleteValue(value: V): boolean;
clear(): void;
}
export {};