https://github.com/mstuart/has-disposable
Check if a value implements the Disposable or AsyncDisposable protocol
https://github.com/mstuart/has-disposable
Last synced: 3 days ago
JSON representation
Check if a value implements the Disposable or AsyncDisposable protocol
- Host: GitHub
- URL: https://github.com/mstuart/has-disposable
- Owner: mstuart
- License: mit
- Created: 2026-02-16T00:34:27.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2026-06-22T05:09:01.000Z (6 days ago)
- Last Synced: 2026-06-22T07:12:06.200Z (6 days ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
- Security: .github/security.md
Awesome Lists containing this project
README
# has-disposable
> Check if a value implements the Disposable or AsyncDisposable protocol
## Install
```sh
npm install has-disposable
```
## Usage
```js
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` if the value has a `Symbol.dispose` method.
#### value
Type: `unknown`
The value to check.
### hasAsyncDisposable(value)
Returns `true` if the value has a `Symbol.asyncDispose` method.
#### value
Type: `unknown`
The value to check.
## Related
- [using](https://github.com/nicolo-ribaudo/tc39-proposal-explicit-resource-management) - TC39 Explicit Resource Management proposal
## License
MIT