UNPKG

frail-map

Version:

FrailMap is an extension of WeakMap that supports primitive values using WeakRef.

62 lines 2.31 kB
/** Options for calling `.set()` on a FrailMap. */ export type SetOptions = { /** * Use strong reference for this value, preventing it from being garbage * collected. */ strong?: boolean; }; /** * Strong limbs with a weak grab, a WeakMap that supports scalars. * * `size` is not updated until a disposed object is accessed via one of * these methods: `has`, `get`, `entries`, `forEach`, `keys` or `values`. */ export declare class FrailMap<K, V> extends Map<K, V> { constructor(entries?: readonly (readonly [K, V])[] | null); /** * Returns a specified element from the Map object. If the value that is * associated to the provided key is an object, then you will get a reference * to that object and any change made to that object will effectively modify * it inside the Map. * * @returns Returns the element associated with the specified key. If no * element is associated with the specified key or the value has been garbage * collected, undefined is returned. */ get(key: K): V | undefined; /** * @returns boolean indicating whether an element with the specified key * exists or not, updates size if value has been garbage collected. */ has(key: K): boolean; /** * Adds a new element with a specified key and value to the Map. If an element * with the same key already exists, the element will be updated. * * A `strong` option can be provided to use a strong reference to act like a * normal map. */ set(key: K, value: V, options?: SetOptions): this; /** * Executes a provided function once per each key/value pair in the Map, in * insertion order. */ forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: this): void; /** * Returns an iterable of key, value pairs for every entry in the map. */ entries(): IterableIterator<[K, V]>; /** * Returns an iterable of keys in the map */ keys(): IterableIterator<K>; /** * Returns an iterable of values in the map */ values(): IterableIterator<V>; [Symbol.iterator](): IterableIterator<[K, V]>; get [Symbol.toStringTag](): string; toJSON(): Record<string, unknown>; } //# sourceMappingURL=FrailMap.d.ts.map