frail-map
Version:
FrailMap is an extension of WeakMap that supports primitive values using WeakRef.
41 lines (26 loc) • 1.04 kB
Markdown
is an extension of WeakMap that supports primitive values using
WeakRef. It may also set individual pairs to be strongly referenced when
specified, or when WeakRef is not available.
```ts
import { FrailMap } from "frail-map";
const myMap = new FrailMap<string, number>();
myMap.set("foo", "foo");
myMap.set("bar", "bar", { strong: true });
console.log(myMap.get("foo")); // -> "foo"
console.log(myMap.get("bar")); // -> "bar"
// ... After GC ...
console.log(myMap.get("foo")); // -> undefined
console.log(myMap.get("bar")); // -> "bar"
```
If you find a bug or would like to suggest a new feature, please open an issue
or submit a pull request on GitHub.
FrailMap is licensed under the MIT License. See the LICENSE file for more
information.
If you find this project useful, please consider supporting it by donating to
the author.
[](https://github.com/sponsors/vicary)
FrailMap