disposable: wrapper to make an object disposable with the using keyword

using feature explanation in TypeScript 5.2 docs

Example:

import { disposable } from "https://esm.town/v/postpostscript/disposable"; using state = disposable( { x: 1, y: 2, }, (value) => console.log("state disposed", value), ); // state disposed { x: 1, y: 2, [Symbol(Symbol.dispose)]: [Function (anonymous)] }

or, to use a proxy instead of modifying the original object:

using state = disposable( { x: 1, y: 2, }, (value) => console.log("proxyState disposed", value), true, ); // proxyState disposed { x: 1, y: 2 }

Full Example

Migrated from folder: Utils/disposable