is-awaitable
v1.0.2
Published
A lightweight solution for detecting async functions.
Maintainers
Readme
is-awaitable
A lightweight solution for detecting async functions (including async generators).
Installation
Using npm:
$ npm install is-awaitableUsing yarn:
$ yarn add is-awaitableUsing pnpm:
$ pnpm add is-awaitableCDN Usage
You can use is-awaitable directly in browsers via CDN:
<script src="https://unpkg.com/is-awaitable@latest/dist/index.umd.js"></script>
<!-- or -->
<script src="https://cdn.jsdelivr.net/npm/is-awaitable@latest/dist/index.umd.js"></script>
<script>
const { isAwaitable } = window.IsAwaitable;
async function foo() { return 'hello'; }
function bar() { return 42; }
console.log( isAwaitable(foo) ); // true
console.log( isAwaitable(bar) ); // false
</script>Usage
import { isAwaitable } from 'is-awaitable';
async function foo() { return 'ok'; }
console.log(isAwaitable(foo)); // true
const bar = async () => {};
console.log(isAwaitable(bar)); // true
async function* gen() { yield 1; }
console.log(isAwaitable(gen)); // true
function baz() { return 42; }
console.log(isAwaitable(baz)); // false
const returnsPromise = () => Promise.resolve('hi');
console.log(isAwaitable(returnsPromise)); // false
console.log(isAwaitable(null)); // false
console.log(isAwaitable(123)); // falseLicense
MIT License
Copyright (c) 2025 Ahmet Tinastepe
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
