1.0.1 • Published 1 year ago

@thundercraft5/weak-utils v1.0.1

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
1 year ago

weak-utils

weak-utils is a zero-dependency lightweight library written in TypeScript that provides weak reference utilities.

What does this do?

weak-utils has 3 components:

Usage

IterableWeakMap<object, any>

Use as you would a regular Map or WeakMap. Has all methods of Map.

IterableWeakSet<object>

Use as you would a regular Set or WeakSet. Has all methods of Set.

WeakProxy<object>

Use as you would a regular a regular proxy, supports revocable proxies as well.

This object works by registering a finalizer for the target value via FinalizationRegistry(), then, when the target value is collected, the proxy is revoked.

The use cases for weak proxies are currently unknown in JS, I added this feature as the result of an experiment. To register a finalizer method, pass a finalize() method in the handler object.