Skip to content

About

Check if a value implements the Disposable or AsyncDisposable protocol

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

has-disposable — Check if a value implements the Disposable or AsyncDisposable protocol

Check if a value implements the Disposable or AsyncDisposable protocol

CI License: MIT npm Ask DeepWiki Socket Node 20+


Install

npm install has-disposable

Usage

import hasDisposable, {hasAsyncDisposable} from 'has-disposable';

const resource = {
	[Symbol.dispose]() {
		console.log('disposed');
	},
};

hasDisposable(resource);
//=> true

hasDisposable({});
//=> false

const asyncResource = {
	async [Symbol.asyncDispose]() {
		console.log('async disposed');
	},
};

hasAsyncDisposable(asyncResource);
//=> true

API

hasDisposable(value)

Returns true when value[Symbol.dispose] is a function, including methods inherited through the prototype chain. Nullish values return false. Primitive values can return true when their boxed prototype defines the method.

Returns true if the value has a Symbol.dispose method.

value

Type: unknown

The value to check.

hasAsyncDisposable(value)

Returns true when value[Symbol.asyncDispose] is a function, including inherited methods. Nullish values return false. Primitive values can return true when their boxed prototype defines the method.

Returns true if the value has a Symbol.asyncDispose method.

value

Type: unknown

The value to check.

Related

  • using - TC39 Explicit Resource Management proposal

License

MIT

About

Check if a value implements the Disposable or AsyncDisposable protocol

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages