proxy-disposable
v1.0.0
Published
Make objects with a dispose method compatible with an ES6 disposable
Maintainers
Readme
proxy-disposable
Make objects with a dispose method compatible with an ES6
disposable.
Table of Contents
Installation
npm install proxy-disposableUsage
Create 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 disposableAPI
d
Wrap an object with a dispose method as an ES6
disposable.
Arguments
disposable(Object) — The disposable to wrap.
Returns
The input disposable as an ES6 disposable.
Why
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.
Compatibility
This project is compatible with Node.js 22 or greater.
