Skip to content

remcohaszing/proxy-disposable

proxy-disposable

github actions codecov npm version npm downloads

Make objects with a dispose method compatible with an ES6 disposable.

Table of Contents

Installation

npm install proxy-disposable

Usage

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 disposable

API

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 24 or greater.

License

MIT © Remco Haszing

About

Make objects with a dispose method compatible with an ES6 disposable

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Contributors