├── .eslintrc
├── .github
└── workflows
│ ├── node-aught.yml
│ ├── node-pretest.yml
│ ├── node-tens.yml
│ ├── node-twenties.yml
│ ├── rebase.yml
│ └── require-allow-edits.yml
├── .gitignore
├── .npmrc
├── .nycrc
├── CHANGELOG.md
├── LICENSE
├── README.md
├── index.d.ts
├── index.js
├── package.json
├── test
├── index.js
└── uglified.js
└── tsconfig.json
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 |
4 | "extends": "@ljharb",
5 |
6 | "rules": {
7 | "no-new-func": 1,
8 | },
9 | }
10 |
--------------------------------------------------------------------------------
/.github/workflows/node-aught.yml:
--------------------------------------------------------------------------------
1 | name: 'Tests: node.js < 10'
2 |
3 | on: [pull_request, push]
4 |
5 | permissions:
6 | contents: read
7 |
8 | jobs:
9 | tests:
10 | uses: ljharb/actions/.github/workflows/node.yml@main
11 | with:
12 | range: '< 10'
13 | type: minors
14 | command: npm run tests-only
15 |
16 | node:
17 | name: 'node < 10'
18 | needs: [tests]
19 | runs-on: ubuntu-latest
20 | steps:
21 | - run: true
22 |
--------------------------------------------------------------------------------
/.github/workflows/node-pretest.yml:
--------------------------------------------------------------------------------
1 | name: 'Tests: pretest/posttest'
2 |
3 | on: [pull_request, push]
4 |
5 | permissions:
6 | contents: read
7 |
8 | jobs:
9 | tests:
10 | uses: ljharb/actions/.github/workflows/pretest.yml@main
11 |
--------------------------------------------------------------------------------
/.github/workflows/node-tens.yml:
--------------------------------------------------------------------------------
1 | name: 'Tests: node.js 10 - 20'
2 |
3 | on: [pull_request, push]
4 |
5 | permissions:
6 | contents: read
7 |
8 | jobs:
9 | tests:
10 | uses: ljharb/actions/.github/workflows/node.yml@main
11 | with:
12 | range: '>= 10 < 20'
13 | type: minors
14 | command: npm run tests-only
15 |
16 | node:
17 | name: 'node 10 - 20'
18 | needs: [tests]
19 | runs-on: ubuntu-latest
20 | steps:
21 | - run: true
22 |
--------------------------------------------------------------------------------
/.github/workflows/node-twenties.yml:
--------------------------------------------------------------------------------
1 | name: 'Tests: node.js >= 20'
2 |
3 | on: [pull_request, push]
4 |
5 | permissions:
6 | contents: read
7 |
8 | jobs:
9 | tests:
10 | uses: ljharb/actions/.github/workflows/node.yml@main
11 | with:
12 | range: '>= 20'
13 | type: minors
14 | command: npm run tests-only
15 |
16 | node:
17 | name: 'node >= 20'
18 | needs: [tests]
19 | runs-on: ubuntu-latest
20 | steps:
21 | - run: true
22 |
--------------------------------------------------------------------------------
/.github/workflows/rebase.yml:
--------------------------------------------------------------------------------
1 | name: Automatic Rebase
2 |
3 | on: [pull_request_target]
4 |
5 | jobs:
6 | _:
7 | uses: ljharb/actions/.github/workflows/rebase.yml@main
8 | secrets:
9 | token: ${{ secrets.GITHUB_TOKEN }}
10 |
--------------------------------------------------------------------------------
/.github/workflows/require-allow-edits.yml:
--------------------------------------------------------------------------------
1 | name: Require “Allow Edits”
2 |
3 | on: [pull_request_target]
4 |
5 | permissions:
6 | contents: read
7 |
8 | jobs:
9 | _:
10 | permissions:
11 | pull-requests: read # for ljharb/require-allow-edits to check 'allow edits' on PR
12 |
13 | name: "Require “Allow Edits”"
14 |
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - uses: ljharb/require-allow-edits@main
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | lerna-debug.log*
8 |
9 | # Diagnostic reports (https://nodejs.org/api/report.html)
10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11 |
12 | # Runtime data
13 | pids
14 | *.pid
15 | *.seed
16 | *.pid.lock
17 |
18 | # Directory for instrumented libs generated by jscoverage/JSCover
19 | lib-cov
20 |
21 | # Coverage directory used by tools like istanbul
22 | coverage
23 | *.lcov
24 |
25 | # nyc test coverage
26 | .nyc_output
27 |
28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29 | .grunt
30 |
31 | # Bower dependency directory (https://bower.io/)
32 | bower_components
33 |
34 | # node-waf configuration
35 | .lock-wscript
36 |
37 | # Compiled binary addons (https://nodejs.org/api/addons.html)
38 | build/Release
39 |
40 | # Dependency directories
41 | node_modules/
42 | jspm_packages/
43 |
44 | # TypeScript v1 declaration files
45 | typings/
46 |
47 | # TypeScript cache
48 | *.tsbuildinfo
49 |
50 | # Optional npm cache directory
51 | .npm
52 |
53 | # Optional eslint cache
54 | .eslintcache
55 |
56 | # Microbundle cache
57 | .rpt2_cache/
58 | .rts2_cache_cjs/
59 | .rts2_cache_es/
60 | .rts2_cache_umd/
61 |
62 | # Optional REPL history
63 | .node_repl_history
64 |
65 | # Output of 'npm pack'
66 | *.tgz
67 |
68 | # Yarn Integrity file
69 | .yarn-integrity
70 |
71 | # dotenv environment variables file
72 | .env
73 | .env.test
74 |
75 | # parcel-bundler cache (https://parceljs.org/)
76 | .cache
77 |
78 | # Next.js build output
79 | .next
80 |
81 | # Nuxt.js build / generate output
82 | .nuxt
83 | dist
84 |
85 | # Gatsby files
86 | .cache/
87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js
88 | # https://nextjs.org/blog/next-9-1#public-directory-support
89 | # public
90 |
91 | # vuepress build output
92 | .vuepress/dist
93 |
94 | # Serverless directories
95 | .serverless/
96 |
97 | # FuseBox cache
98 | .fusebox/
99 |
100 | # DynamoDB Local files
101 | .dynamodb/
102 |
103 | # TernJS port file
104 | .tern-port
105 |
106 | # Only apps should have lockfiles
107 | npm-shrinkwrap.json
108 | package-lock.json
109 | yarn.lock
110 |
111 | .npmignore
112 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | package-lock=false
2 | allow-same-version=true
3 | message=v%s
4 |
--------------------------------------------------------------------------------
/.nycrc:
--------------------------------------------------------------------------------
1 | {
2 | "all": true,
3 | "check-coverage": false,
4 | "reporter": ["text-summary", "text", "html", "json"],
5 | "exclude": [
6 | "coverage",
7 | "test"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file.
4 |
5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7 |
8 | ## [v2.1.1](https://github.com/inspect-js/is-async-function/compare/v2.1.0...v2.1.1) - 2025-01-22
9 |
10 | ### Fixed
11 |
12 | - [Refactor] use `async-function` for the eval parts [`#31`](https://github.com/inspect-js/is-async-function/issues/31)
13 |
14 | ### Commits
15 |
16 | - [Refactor] move `new Function` helper into a separate file [`db36da5`](https://github.com/inspect-js/is-async-function/commit/db36da5467fbbf0f2ae264114be6aa9edf55e218)
17 | - [Dev Deps] update `@arethetypeswrong/cli`, `@types/tape` [`981ab90`](https://github.com/inspect-js/is-async-function/commit/981ab907b700d344b510ca1617fda00a66513aa2)
18 | - [meta] add `exports` [`81bb8e5`](https://github.com/inspect-js/is-async-function/commit/81bb8e578c8cbeeda742715ab7a935c0472866a1)
19 | - [Refactor] skip `getProto` call when `AsyncFunction` does not exist [`dc929a5`](https://github.com/inspect-js/is-async-function/commit/dc929a547a5f7cd1337b176d20135b8cc3cc23cb)
20 |
21 | ## [v2.1.0](https://github.com/inspect-js/is-async-function/compare/v2.0.0...v2.1.0) - 2025-01-02
22 |
23 | ### Commits
24 |
25 | - [meta] use `npmignore` to autogenerate an npmignore file [`b8d050b`](https://github.com/inspect-js/is-async-function/commit/b8d050ba1ab615ef748e8ffbe48c5fc4e14af510)
26 | - [actions] split out node 10-20, and 20+ [`1c8cd4b`](https://github.com/inspect-js/is-async-function/commit/1c8cd4bb565934ec5a4d9fc351ac9c8e2b217c07)
27 | - [New] add types [`5ba6244`](https://github.com/inspect-js/is-async-function/commit/5ba62441efb4eb267659bcccd615018e7e09cc30)
28 | - [Robustness] use `call-bound`, `safe-regex-test` [`9379ecd`](https://github.com/inspect-js/is-async-function/commit/9379ecda6ddce8460a6a0dc1a3d5555443b0b510)
29 | - [actions] update rebase action to use reusable workflow [`81b54fb`](https://github.com/inspect-js/is-async-function/commit/81b54fbcb881ac0000306dfd8aade39c51191256)
30 | - [Tests] use `for-each` [`ebdc486`](https://github.com/inspect-js/is-async-function/commit/ebdc486ab08c35651567c9f21f11a18ab5618737)
31 | - [Dev Deps] update `@ljharb/eslint-config`, `auto-changelog`, `npmignore`, `tape` [`9eb494f`](https://github.com/inspect-js/is-async-function/commit/9eb494f5f5a89eebf7981db906c0c821598465fe)
32 | - [Dev Deps] update `aud`, `tape` [`ea43809`](https://github.com/inspect-js/is-async-function/commit/ea43809bff25e47e196bde254c7383464c03ae7e)
33 | - [Refactor] use `get-proto` directly [`fc46390`](https://github.com/inspect-js/is-async-function/commit/fc4639088bb6ed4e8b19988d3e642d45ee45e70e)
34 | - [Tests] replace `aud` with `npm audit` [`edb4afb`](https://github.com/inspect-js/is-async-function/commit/edb4afb68d6d63d049608269fdf83cdb98956ff3)
35 | - [Deps] update `has-tostringtag` [`dc78cf5`](https://github.com/inspect-js/is-async-function/commit/dc78cf545f87ecc17fc7f3426bbbc5ecdea9d167)
36 | - [Dev Deps] add missing peer dep [`a93d8ff`](https://github.com/inspect-js/is-async-function/commit/a93d8ff0a22e4351d625ca5bb0fc73d222f9756c)
37 |
38 | ## [v2.0.0](https://github.com/inspect-js/is-async-function/compare/v1.3.0...v2.0.0) - 2022-04-11
39 |
40 | ### Commits
41 |
42 | - [Breaking] v2 implementation and tests [`d79a37e`](https://github.com/inspect-js/is-async-function/commit/d79a37e25e24a74be3c349de51fda4ad58f30f3a)
43 | - Initial commit [`456defc`](https://github.com/inspect-js/is-async-function/commit/456defc6dc36809d11dd5a199110e46fe9fb4a6f)
44 | - npm init [`d35b611`](https://github.com/inspect-js/is-async-function/commit/d35b611d669e57a3a6fd017930d3bf9a0589ffd2)
45 | - Only apps should have lockfiles [`5920874`](https://github.com/inspect-js/is-async-function/commit/5920874ec2b26762d1037168a73e1c29a4286b1a)
46 |
47 | ## [v1.3.0](https://github.com/inspect-js/is-async-function/compare/v1.2.4...v1.3.0) - 2020-01-15
48 |
49 | ### Commits
50 |
51 | - feat: update deps, ci, readme [`dbb52a7`](https://github.com/inspect-js/is-async-function/commit/dbb52a7714887e897df62302a6ad8e8402d67fe4)
52 | - chore(release): 1.3.0 [`972e26c`](https://github.com/inspect-js/is-async-function/commit/972e26c01ad14aa3560462624f24f4464efc46a3)
53 |
54 | ## [v1.2.4](https://github.com/inspect-js/is-async-function/compare/v1.2.3...v1.2.4) - 2020-01-15
55 |
56 | ### Merged
57 |
58 | - fix(src): remove unneeded condition [`#16`](https://github.com/inspect-js/is-async-function/pull/16)
59 |
60 | ### Fixed
61 |
62 | - fix: update deps + the tests; close #17 [`#17`](https://github.com/inspect-js/is-async-function/issues/17)
63 |
64 | ### Commits
65 |
66 | - chore: update broken badge links [`2985e36`](https://github.com/inspect-js/is-async-function/commit/2985e36a644306ab2beb392e6833860cc1b3dadf)
67 | - chore: add github funding file [`377233a`](https://github.com/inspect-js/is-async-function/commit/377233ab85f042e68b4cf5c7fd91860b77e8ce53)
68 | - chore: all modules are stable for years [`b7db9f0`](https://github.com/inspect-js/is-async-function/commit/b7db9f07cfcd8e3f7f7c448f71dcf73ef0e9b67e)
69 | - chore(release): 1.2.4 [`a9f441f`](https://github.com/inspect-js/is-async-function/commit/a9f441f0b801dabf6e8a1690c871fd564e56ddad)
70 | - fix: add npm funding field [`c05ef28`](https://github.com/inspect-js/is-async-function/commit/c05ef28a1aa33543fc29c1c897613dc8676c1afc)
71 | - chore: drop testing on old Node versions [`c975f68`](https://github.com/inspect-js/is-async-function/commit/c975f68a788d99ebf109a34ed9867f19c85b8805)
72 | - chore(ci): test on 6 only [`106dcdd`](https://github.com/inspect-js/is-async-function/commit/106dcdd6d225248ef55c41218706fef1a7ce8c0e)
73 |
74 | ## [v1.2.3](https://github.com/inspect-js/is-async-function/compare/v1.2.2...v1.2.3) - 2017-03-11
75 |
76 | ### Commits
77 |
78 | - fix(style): remove lazy-cache, and update boilerplate stuff [`abd32db`](https://github.com/inspect-js/is-async-function/commit/abd32dba0d727e9a75fffa7ef7df138bbc722b69)
79 | - fix(docs): regenerate readme [`592f1b7`](https://github.com/inspect-js/is-async-function/commit/592f1b721c7c81bc1a6a84e462f4bd7ba7f24cd3)
80 | - fix(package): add missing dependency [`73f404d`](https://github.com/inspect-js/is-async-function/commit/73f404d9afc054c90c1f1bee280497ac809b1eb3)
81 | - chore(release): 1.2.3 [`103cf28`](https://github.com/inspect-js/is-async-function/commit/103cf28cfa5302a5a00bb5c9bd8bf9ecc69999fa)
82 | - fix(package): wrong version, because too fast update ;d [`2e887f0`](https://github.com/inspect-js/is-async-function/commit/2e887f09dbc9e234f5f26cadd4e7fe9cc97184fb)
83 |
84 | ## [v1.2.2](https://github.com/inspect-js/is-async-function/compare/v1.2.1...v1.2.2) - 2016-10-29
85 |
86 | ### Fixed
87 |
88 | - fix(docs): fixes and updates API docs [`#14`](https://github.com/inspect-js/is-async-function/issues/14)
89 |
90 | ### Commits
91 |
92 | - chore(release): 1.2.2 [`9165f94`](https://github.com/inspect-js/is-async-function/commit/9165f942865906a02e0f9afe55ac2f305d71a9b1)
93 |
94 | ## [v1.2.1](https://github.com/inspect-js/is-async-function/compare/v1.2.0...v1.2.1) - 2016-10-27
95 |
96 | ### Fixed
97 |
98 | - fix(non-strict): fix a bug in non-strict mode [`#13`](https://github.com/inspect-js/is-async-function/issues/13)
99 |
100 | ### Commits
101 |
102 | - chore(release): 1.2.1 [`f4c7f02`](https://github.com/inspect-js/is-async-function/commit/f4c7f02ecb1ca02772890552797da3b39883ed43)
103 |
104 | ## [v1.2.0](https://github.com/inspect-js/is-async-function/compare/v1.1.5...v1.2.0) - 2016-10-27
105 |
106 | ### Merged
107 |
108 | - Revert "Update arr-includes to version 2.0.0 🚀" [`#12`](https://github.com/inspect-js/is-async-function/pull/12)
109 | - chore(package): update arr-includes to version 2.0.0 [`#11`](https://github.com/inspect-js/is-async-function/pull/11)
110 |
111 | ### Commits
112 |
113 | - feat(strict): introduce strict mode [`ef8526f`](https://github.com/inspect-js/is-async-function/commit/ef8526ffa8ba2b4cf37f6bd2dae21aee871e6e6a)
114 | - docs(update): api docs [`739eb54`](https://github.com/inspect-js/is-async-function/commit/739eb5482ba560ad2de153a29fc16778f4d3ef3f)
115 | - chore(release): 1.2.0 [`3222afe`](https://github.com/inspect-js/is-async-function/commit/3222afed47c9b5d2fa12490aff2d7c9887183ea2)
116 |
117 | ## [v1.1.5](https://github.com/inspect-js/is-async-function/compare/v1.1.4...v1.1.5) - 2016-09-21
118 |
119 | ### Commits
120 |
121 | - chore(tests): simplify tests [`be112bb`](https://github.com/inspect-js/is-async-function/commit/be112bb3dec204f174bf745056b7c0fc7377aef5)
122 | - Release v1.1.5 [`577d96c`](https://github.com/inspect-js/is-async-function/commit/577d96c9f0fb6288e6bc88d8e51703b98f19b20c)
123 |
124 | ## [v1.1.4](https://github.com/inspect-js/is-async-function/compare/v1.1.3...v1.1.4) - 2016-09-21
125 |
126 | ### Fixed
127 |
128 | - chore(package): update deps, use lazy-cache - closes #10 [`#10`](https://github.com/inspect-js/is-async-function/issues/10)
129 |
130 | ### Commits
131 |
132 | - chore(package/tests): update to use `mukla` instead of `assertit` lib [`83011b1`](https://github.com/inspect-js/is-async-function/commit/83011b1e2820e239c606d872468582f5a9249c47)
133 | - chore(package): update npm scripts, add coveralls/standard/nyc to devDeps [`631acbd`](https://github.com/inspect-js/is-async-function/commit/631acbdcf9fd9aa6d56ac98e10f3092e7e5be485)
134 | - chore(gitignore): update gitignore [`7f09f8f`](https://github.com/inspect-js/is-async-function/commit/7f09f8f40777879e70315dfeef0805755a44a293)
135 | - chore(editorconfig): update editorconfig [`8bb8593`](https://github.com/inspect-js/is-async-function/commit/8bb85939f87e6738c5ca35b5e5f5d8cca67353c9)
136 | - docs(readme): run verb to update readme [`cf15044`](https://github.com/inspect-js/is-async-function/commit/cf150446dc4e948f2629377d7f369824bfda8b3b)
137 | - Release v1.1.4 [`41190e1`](https://github.com/inspect-js/is-async-function/commit/41190e1da3aeb787921b3ea5d834634295c31de8)
138 |
139 | ## [v1.1.3](https://github.com/inspect-js/is-async-function/compare/v1.1.2...v1.1.3) - 2016-04-21
140 |
141 | ### Merged
142 |
143 | - chore(package): update is-match to version 0.4.1 [`#7`](https://github.com/inspect-js/is-async-function/pull/7)
144 |
145 | ### Commits
146 |
147 | - use `common-callback-names` [`37c253f`](https://github.com/inspect-js/is-async-function/commit/37c253f9a34b68acd5651075a3f1b74cd30ed8fd)
148 | - Release v1.1.3 [`f212193`](https://github.com/inspect-js/is-async-function/commit/f212193a00790ccae387e2d7a373076fcbbb9d8f)
149 |
150 | ## [v1.1.2](https://github.com/inspect-js/is-async-function/compare/v1.1.1...v1.1.2) - 2016-03-18
151 |
152 | ### Commits
153 |
154 | - cleanup and update metadata [`e09ab8b`](https://github.com/inspect-js/is-async-function/commit/e09ab8b98e6aecd28d38ba4ff4c1f17c26549a06)
155 | - update docs [`42920c6`](https://github.com/inspect-js/is-async-function/commit/42920c699f706fcf1048e0c039b335d7bbaf34ed)
156 | - Release v1.1.2 [`19d77d6`](https://github.com/inspect-js/is-async-function/commit/19d77d6ba7abe87ecf4d2765cd8536fca140b3bd)
157 |
158 | ## [v1.1.1](https://github.com/inspect-js/is-async-function/compare/v1.1.0...v1.1.1) - 2016-03-18
159 |
160 | ### Commits
161 |
162 | - run update [`27b21bf`](https://github.com/inspect-js/is-async-function/commit/27b21bf76254635d6c5c18f896b6f151938ae810)
163 | - add docs [`ab38f94`](https://github.com/inspect-js/is-async-function/commit/ab38f947707182e0ea165e3bee90bd46b8dbfaf9)
164 | - update docs [`90654c9`](https://github.com/inspect-js/is-async-function/commit/90654c93e8ff9d0cfd1443ae3609cd898b57ef11)
165 | - refactor, allow passing custom array of argument names [`a1787c7`](https://github.com/inspect-js/is-async-function/commit/a1787c757f522cb5e1c568ec5270be14a38c4cc9)
166 | - add related libs [`868f423`](https://github.com/inspect-js/is-async-function/commit/868f4235a449d610a87351e5a5070f42a0c6e7ce)
167 | - Release v1.1.1 [`bc7d85e`](https://github.com/inspect-js/is-async-function/commit/bc7d85e2a115163d3b09f78be5196f21adce1a7c)
168 | - update description [`ce2e97b`](https://github.com/inspect-js/is-async-function/commit/ce2e97b34762f2087699a5b9910e498ec7062090)
169 |
170 | ## [v1.1.0](https://github.com/inspect-js/is-async-function/compare/v1.0.0...v1.1.0) - 2015-06-25
171 |
172 | ### Commits
173 |
174 | - Release v1.1.0 [`b3f3704`](https://github.com/inspect-js/is-async-function/commit/b3f3704f13a32664a08b3d55162925e37626f5e8)
175 | - update metadata [`95e6bc2`](https://github.com/inspect-js/is-async-function/commit/95e6bc2cc195ff5d2ab01f47c6a157b3a583d01a)
176 | - check also for `done` and `next` [`6697d29`](https://github.com/inspect-js/is-async-function/commit/6697d29430ac9ce5f55572a2d7762baa1f05a33b)
177 |
178 | ## v1.0.0 - 2015-06-05
179 |
180 | ### Commits
181 |
182 | - :cat2: implement :star2: [`eaccc68`](https://github.com/inspect-js/is-async-function/commit/eaccc681838a983390e93607451500982759bd7a)
183 | - add keywords [`55a5ffc`](https://github.com/inspect-js/is-async-function/commit/55a5ffc65d344328cf5b5bb7b7e1520ecede0035)
184 | - Release v1.0.0 [`66eab5f`](https://github.com/inspect-js/is-async-function/commit/66eab5f96c62a6a39b913a84e8ec4b37c657026a)
185 | - refactor [`a7ce00d`](https://github.com/inspect-js/is-async-function/commit/a7ce00d537bf420338b91fee00eb6893d14952bf)
186 | - add test for when throw [`60d0175`](https://github.com/inspect-js/is-async-function/commit/60d0175a955645b304f572fd571a1ced47486958)
187 | - add `related` section [`904acd8`](https://github.com/inspect-js/is-async-function/commit/904acd8fbd5c6c020ba537cc9962154d818ad067)
188 | - simplify travis [`ee17273`](https://github.com/inspect-js/is-async-function/commit/ee172737486a8a5f7b2b642aa72e6ca7a1749a1c)
189 | - Initial commit [`7e914c1`](https://github.com/inspect-js/is-async-function/commit/7e914c1c6d669635f239fa86d9d96f85d8aaaab4)
190 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2021 Jordan Harband
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # is-async-function [![Version Badge][2]][1]
2 |
3 | [![github actions][actions-image]][actions-url]
4 | [![coverage][codecov-image]][codecov-url]
5 | [![dependency status][5]][6]
6 | [![dev dependency status][7]][8]
7 | [![License][license-image]][license-url]
8 | [![Downloads][downloads-image]][downloads-url]
9 |
10 | [![npm badge][11]][1]
11 |
12 | Is this a native `async function`?
13 |
14 | ## Example
15 |
16 | ```js
17 | var isAsyncFunction = require('is-async-function');
18 | assert(!isAsyncFunction(function () {}));
19 | assert(!isAsyncFunction(null));
20 | assert(!isAsyncFunction(function* () { yield 42; return Infinity; }));
21 | assert(isAsyncFunction(async function () {}));
22 | ```
23 |
24 | ## Tests
25 | Simply clone the repo, `npm install`, and run `npm test`
26 |
27 | [1]: https://npmjs.org/package/is-async-function
28 | [2]: https://versionbadg.es/inspect-js/is-async-function.svg
29 | [5]: https://david-dm.org/inspect-js/is-async-function.svg
30 | [6]: https://david-dm.org/inspect-js/is-async-function
31 | [7]: https://david-dm.org/inspect-js/is-async-function/dev-status.svg
32 | [8]: https://david-dm.org/inspect-js/is-async-function#info=devDependencies
33 | [11]: https://nodei.co/npm/is-async-function.png?downloads=true&stars=true
34 | [license-image]: https://img.shields.io/npm/l/is-async-function.svg
35 | [license-url]: LICENSE
36 | [downloads-image]: https://img.shields.io/npm/dm/is-async-function.svg
37 | [downloads-url]: https://npm-stat.com/charts.html?package=is-async-function
38 | [codecov-image]: https://codecov.io/gh/inspect-js/is-async-function/branch/main/graphs/badge.svg
39 | [codecov-url]: https://app.codecov.io/gh/inspect-js/is-async-function/
40 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-async-function
41 | [actions-url]: https://github.com/inspect-js/is-async-function/actions
42 |
--------------------------------------------------------------------------------
/index.d.ts:
--------------------------------------------------------------------------------
1 | import type { AsyncFunction } from 'async-function';
2 |
3 | declare namespace isAsyncFunction {
4 | export type { AsyncFunction };
5 | }
6 |
7 | declare function isAsyncFunction(fn: unknown): fn is AsyncFunction;
8 |
9 | export = isAsyncFunction;
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var callBound = require('call-bound');
4 | var safeRegexTest = require('safe-regex-test');
5 |
6 | var toStr = callBound('Object.prototype.toString');
7 | var fnToStr = callBound('Function.prototype.toString');
8 | var isFnRegex = safeRegexTest(/^\s*async(?:\s+function(?:\s+|\()|\s*\()/);
9 |
10 | var hasToStringTag = require('has-tostringtag/shams')();
11 | var getProto = require('get-proto');
12 |
13 | var getAsyncFunc = require('async-function');
14 |
15 | /** @type {import('.')} */
16 | module.exports = function isAsyncFunction(fn) {
17 | if (typeof fn !== 'function') {
18 | return false;
19 | }
20 | if (isFnRegex(fnToStr(fn))) {
21 | return true;
22 | }
23 | if (!hasToStringTag) {
24 | var str = toStr(fn);
25 | return str === '[object AsyncFunction]';
26 | }
27 | if (!getProto) {
28 | return false;
29 | }
30 | var asyncFunc = getAsyncFunc();
31 | return asyncFunc && asyncFunc.prototype === getProto(fn);
32 | };
33 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "is-async-function",
3 | "version": "2.1.1",
4 | "description": "Determine if a function is a native async function.",
5 | "main": "index.js",
6 | "exports": {
7 | ".": "./index.js",
8 | "./package.json": "./package.json"
9 | },
10 | "scripts": {
11 | "prepack": "npmignore --auto --commentLines=autogenerated",
12 | "prepublishOnly": "safe-publish-latest",
13 | "prepublish": "not-in-publish || npm run prepublishOnly",
14 | "pretest": "npm run lint",
15 | "test": "npm run tests-only",
16 | "tests-only": "nyc npm run test:all",
17 | "test:all": "npm run test:index && npm run test:uglified",
18 | "test:index": "node test",
19 | "test:uglified": "node test/uglified",
20 | "posttest": "npx npm@\">= 10.2\" audit --production",
21 | "lint": "eslint --ext=js,mjs .",
22 | "postlint": "tsc && attw -P",
23 | "version": "auto-changelog && git add CHANGELOG.md",
24 | "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
25 | },
26 | "repository": {
27 | "type": "git",
28 | "url": "git://github.com/inspect-js/is-async-function.git"
29 | },
30 | "keywords": [
31 | "async",
32 | "async function",
33 | "es6",
34 | "es2015",
35 | "yield",
36 | "function",
37 | "function*"
38 | ],
39 | "author": "Jordan Harband ",
40 | "funding": {
41 | "url": "https://github.com/sponsors/ljharb"
42 | },
43 | "license": "MIT",
44 | "bugs": {
45 | "url": "https://github.com/inspect-js/is-async-function/issues"
46 | },
47 | "dependencies": {
48 | "async-function": "^1.0.0",
49 | "call-bound": "^1.0.3",
50 | "get-proto": "^1.0.1",
51 | "has-tostringtag": "^1.0.2",
52 | "safe-regex-test": "^1.1.0"
53 | },
54 | "devDependencies": {
55 | "@arethetypeswrong/cli": "^0.17.3",
56 | "@ljharb/eslint-config": "^21.1.1",
57 | "@ljharb/tsconfig": "^0.2.3",
58 | "@types/for-each": "^0.3.3",
59 | "@types/make-async-function": "^1.0.2",
60 | "@types/make-generator-function": "^2.0.3",
61 | "@types/tape": "^5.8.1",
62 | "auto-changelog": "^2.5.0",
63 | "encoding": "^0.1.13",
64 | "eslint": "=8.8.0",
65 | "for-each": "^0.3.3",
66 | "in-publish": "^2.0.1",
67 | "make-async-function": "^1.0.0",
68 | "make-generator-function": "^2.0.0",
69 | "npmignore": "^0.3.1",
70 | "nyc": "^10.3.2",
71 | "safe-publish-latest": "^2.0.0",
72 | "tape": "^5.9.0",
73 | "typescript": "next",
74 | "uglify-register": "^1.0.1"
75 | },
76 | "testling": {
77 | "files": "test/index.js",
78 | "browsers": [
79 | "iexplore/6.0..latest",
80 | "firefox/3.0..6.0",
81 | "firefox/15.0..latest",
82 | "firefox/nightly",
83 | "chrome/4.0..10.0",
84 | "chrome/20.0..latest",
85 | "chrome/canary",
86 | "opera/10.0..latest",
87 | "opera/next",
88 | "safari/4.0..latest",
89 | "ipad/6.0..latest",
90 | "iphone/6.0..latest",
91 | "android-browser/4.2"
92 | ]
93 | },
94 | "engines": {
95 | "node": ">= 0.4"
96 | },
97 | "auto-changelog": {
98 | "output": "CHANGELOG.md",
99 | "template": "keepachangelog",
100 | "unreleased": false,
101 | "commitLimit": false,
102 | "backfillLimit": false,
103 | "hideCredit": true
104 | },
105 | "publishConfig": {
106 | "ignore": [
107 | ".github/workflows"
108 | ]
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/test/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /* globals window */
4 |
5 | var test = require('tape');
6 | var isAsyncFunction = require('../index');
7 | var generatorFuncs = require('make-generator-function')();
8 | var asyncFuncs = require('make-async-function').list();
9 | var hasToStringTag = require('has-tostringtag/shams')();
10 |
11 | var forEach = require('for-each');
12 |
13 | test('returns false for non-functions', function (t) {
14 | var nonFuncs = [
15 | true,
16 | false,
17 | null,
18 | undefined,
19 | {},
20 | [],
21 | /a/g,
22 | 'string',
23 | 42,
24 | new Date()
25 | ];
26 | t.plan(nonFuncs.length);
27 | forEach(nonFuncs, function (nonFunc) {
28 | t.notOk(isAsyncFunction(nonFunc), nonFunc + ' is not a function');
29 | });
30 | t.end();
31 | });
32 |
33 | test('returns false for non-async functions', function (t) {
34 | var func = function () {};
35 | t.notOk(isAsyncFunction(func), 'anonymous function is not an async function');
36 |
37 | var namedFunc = function foo() {};
38 | t.notOk(isAsyncFunction(namedFunc), 'named function is not an async function');
39 |
40 | if (typeof window === 'undefined') {
41 | t.skip('window.alert is not an async function');
42 | } else {
43 | t.notOk(isAsyncFunction(window.alert), 'window.alert is not an async function');
44 | }
45 | t.end();
46 | });
47 |
48 | var fakeToString = function () { return 'async function () { return "TOTALLY REAL I SWEAR!"; }'; };
49 |
50 | test('returns false for non-async function with faked toString', function (t) {
51 | var func = function () {};
52 | func.toString = fakeToString;
53 |
54 | t.notEqual(String(func), Function.prototype.toString.apply(func), 'faked toString is not real toString');
55 | t.notOk(isAsyncFunction(func), 'anonymous function with faked toString is not an async function');
56 | t.end();
57 | });
58 |
59 | test('returns false for generator functions', function (t) {
60 | if (generatorFuncs.length > 0) {
61 | forEach(generatorFuncs, function (generatorFunc) {
62 | t.notOk(isAsyncFunction(generatorFunc), generatorFunc + ' is not async function');
63 | });
64 | } else {
65 | t.skip('generator function is not async function - this environment does not support ES6 generator functions. Please use an engine that supports them.');
66 | }
67 | t.end();
68 | });
69 |
70 | test('returns false for non-async function with faked @@toStringTag', { skip: !hasToStringTag || asyncFuncs.length === 0 }, function (t) {
71 | var asyncFunc = asyncFuncs[0];
72 | /** @type {{ toString(): unknown; valueOf(): unknown; [Symbol.toStringTag]?: unknown }} */
73 | var fakeAsyncFunction = {
74 | toString: function () { return String(asyncFunc); },
75 | valueOf: function () { return asyncFunc; }
76 | };
77 | fakeAsyncFunction[Symbol.toStringTag] = 'AsyncFunction';
78 | t.notOk(isAsyncFunction(fakeAsyncFunction), 'fake AsyncFunction with @@toStringTag "AsyncFunction" is not an async function');
79 | t.end();
80 | });
81 |
82 | test('returns true for async functions', function (t) {
83 | if (asyncFuncs.length > 0) {
84 | forEach(asyncFuncs, function (asyncFunc) {
85 | t.ok(isAsyncFunction(asyncFunc), asyncFunc + ' is async function');
86 | });
87 | } else {
88 | t.skip('async function is async function - this environment does not support ES2018 async functions. Please use an engine that supports them.');
89 | }
90 | t.end();
91 | });
92 |
--------------------------------------------------------------------------------
/test/uglified.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // @ts-expect-error
4 | require('uglify-register/api').register({
5 | exclude: [/\/node_modules\//, /\/test\//],
6 | uglify: { mangle: true }
7 | });
8 |
9 | require('./');
10 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@ljharb/tsconfig",
3 | "compilerOptions": {
4 | "target": "ES2021",
5 | "maxNodeModuleJsDepth": 0,
6 | },
7 | "exclude": [
8 | "coverage",
9 | ],
10 | }
11 |
--------------------------------------------------------------------------------