Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/loklaan/is-async-func

Check if a value is an async function, from ES2017 specification. Supports babel.
https://github.com/loklaan/is-async-func

async-functions es2017 type-checking

Last synced: 2 months ago
JSON representation

Check if a value is an async function, from ES2017 specification. Supports babel.

Awesome Lists containing this project

README

        

# is-async-func

![size](https://img.shields.io/badge/size-282%20B-grey.svg)
![dependencies](https://img.shields.io/badge/dependencies-0-grey.svg)
[![NPM](https://img.shields.io/npm/v/is-async-func.svg)](https://npmjs.com/package/is-async-func)
[![Travis](https://img.shields.io/travis/loklaan/is-async-func.svg)](https://travis-ci.org/loklaan/is-async-func)
[![Codecov](https://img.shields.io/codecov/c/github/loklaan/is-async-func.svg)](https://codecov.io/gh/loklaan/is-async-func)

Check if a value is an async function, from ES2017 specification

Supports runtime implementations, as well as babel transpiled code.

```js
const isAsyncFunction = require('is-async-func');

isAsyncFunction(async function () {})
// true

isAsyncFunction(async function foo () {})
// true

isAsyncFunction(async () => {})
// true

const foo = { async bar () {} }
isAsyncFunction(foo.bar)
// true

const foo = { bar: async function () {} }
isAsyncFunction(foo.bar)
// true

const foo = { bar: async () => {} }
isAsyncFunction(foo.bar)
// true

class Foo () {
async bar () {}
}
isAsyncFunction((new Foo()).bar)
// true
```

## Install

```shell
npm install is-async-func
# yarn add is-async-func
```

## Should I use this?

For runtimes that support async/await, yes!

For transpiled async/await, probably! :grimacing:
The transpilation tests cover many different combinations of async declarations and babel transform presets, but the transpiled detection generally takes a hacky approach. Probably-definitely don't use this in hot code.

## License

Licensed under the MIT License, Copyright © 2017 Lochlan Bunn.