Make objects with a dispose method compatible with an ES6
disposable.
npm install proxy-disposableCreate an object with a dispose method. Then wrap it using the d function. For example,
the following script:
import { d } from 'proxy-disposable'
using disposable = d({
name: 'object',
dispose() {
console.log('Disposed', this.name)
}
})
disposable.name = 'disposable'Yields:
Disposed disposable
Wrap an object with a dispose method as an ES6
disposable.
disposable(Object) — The disposable to wrap.
The input disposable as an ES6 disposable.
The dispose method is commonly used in various projects, such as
language server related projects and
Monaco editor.
This package makes these nicer to work with in contexts where you want to quickly create an object, and clean up afterwards. A typical use case is tests.
This project is compatible with Node.js 24 or greater.