Thundercraft5 / weak-utils

⇢ A zero-dependency lightweight library for iterable weak collections and proxies

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

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

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

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.

About

⇢ A zero-dependency lightweight library for iterable weak collections and proxies


Languages

Language:TypeScript 100.0%