UNPKG

thorish

Version:

This is a library of useful JS concepts and data structures for Node and the browser. It it, unashamedly, a dumping ground for code needed by [@samthor](https://twitter.com/samthor)'s projects.

29 lines (28 loc) 717 B
/** * A dead-simple cache helper. */ export declare class SimpleCache<K, V> { private readonly gen; private readonly m; constructor(gen: (k: K) => V); /** * Copies this as a regular {@link Map}. */ copy(): Map<K, V>; has(k: K): boolean; get(k: K): V; get size(): number; clear(): void; keys(): MapIterator<K>; entries(): MapIterator<[K, V]>; values(): MapIterator<V>; delete(k: K): boolean; } /** * Return a helper which runs the passed function at most once. */ export declare function once<T = void>(fn: () => T): () => T; /** * Lazy {@link WeakMap} factory. */ export declare function lazyWeak<W extends Object, V>(fn: (w: W) => V): (w: W) => V;