obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
99 lines (98 loc) • 2.3 kB
text/typescript
/**
* @packageDocumentation
*
* Two-way map.
*/
/**
* A map that allows you to look up a value by its key and vice versa.
*
* @example
* ```ts
* const map = new TwoWayMap<string, number>();
* map.set('foo', 42);
* map.getValue('foo'); // 42
* map.getKey(42); // 'foo'
* map.deleteKey('foo');
* map.deleteValue(42);
* map.clear();
* ```
*/
export declare class TwoWayMap<Key, Value> {
private readonly keyValueMap;
private readonly valueKeyMap;
/**
* Creates a new two-way map.
*
* @param entries - Entries to initialize the map with.
*/
constructor(entries?: (readonly [key: Key, value: Value])[]);
/**
* Clears the map.
*/
clear(): void;
/**
* Deletes a key from the map.
*
* @param key - The key.
*/
deleteKey(key: Key): void;
/**
* Deletes a value from the map.
*
* @param value - The value.
*/
deleteValue(value: Value): void;
/**
* Gets all entries in the map.
*
* @returns An iterator over all entries in the map.
*/
entries(): IterableIterator<readonly [key: Key, value: Value]>;
/**
* Gets a key by its value.
*
* @param value - The value.
* @returns The key.
*/
getKey(value: Value): Key | undefined;
/**
* Gets a value by its key.
*
* @param key - The key.
* @returns The value.
*/
getValue(key: Key): undefined | Value;
/**
* Checks if the map has a key.
*
* @param key - The key.
* @returns `true` if the map has the key, `false` otherwise.
*/
hasKey(key: Key): boolean;
/**
* Checks if the map has a value.
*
* @param value - The value.
* @returns `true` if the map has the value, `false` otherwise.
*/
hasValue(value: Value): boolean;
/**
* Gets all keys in the map.
*
* @returns An iterator over all keys in the map.
*/
keys(): IterableIterator<Key>;
/**
* Sets a key-value pair in the map.
*
* @param key - The key.
* @param value - The value.
*/
set(key: Key, value: Value): void;
/**
* Gets all values in the map.
*
* @returns An iterator over all values in the map.
*/
values(): IterableIterator<Value>;
}