is-async-function
Advanced tools
Comparing version 1.3.0 to 2.0.0
186
CHANGELOG.md
# Changelog | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
All notable changes to this project will be documented in this file. | ||
## [1.3.0](https://github.com/tunnckocore/is-async-function/compare/v1.2.4...v1.3.0) (2020-01-15) | ||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
## [v2.0.0](https://github.com/inspect-js/is-async-function/compare/v1.3.0...v2.0.0) - 2022-04-11 | ||
### Features | ||
### Commits | ||
* update deps, ci, readme ([dbb52a7](https://github.com/tunnckocore/is-async-function/commit/dbb52a7714887e897df62302a6ad8e8402d67fe4)) | ||
- [Breaking] v2 implementation and tests [`d79a37e`](https://github.com/inspect-js/is-async-function/commit/d79a37e25e24a74be3c349de51fda4ad58f30f3a) | ||
- Initial commit [`456defc`](https://github.com/inspect-js/is-async-function/commit/456defc6dc36809d11dd5a199110e46fe9fb4a6f) | ||
- npm init [`d35b611`](https://github.com/inspect-js/is-async-function/commit/d35b611d669e57a3a6fd017930d3bf9a0589ffd2) | ||
- Only apps should have lockfiles [`5920874`](https://github.com/inspect-js/is-async-function/commit/5920874ec2b26762d1037168a73e1c29a4286b1a) | ||
### [1.2.4](https://github.com/tunnckocore/is-async-function/compare/v1.2.3...v1.2.4) (2020-01-15) | ||
## [v1.3.0](https://github.com/inspect-js/is-async-function/compare/v1.2.4...v1.3.0) - 2020-01-15 | ||
### Commits | ||
### Bug Fixes | ||
- feat: update deps, ci, readme [`dbb52a7`](https://github.com/inspect-js/is-async-function/commit/dbb52a7714887e897df62302a6ad8e8402d67fe4) | ||
- chore(release): 1.3.0 [`972e26c`](https://github.com/inspect-js/is-async-function/commit/972e26c01ad14aa3560462624f24f4464efc46a3) | ||
* add npm funding field ([c05ef28](https://github.com/tunnckocore/is-async-function/commit/c05ef28a1aa33543fc29c1c897613dc8676c1afc)) | ||
* update deps + the tests; close [#17](https://github.com/tunnckocore/is-async-function/issues/17) ([f2474fc](https://github.com/tunnckocore/is-async-function/commit/f2474fcd339935b9aba7f96668a4a3c66a12a5c3)) | ||
* **src:** remove unneeded condition ([#16](https://github.com/tunnckocore/is-async-function/issues/16)) ([a4d5b41](https://github.com/tunnckocore/is-async-function/commit/a4d5b41fb38efabf735dc3f63779070b0e762c17)) | ||
## [v1.2.4](https://github.com/inspect-js/is-async-function/compare/v1.2.3...v1.2.4) - 2020-01-15 | ||
<a name="1.2.3"></a> | ||
## [1.2.3](https://github.com/tunnckocore/is-async-function/compare/v1.2.2...v1.2.3) (2017-03-11) | ||
### Merged | ||
- fix(src): remove unneeded condition [`#16`](https://github.com/inspect-js/is-async-function/pull/16) | ||
### Bug Fixes | ||
### Fixed | ||
* **docs:** regenerate readme ([592f1b7](https://github.com/tunnckocore/is-async-function/commit/592f1b7)) | ||
* **package:** add missing dependency ([73f404d](https://github.com/tunnckocore/is-async-function/commit/73f404d)) | ||
* **package:** wrong version, because too fast update ;d ([2e887f0](https://github.com/tunnckocore/is-async-function/commit/2e887f0)) | ||
* **style:** remove lazy-cache, and update boilerplate stuff ([abd32db](https://github.com/tunnckocore/is-async-function/commit/abd32db)) | ||
- fix: update deps + the tests; close #17 [`#17`](https://github.com/inspect-js/is-async-function/issues/17) | ||
### Commits | ||
- chore: update broken badge links [`2985e36`](https://github.com/inspect-js/is-async-function/commit/2985e36a644306ab2beb392e6833860cc1b3dadf) | ||
- chore: add github funding file [`377233a`](https://github.com/inspect-js/is-async-function/commit/377233ab85f042e68b4cf5c7fd91860b77e8ce53) | ||
- chore: all modules are stable for years [`b7db9f0`](https://github.com/inspect-js/is-async-function/commit/b7db9f07cfcd8e3f7f7c448f71dcf73ef0e9b67e) | ||
- chore(release): 1.2.4 [`a9f441f`](https://github.com/inspect-js/is-async-function/commit/a9f441f0b801dabf6e8a1690c871fd564e56ddad) | ||
- fix: add npm funding field [`c05ef28`](https://github.com/inspect-js/is-async-function/commit/c05ef28a1aa33543fc29c1c897613dc8676c1afc) | ||
- chore: drop testing on old Node versions [`c975f68`](https://github.com/inspect-js/is-async-function/commit/c975f68a788d99ebf109a34ed9867f19c85b8805) | ||
- chore(ci): test on 6 only [`106dcdd`](https://github.com/inspect-js/is-async-function/commit/106dcdd6d225248ef55c41218706fef1a7ce8c0e) | ||
<a name="1.2.2"></a> | ||
## [1.2.2](https://github.com/tunnckocore/is-async-function/compare/v1.2.1...v1.2.2) (2016-10-29) | ||
## [v1.2.3](https://github.com/inspect-js/is-async-function/compare/v1.2.2...v1.2.3) - 2017-03-11 | ||
### Commits | ||
### Bug Fixes | ||
- fix(style): remove lazy-cache, and update boilerplate stuff [`abd32db`](https://github.com/inspect-js/is-async-function/commit/abd32dba0d727e9a75fffa7ef7df138bbc722b69) | ||
- fix(docs): regenerate readme [`592f1b7`](https://github.com/inspect-js/is-async-function/commit/592f1b721c7c81bc1a6a84e462f4bd7ba7f24cd3) | ||
- fix(package): add missing dependency [`73f404d`](https://github.com/inspect-js/is-async-function/commit/73f404d9afc054c90c1f1bee280497ac809b1eb3) | ||
- chore(release): 1.2.3 [`103cf28`](https://github.com/inspect-js/is-async-function/commit/103cf28cfa5302a5a00bb5c9bd8bf9ecc69999fa) | ||
- fix(package): wrong version, because too fast update ;d [`2e887f0`](https://github.com/inspect-js/is-async-function/commit/2e887f09dbc9e234f5f26cadd4e7fe9cc97184fb) | ||
* **docs:** fixes and updates API docs ([b909ae7](https://github.com/tunnckocore/is-async-function/commit/b909ae7)), closes [#14](https://github.com/tunnckocore/is-async-function/issues/14) | ||
## [v1.2.2](https://github.com/inspect-js/is-async-function/compare/v1.2.1...v1.2.2) - 2016-10-29 | ||
### Fixed | ||
- fix(docs): fixes and updates API docs [`#14`](https://github.com/inspect-js/is-async-function/issues/14) | ||
<a name="1.2.1"></a> | ||
## [1.2.1](https://github.com/tunnckocore/is-async-function/compare/v1.2.0...v1.2.1) (2016-10-27) | ||
### Commits | ||
- chore(release): 1.2.2 [`9165f94`](https://github.com/inspect-js/is-async-function/commit/9165f942865906a02e0f9afe55ac2f305d71a9b1) | ||
### Bug Fixes | ||
## [v1.2.1](https://github.com/inspect-js/is-async-function/compare/v1.2.0...v1.2.1) - 2016-10-27 | ||
* **non-strict:** fix a bug in non-strict mode ([2d25126](https://github.com/tunnckocore/is-async-function/commit/2d25126)), closes [#13](https://github.com/tunnckocore/is-async-function/issues/13) | ||
### Fixed | ||
- fix(non-strict): fix a bug in non-strict mode [`#13`](https://github.com/inspect-js/is-async-function/issues/13) | ||
### Commits | ||
<a name="1.2.0"></a> | ||
# [1.2.0](https://github.com/tunnckocore/is-async-function/compare/v1.1.5...v1.2.0) (2016-10-27) | ||
- chore(release): 1.2.1 [`f4c7f02`](https://github.com/inspect-js/is-async-function/commit/f4c7f02ecb1ca02772890552797da3b39883ed43) | ||
## [v1.2.0](https://github.com/inspect-js/is-async-function/compare/v1.1.5...v1.2.0) - 2016-10-27 | ||
### Features | ||
### Merged | ||
* **strict:** introduce strict mode ([ef8526f](https://github.com/tunnckocore/is-async-function/commit/ef8526f)) | ||
- Revert "Update arr-includes to version 2.0.0 🚀" [`#12`](https://github.com/inspect-js/is-async-function/pull/12) | ||
- chore(package): update arr-includes to version 2.0.0 [`#11`](https://github.com/inspect-js/is-async-function/pull/11) | ||
### Commits | ||
- feat(strict): introduce strict mode [`ef8526f`](https://github.com/inspect-js/is-async-function/commit/ef8526ffa8ba2b4cf37f6bd2dae21aee871e6e6a) | ||
- docs(update): api docs [`739eb54`](https://github.com/inspect-js/is-async-function/commit/739eb5482ba560ad2de153a29fc16778f4d3ef3f) | ||
- chore(release): 1.2.0 [`3222afe`](https://github.com/inspect-js/is-async-function/commit/3222afed47c9b5d2fa12490aff2d7c9887183ea2) | ||
## [v1.1.5](https://github.com/inspect-js/is-async-function/compare/v1.1.4...v1.1.5) - 2016-09-21 | ||
### Commits | ||
## 1.1.5 - 2016-09-21 | ||
- Release v1.1.5 / npm@v1.1.5 | ||
- update tests to cleanup codeclimate issues | ||
- chore(tests): simplify tests [`be112bb`](https://github.com/inspect-js/is-async-function/commit/be112bb3dec204f174bf745056b7c0fc7377aef5) | ||
- Release v1.1.5 [`577d96c`](https://github.com/inspect-js/is-async-function/commit/577d96c9f0fb6288e6bc88d8e51703b98f19b20c) | ||
## 1.1.4 - 2016-09-21 | ||
- Release v1.1.4 / npm@v1.1.4 | ||
- use `lazy-cache` and `lazy-arrayify`, closes #10 | ||
- add support for `names` to be a string, not only array of strings | ||
- update to use `mukla` instead of `assertit` | ||
- update npm scripts | ||
- update travis builds and coverage things | ||
- update gitignore | ||
- update editorconfig | ||
- add `standard`, `nyc` and `coveralls` to devDeps | ||
## [v1.1.4](https://github.com/inspect-js/is-async-function/compare/v1.1.3...v1.1.4) - 2016-09-21 | ||
## 1.1.3 - 2016-04-21 | ||
- Release v1.1.3 / npm@v1.1.3 | ||
- use `common-callback-names` package | ||
- bump deps | ||
### Fixed | ||
## 1.1.2 - 2016-03-18 | ||
- Release v1.1.2 / npm@v1.1.2 | ||
- update metadata, keyword | ||
- update docs, description | ||
- cleanup unused arguments | ||
- chore(package): update deps, use lazy-cache - closes #10 [`#10`](https://github.com/inspect-js/is-async-function/issues/10) | ||
## 1.1.1 - 2016-03-18 | ||
- Release v1.1.1 / npm@v1.1.1 | ||
- add related libs | ||
- update docs | ||
- update description | ||
- add docs | ||
r- efactor, allow passing custom array of argument names | ||
- run update - lint, lincense year, metadata, boilerplate stuff | ||
### Commits | ||
## 1.1.0 - 2015-06-25 | ||
- Release v1.1.0 / npm@v1.1.0 | ||
- update metadata | ||
- add check for `done` and `next` | ||
- chore(package/tests): update to use `mukla` instead of `assertit` lib [`83011b1`](https://github.com/inspect-js/is-async-function/commit/83011b1e2820e239c606d872468582f5a9249c47) | ||
- chore(package): update npm scripts, add coveralls/standard/nyc to devDeps [`631acbd`](https://github.com/inspect-js/is-async-function/commit/631acbdcf9fd9aa6d56ac98e10f3092e7e5be485) | ||
- chore(gitignore): update gitignore [`7f09f8f`](https://github.com/inspect-js/is-async-function/commit/7f09f8f40777879e70315dfeef0805755a44a293) | ||
- chore(editorconfig): update editorconfig [`8bb8593`](https://github.com/inspect-js/is-async-function/commit/8bb85939f87e6738c5ca35b5e5f5d8cca67353c9) | ||
- docs(readme): run verb to update readme [`cf15044`](https://github.com/inspect-js/is-async-function/commit/cf150446dc4e948f2629377d7f369824bfda8b3b) | ||
- Release v1.1.4 [`41190e1`](https://github.com/inspect-js/is-async-function/commit/41190e1da3aeb787921b3ea5d834634295c31de8) | ||
## 1.0.0 - 2015-06-05 | ||
- Release v1.0.0 / npm@v1.0.0 | ||
- add test for when throw | ||
- refactor | ||
- add `related` section | ||
- add keywords | ||
- implement | ||
## [v1.1.3](https://github.com/inspect-js/is-async-function/compare/v1.1.2...v1.1.3) - 2016-04-21 | ||
## 0.0.0 - 2015-06-05 | ||
- first commits | ||
### Merged | ||
- chore(package): update is-match to version 0.4.1 [`#7`](https://github.com/inspect-js/is-async-function/pull/7) | ||
### Commits | ||
- use `common-callback-names` [`37c253f`](https://github.com/inspect-js/is-async-function/commit/37c253f9a34b68acd5651075a3f1b74cd30ed8fd) | ||
- Release v1.1.3 [`f212193`](https://github.com/inspect-js/is-async-function/commit/f212193a00790ccae387e2d7a373076fcbbb9d8f) | ||
## [v1.1.2](https://github.com/inspect-js/is-async-function/compare/v1.1.1...v1.1.2) - 2016-03-18 | ||
### Commits | ||
- cleanup and update metadata [`e09ab8b`](https://github.com/inspect-js/is-async-function/commit/e09ab8b98e6aecd28d38ba4ff4c1f17c26549a06) | ||
- update docs [`42920c6`](https://github.com/inspect-js/is-async-function/commit/42920c699f706fcf1048e0c039b335d7bbaf34ed) | ||
- Release v1.1.2 [`19d77d6`](https://github.com/inspect-js/is-async-function/commit/19d77d6ba7abe87ecf4d2765cd8536fca140b3bd) | ||
## [v1.1.1](https://github.com/inspect-js/is-async-function/compare/v1.1.0...v1.1.1) - 2016-03-18 | ||
### Commits | ||
- run update [`27b21bf`](https://github.com/inspect-js/is-async-function/commit/27b21bf76254635d6c5c18f896b6f151938ae810) | ||
- add docs [`ab38f94`](https://github.com/inspect-js/is-async-function/commit/ab38f947707182e0ea165e3bee90bd46b8dbfaf9) | ||
- update docs [`90654c9`](https://github.com/inspect-js/is-async-function/commit/90654c93e8ff9d0cfd1443ae3609cd898b57ef11) | ||
- refactor, allow passing custom array of argument names [`a1787c7`](https://github.com/inspect-js/is-async-function/commit/a1787c757f522cb5e1c568ec5270be14a38c4cc9) | ||
- add related libs [`868f423`](https://github.com/inspect-js/is-async-function/commit/868f4235a449d610a87351e5a5070f42a0c6e7ce) | ||
- Release v1.1.1 [`bc7d85e`](https://github.com/inspect-js/is-async-function/commit/bc7d85e2a115163d3b09f78be5196f21adce1a7c) | ||
- update description [`ce2e97b`](https://github.com/inspect-js/is-async-function/commit/ce2e97b34762f2087699a5b9910e498ec7062090) | ||
## [v1.1.0](https://github.com/inspect-js/is-async-function/compare/v1.0.0...v1.1.0) - 2015-06-25 | ||
### Commits | ||
- Release v1.1.0 [`b3f3704`](https://github.com/inspect-js/is-async-function/commit/b3f3704f13a32664a08b3d55162925e37626f5e8) | ||
- update metadata [`95e6bc2`](https://github.com/inspect-js/is-async-function/commit/95e6bc2cc195ff5d2ab01f47c6a157b3a583d01a) | ||
- check also for `done` and `next` [`6697d29`](https://github.com/inspect-js/is-async-function/commit/6697d29430ac9ce5f55572a2d7762baa1f05a33b) | ||
## v1.0.0 - 2015-06-05 | ||
### Commits | ||
- :cat2: implement :star2: [`eaccc68`](https://github.com/inspect-js/is-async-function/commit/eaccc681838a983390e93607451500982759bd7a) | ||
- add keywords [`55a5ffc`](https://github.com/inspect-js/is-async-function/commit/55a5ffc65d344328cf5b5bb7b7e1520ecede0035) | ||
- Release v1.0.0 [`66eab5f`](https://github.com/inspect-js/is-async-function/commit/66eab5f96c62a6a39b913a84e8ec4b37c657026a) | ||
- refactor [`a7ce00d`](https://github.com/inspect-js/is-async-function/commit/a7ce00d537bf420338b91fee00eb6893d14952bf) | ||
- add test for when throw [`60d0175`](https://github.com/inspect-js/is-async-function/commit/60d0175a955645b304f572fd571a1ced47486958) | ||
- add `related` section [`904acd8`](https://github.com/inspect-js/is-async-function/commit/904acd8fbd5c6c020ba537cc9962154d818ad067) | ||
- simplify travis [`ee17273`](https://github.com/inspect-js/is-async-function/commit/ee172737486a8a5f7b2b642aa72e6ca7a1749a1c) | ||
- Initial commit [`7e914c1`](https://github.com/inspect-js/is-async-function/commit/7e914c1c6d669635f239fa86d9d96f85d8aaaab4) |
101
index.js
@@ -1,67 +0,38 @@ | ||
/*! | ||
* is-async-function <https://github.com/tunnckoCore/is-async-function> | ||
* | ||
* Copyright (c) Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online) | ||
* Released under the MIT license. | ||
*/ | ||
'use strict'; | ||
'use strict' | ||
var toStr = Object.prototype.toString; | ||
var fnToStr = Function.prototype.toString; | ||
var isFnRegex = /^\s*async(?:\s+function(?:\s+|\()|\s*\()/; | ||
var hasToStringTag = require('has-tostringtag/shams')(); | ||
var getProto = Object.getPrototypeOf; | ||
var getAsyncFunc = function () { // eslint-disable-line consistent-return | ||
if (!hasToStringTag) { | ||
return false; | ||
} | ||
try { | ||
return Function('return async function () {}')(); | ||
} catch (e) { | ||
} | ||
}; | ||
var AsyncFunction; | ||
var arrayify = require('arrify') | ||
var arrIncludes = require('arr-includes') | ||
var callbackNames = require('common-callback-names') | ||
var functionArguments = require('function-arguments') | ||
/* istanbul ignore next */ | ||
arrIncludes = arrIncludes.default || arrIncludes | ||
/** | ||
* > Trying to guess is `fn` asynchronous function or not. | ||
* But not [is-callback-function][] be aware of that diff. | ||
* | ||
* **Example** | ||
* | ||
* ```js | ||
* var fs = require('fs') | ||
* var isAsyncFn = require('is-async-function') | ||
* | ||
* console.log(isAsyncFunction(fs.readFile)) // => true | ||
* console.log(isAsyncFunction(fs.stat)) // => true | ||
* | ||
* console.log(isAsyncFunction(fs.readFileSync)) // => false | ||
* console.log(isAsyncFunction(fs.statSync)) // => false | ||
* | ||
* // or pass custom names to recognize as `async` | ||
* console.log(isAsyncFunction(fs.stat, ['cb'])) // => false | ||
* console.log(isAsyncFunction(fs.readFile, ['foo', 'bar'])) | ||
* // => false, because fs.readFile uses `cb` | ||
* ``` | ||
* | ||
* @param {Function} `fn` is this `fn` a callback function | ||
* @param {Array} `names` arguments names, default are [common-callback-names][] | ||
* @param {Boolean} `strict` defaults to `true` to always return a boolean, | ||
* pass `false` to get index (position) - this is | ||
* useful when you wanna understand which "callback name" | ||
* exists as argument in that `fn` | ||
* @return {Boolean|Number} always boolean `true` or `false` when on strict mode, | ||
* othewise it can be Number index representing the position | ||
* and if index is 0 it is transformed to boolean `true` - so | ||
* always positive value if function is async. | ||
* @api public | ||
*/ | ||
module.exports = function isAsyncFunction (fn, names, strict) { | ||
if (typeof fn !== 'function') { | ||
throw new TypeError('is-async-function expect a function') | ||
} | ||
strict = typeof names === 'boolean' ? names : strict | ||
strict = typeof strict === 'boolean' ? strict : true | ||
names = typeof names === 'boolean' ? null : names | ||
names = arrayify(names) | ||
names = names.length ? names : callbackNames | ||
var idx = arrIncludes(names, functionArguments(fn)) | ||
return strict ? Boolean(idx) : idx | ||
} | ||
module.exports = function isAsyncFunction(fn) { | ||
if (typeof fn !== 'function') { | ||
return false; | ||
} | ||
if (isFnRegex.test(fnToStr.call(fn))) { | ||
return true; | ||
} | ||
if (!hasToStringTag) { | ||
var str = toStr.call(fn); | ||
return str === '[object AsyncFunction]'; | ||
} | ||
if (!getProto) { | ||
return false; | ||
} | ||
if (typeof AsyncFunction === 'undefined') { | ||
var asyncFunc = getAsyncFunc(); | ||
AsyncFunction = asyncFunc ? getProto(asyncFunc) : false; | ||
} | ||
return getProto(fn) === AsyncFunction; | ||
}; |
204
package.json
{ | ||
"name": "is-async-function", | ||
"version": "1.3.0", | ||
"description": "Is function really asynchronous function? Trying to guess that based on check if [common-callback-names][] exists as function arguments names or you can pass your custom.", | ||
"repository": "tunnckoCore/is-async-function", | ||
"author": "Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online)", | ||
"precommit.silent": true, | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"lint": "standard index.js test.js --fix --verbose", | ||
"test": "npm-run-all -s lint test:*", | ||
"test:api": "nyc --reporter lcov node test.js", | ||
"test:report": "nyc report", | ||
"prerelease": "npm test", | ||
"release": "standard-version --sign --no-verify", | ||
"git": "npm-run-all -s git:*", | ||
"git:add": "git add --all", | ||
"git:cz": "git-cz", | ||
"commit": "npm-run-all -s test git" | ||
}, | ||
"dependencies": { | ||
"arr-includes": "^2.2.0", | ||
"arrify": "^2.0.1", | ||
"common-callback-names": "^2.0.1", | ||
"function-arguments": "^1.0.8" | ||
}, | ||
"devDependencies": { | ||
"commitizen": "^4.0.3", | ||
"cz-conventional-changelog": "^3.0.2", | ||
"micromatch": "^4.0.2", | ||
"mukla": "^0.4.9", | ||
"npm-run-all": "^4.1.5", | ||
"nyc": "^15.0.0", | ||
"pre-commit": "^1.2.2", | ||
"standard": "^14.3.1", | ||
"standard-version": "^7.0.1" | ||
}, | ||
"funding": { | ||
"url": "https://ko-fi.com/tunnckoCore" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"assume", | ||
"async", | ||
"callback", | ||
"cb", | ||
"check", | ||
"common", | ||
"done", | ||
"exist", | ||
"fn", | ||
"func", | ||
"function", | ||
"is", | ||
"is-async-function", | ||
"names", | ||
"next", | ||
"really", | ||
"util", | ||
"validate" | ||
], | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"verb": { | ||
"run": true, | ||
"toc": { | ||
"render": true, | ||
"method": "preWrite", | ||
"maxdepth": 3 | ||
}, | ||
"layout": "empty", | ||
"tasks": [ | ||
"readme" | ||
], | ||
"related": { | ||
"list": [ | ||
"function-arguments", | ||
"fn-args", | ||
"get-fn-name", | ||
"fn-name", | ||
"parse-function", | ||
"is-callback-function", | ||
"common-callback-names", | ||
"always-done", | ||
"minibase", | ||
"try-catch-core" | ||
], | ||
"highlight": "always-done" | ||
}, | ||
"lint": { | ||
"reflinks": true | ||
}, | ||
"reflinks": [ | ||
"always-done", | ||
"async-done", | ||
"base", | ||
"charlike", | ||
"commitizen", | ||
"common-callback-names", | ||
"dezalgo", | ||
"fn-name", | ||
"is-callback-function", | ||
"once", | ||
"standard-version", | ||
"verb", | ||
"verb-generate-readme" | ||
] | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"statements": 100, | ||
"functions": 100, | ||
"branches": 100, | ||
"lines": 100 | ||
} | ||
"name": "is-async-function", | ||
"version": "2.0.0", | ||
"description": "Determine if a function is a native async function.", | ||
"main": "index.js", | ||
"scripts": { | ||
"prepublishOnly": "safe-publish-latest", | ||
"prepublish": "not-in-publish || npm run prepublishOnly", | ||
"pretest": "npm run lint", | ||
"test": "npm run tests-only", | ||
"tests-only": "nyc npm run test:all", | ||
"test:all": "npm run test:index && npm run test:uglified", | ||
"test:index": "node test", | ||
"test:uglified": "node test/uglified", | ||
"posttest": "aud --production", | ||
"lint": "eslint --ext=js,mjs .", | ||
"version": "auto-changelog && git add CHANGELOG.md", | ||
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/inspect-js/is-async-function.git" | ||
}, | ||
"keywords": [ | ||
"async", | ||
"async function", | ||
"es6", | ||
"es2015", | ||
"yield", | ||
"function", | ||
"function*" | ||
], | ||
"author": "Jordan Harband <ljharb@gmail.com>", | ||
"funding": { | ||
"url": "https://github.com/sponsors/ljharb" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/inspect-js/is-async-function/issues" | ||
}, | ||
"dependencies": { | ||
"has-tostringtag": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^21.0.0", | ||
"aud": "^2.0.0", | ||
"auto-changelog": "^2.4.0", | ||
"eslint": "=8.8.0", | ||
"in-publish": "^2.0.1", | ||
"make-async-function": "^1.0.0", | ||
"make-generator-function": "^2.0.0", | ||
"nyc": "^10.3.2", | ||
"safe-publish-latest": "^2.0.0", | ||
"tape": "^5.5.3", | ||
"uglify-register": "^1.0.1" | ||
}, | ||
"testling": { | ||
"files": "test/index.js", | ||
"browsers": [ | ||
"iexplore/6.0..latest", | ||
"firefox/3.0..6.0", | ||
"firefox/15.0..latest", | ||
"firefox/nightly", | ||
"chrome/4.0..10.0", | ||
"chrome/20.0..latest", | ||
"chrome/canary", | ||
"opera/10.0..latest", | ||
"opera/next", | ||
"safari/4.0..latest", | ||
"ipad/6.0..latest", | ||
"iphone/6.0..latest", | ||
"android-browser/4.2" | ||
] | ||
}, | ||
"engines": { | ||
"node": ">= 0.4" | ||
}, | ||
"auto-changelog": { | ||
"output": "CHANGELOG.md", | ||
"template": "keepachangelog", | ||
"unreleased": false, | ||
"commitLimit": false, | ||
"backfillLimit": false, | ||
"hideCredit": true | ||
} | ||
} |
241
README.md
@@ -1,218 +0,41 @@ | ||
# is-async-function [![npm version][npmv-img]][npmv-url] [![mit license][license-img]][license-url] [![NPM monthly downloads](https://img.shields.io/npm/dm/is-async-function.svg?style=flat)](https://npmjs.org/package/is-async-function) [![npm total downloads][downloads-img]][downloads-url] | ||
# is-async-function <sup>[![Version Badge][2]][1]</sup> | ||
> Is function really asynchronous function? Trying to guess that based on check if [common-callback-names][] exists as function arguments names or you can pass your custom. | ||
[![github actions][actions-image]][actions-url] | ||
[![coverage][codecov-image]][codecov-url] | ||
[![dependency status][5]][6] | ||
[![dev dependency status][7]][8] | ||
[![License][license-image]][license-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
[![code style][standard-img]][standard-url] | ||
[![linux build][travis-img]][travis-url] | ||
[![code coverage][coverage-img]][coverage-url] | ||
[![dependency status][david-img]][david-url] | ||
[![paypal donate][paypalme-img]][paypalme-url] | ||
[![Buy me a Kofi][kofi-img]][kofi-url] | ||
[![npm badge][11]][1] | ||
You might also be interested in [always-done](https://github.com/hybridables/always-done#readme). | ||
Is this a native `async function`? | ||
## Table of Contents | ||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [API](#api) | ||
* [isAsyncFunction](#isasyncfunction) | ||
- [Related](#related) | ||
- [Contributing](#contributing) | ||
- [Building docs](#building-docs) | ||
- [Running tests](#running-tests) | ||
- [Author](#author) | ||
- [License](#license) | ||
## Example | ||
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_ | ||
## Install | ||
Install with [npm](https://www.npmjs.com/) | ||
``` | ||
$ npm install is-async-function --save | ||
``` | ||
or install using [yarn](https://yarnpkg.com) | ||
``` | ||
$ yarn add is-async-function | ||
``` | ||
## Usage | ||
> For more use-cases see the [tests](test.js) | ||
```js | ||
const isAsyncFunction = require('is-async-function') | ||
var isAsyncFunction = require('is-async-function'); | ||
assert(!isAsyncFunction(function () {})); | ||
assert(!isAsyncFunction(null)); | ||
assert(!isAsyncFunction(function* () { yield 42; return Infinity; })); | ||
assert(isAsyncFunction(async function () {})); | ||
``` | ||
_**Important Note:** It may fail, if the given function is using "default params" like `options = { foo: 1 }`. | ||
That limitation comes currently from the `function-arguments` package. It may or may not be fixed there in future._ | ||
## Tests | ||
Simply clone the repo, `npm install`, and run `npm test` | ||
## API | ||
### [isAsyncFunction](index.js#L53) | ||
> Trying to guess is `fn` asynchronous function or not. But not [is-callback-function][] be aware of that diff. | ||
**Params** | ||
* `fn` **{Function}**: is this `fn` a callback function | ||
* `names` **{Array}**: arguments names, default are [common-callback-names][] | ||
* `strict` **{Boolean}**: defaults to `true` to always return a boolean, pass `false` to get index (position) - this is useful when you wanna understand which "callback name" exists as argument in that `fn` | ||
* `returns` **{Boolean|Number}**: always boolean `true` or `false` when on strict mode, othewise it can be Number index representing the position and if index is 0 it is transformed to boolean `true` - so always positive value if function is async. | ||
**Example** | ||
```js | ||
var fs = require('fs') | ||
var isAsyncFn = require('is-async-function') | ||
console.log(isAsyncFunction(fs.readFile)) // => true | ||
console.log(isAsyncFunction(fs.stat)) // => true | ||
console.log(isAsyncFunction(fs.readFileSync)) // => false | ||
console.log(isAsyncFunction(fs.statSync)) // => false | ||
// or pass custom names to recognize as `async` | ||
console.log(isAsyncFunction(fs.stat, ['cb'])) // => false | ||
console.log(isAsyncFunction(fs.readFile, ['foo', 'bar'])) | ||
// => false, because fs.readFile uses `cb` | ||
``` | ||
**non-strict mode** | ||
> passing `false` as second or third argument | ||
```js | ||
var isAsyncFunction = require('is-async-function') | ||
console.log(isAsyncFunction(fs.readFile, false)) // => 2 | ||
// => 2, because it callback argument is called `cb` | ||
// and that's the third element in `common-callback-names` array | ||
console.log(isAsyncFunction(fs.stat, false)) // => 1 | ||
// => 1, because it callback argument is called `callback_` | ||
// and that's the second element in `common-callback-names` array | ||
``` | ||
**Side note:** In previous nodejs versions it was called in a few different ways - `cb_`, `callback_` and etc. That's why [common-callback-names][] exists. As in v7 it seems everything now is called `callback`. So in most of the cases you will get boolean `true` always - both in strict and non-strict mode. In non-strict mode that will mean your function has argument called `callback`. | ||
If you pass array of names as second argument, in non-strict mode you will get index of that array. | ||
**Example** | ||
```js | ||
var isAsyncFn = require('is-async-function') | ||
// you considered you callback fucntion | ||
// to be called `qux` for some reason | ||
function myAsyncFn (foo, bar, qux) { | ||
qux(null, 123) | ||
} | ||
console.log(isAsyncFn(myAsyncFn)) // => false | ||
console.log(isAsyncFn(myAsyncFn, false)) // => false | ||
console.log(isAsyncFn(myAsyncFn, ['callback', 'qux'], false)) // => 1 | ||
// you are getting "1", because `qux` is second item | ||
// in provided `names` array. | ||
``` | ||
## Related | ||
- [always-done](https://www.npmjs.com/package/always-done): Handle completion and errors with elegance! Support for streams, callbacks, promises, child processes, async/await and sync functions. A drop-in replacement… [more](https://github.com/hybridables/always-done#readme) | [homepage](https://github.com/hybridables/always-done#readme "Handle completion and errors with elegance! Support for streams, callbacks, promises, child processes, async/await and sync functions. A drop-in replacement for [async-done][] - pass 100% of its tests plus more") | ||
- [common-callback-names](https://www.npmjs.com/package/common-callback-names): List of common callback names - callback, cb, callback_, next, done. | [homepage](https://github.com/tunnckocore/common-callback-names#readme "List of common callback names - callback, cb, callback_, next, done.") | ||
- [fn-args](https://www.npmjs.com/package/fn-args): Get the arguments of a function, arrow function, generator function, async function | [homepage](https://github.com/sindresorhus/fn-args#readme "Get the arguments of a function, arrow function, generator function, async function") | ||
- [fn-name](https://www.npmjs.com/package/fn-name): Get the name of a named function | [homepage](https://github.com/sindresorhus/fn-name#readme "Get the name of a named function") | ||
- [function-arguments](https://www.npmjs.com/package/function-arguments): Get arguments of a function, useful for and used in dependency injectors. Works for regular functions, generator functions and arrow… [more](https://github.com/tunnckocore/function-arguments#readme) | [homepage](https://github.com/tunnckocore/function-arguments#readme "Get arguments of a function, useful for and used in dependency injectors. Works for regular functions, generator functions and arrow functions.") | ||
- [get-fn-name](https://www.npmjs.com/package/get-fn-name): Get function name with strictness and correctness in mind. Also works for arrow functions and getting correct name of bounded… [more](https://github.com/tunnckocore/get-fn-name#readme) | [homepage](https://github.com/tunnckocore/get-fn-name#readme "Get function name with strictness and correctness in mind. Also works for arrow functions and getting correct name of bounded functions. Powered by [fn-name][].") | ||
- [is-callback-function](https://www.npmjs.com/package/is-callback-function): Returns true if function is a callback. Checks its name is one of [common-callback-names][] - callback, cb, cb_, callback_, next… [more](https://github.com/tunnckocore/is-callback-function#readme) | [homepage](https://github.com/tunnckocore/is-callback-function#readme "Returns true if function is a callback. Checks its name is one of [common-callback-names][] - callback, cb, cb_, callback_, next, done, they can be customized, these are default.") | ||
- [minibase](https://www.npmjs.com/package/minibase): Minimalist alternative for Base. Build complex APIs with small units called plugins. Works well with most of the already existing… [more](https://github.com/node-minibase/minibase#readme) | [homepage](https://github.com/node-minibase/minibase#readme "Minimalist alternative for Base. Build complex APIs with small units called plugins. Works well with most of the already existing [base][] plugins.") | ||
- [parse-function](https://www.npmjs.com/package/parse-function): Parse a function into an object using espree, acorn or babylon parsers. Extensible through Smart Plugins | [homepage](https://tunnckocore.com/opensource "Parse a function into an object using espree, acorn or babylon parsers. Extensible through Smart Plugins") | ||
- [try-catch-core](https://www.npmjs.com/package/try-catch-core): Low-level package to handle completion and errors of sync or asynchronous functions, using [once][] and [dezalgo][] libs. Useful for and… [more](https://github.com/hybridables/try-catch-core#readme) | [homepage](https://github.com/hybridables/try-catch-core#readme "Low-level package to handle completion and errors of sync or asynchronous functions, using [once][] and [dezalgo][] libs. Useful for and used in higher-level libs such as [always-done][] to handle completion of anything.") | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/tunnckoCore/is-async-function/issues/new). | ||
Please read the [contributing guidelines](CONTRIBUTING.md) for advice on opening issues, pull requests, and coding standards. | ||
If you need some help and can spent some cash, feel free to [contact me at CodeMentor.io](https://www.codementor.io/tunnckocore?utm_source=github&utm_medium=button&utm_term=tunnckocore&utm_campaign=github) too. | ||
**In short:** If you want to contribute to that project, please follow these things | ||
1. Please DO NOT edit [README.md](README.md), [CHANGELOG.md](CHANGELOG.md) and [.verb.md](.verb.md) files. See ["Building docs"](#building-docs) section. | ||
2. Ensure anything is okey by installing the dependencies and run the tests. See ["Running tests"](#running-tests) section. | ||
3. Always use `npm run commit` to commit changes instead of `git commit`, because it is interactive and user-friendly. It uses [commitizen][] behind the scenes, which follows Conventional Changelog idealogy. | ||
4. Do NOT bump the version in package.json. For that we use `npm run release`, which is [standard-version][] and follows Conventional Changelog idealogy. | ||
Thanks a lot! :) | ||
## Building docs | ||
Documentation and that readme is generated using [verb-generate-readme][], which is a [verb][] generator, so you need to install both of them and then run `verb` command like that | ||
``` | ||
$ npm install verbose/verb#dev verb-generate-readme --global && verb | ||
``` | ||
_Please don't edit the README directly. Any changes to the readme must be made in [.verb.md](.verb.md)._ | ||
## Running tests | ||
Clone repository and run the following in that cloned directory | ||
``` | ||
$ npm install && npm test | ||
``` | ||
## Author | ||
**Charlike Mike Reagent** | ||
+ [GitHub Profile](https://github.com/Charlike Mike Reagent) | ||
+ [Twitter Profile](https://twitter.com/Charlike Mike Reagent) | ||
+ [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) | ||
+ [codementor/tunnckoCore](https://codementor.io/tunnckoCore) | ||
## License | ||
Copyright © 2015, 2020, [Charlike Mike Reagent](https://i.am.charlike.online). Released under the [MIT License](LICENSE). | ||
*** | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on January 15, 2020._ | ||
_Project scaffolded using [charlike][] cli._ | ||
[always-done]: https://github.com/hybridables/always-done | ||
[async-done]: https://github.com/gulpjs/async-done | ||
[base]: https://github.com/node-base/base | ||
[charlike]: https://github.com/tunnckoCoreLabs/charlike | ||
[commitizen]: https://github.com/commitizen/cz-cli | ||
[common-callback-names]: https://github.com/tunnckocore/common-callback-names | ||
[dezalgo]: https://github.com/npm/dezalgo | ||
[fn-name]: https://github.com/sindresorhus/fn-name | ||
[is-callback-function]: https://github.com/tunnckocore/is-callback-function | ||
[once]: https://github.com/isaacs/once | ||
[standard-version]: https://github.com/conventional-changelog/standard-version | ||
[verb-generate-readme]: https://github.com/verbose/verb-generate-readme | ||
[verb]: https://github.com/verbose/verb | ||
[license-url]: https://www.npmjs.com/package/is-async-function | ||
[license-img]: https://badgen.net/npm/license/is-async-function | ||
[downloads-url]: https://www.npmjs.com/package/is-async-function | ||
[downloads-img]: https://badgen.net/npm/dt/is-async-function | ||
[travis-url]: https://travis-ci.org/tunnckoCore/is-async-function | ||
[travis-img]: https://badgen.net/travis/tunnckoCore/is-async-function/master?label=build&icon=travis | ||
[coverage-url]: https://codecov.io/gh/tunnckoCore/is-async-function | ||
[coverage-img]: https://badgen.net/codecov/c/github/tunnckoCore/is-async-function/master | ||
[david-url]: https://david-dm.org/tunnckoCore/is-async-function | ||
[david-img]: https://badgen.net/david/dep/tunnckoCore/is-async-function | ||
[standard-url]: https://github.com/feross/standard | ||
[standard-img]: https://badgen.net/badge/code%20style/standard/green | ||
[paypalme-url]: https://www.paypal.me/tunnckoCore | ||
[paypalme-img]: https://badgen.net/badge/paypal/donate/green | ||
[kofi-url]: https://ko-fi.com/tunnckoCore | ||
[kofi-img]: https://badgen.net/badge/Buy%20me/a%20coffee/29abe0c2?icon=https://rawcdn.githack.com/tunnckoCore/badgen-icons/f8264c6414e0bec449dd86f2241d50a9b89a1203/icons/kofi.svg | ||
[npmv-url]: https://www.npmjs.com/package/is-async-function | ||
[npmv-img]: https://badgen.net/npm/v/is-async-function?icon=npm | ||
[1]: https://npmjs.org/package/is-async-function | ||
[2]: https://versionbadg.es/inspect-js/is-async-function.svg | ||
[5]: https://david-dm.org/inspect-js/is-async-function.svg | ||
[6]: https://david-dm.org/inspect-js/is-async-function | ||
[7]: https://david-dm.org/inspect-js/is-async-function/dev-status.svg | ||
[8]: https://david-dm.org/inspect-js/is-async-function#info=devDependencies | ||
[11]: https://nodei.co/npm/is-async-function.png?downloads=true&stars=true | ||
[license-image]: https://img.shields.io/npm/l/is-async-function.svg | ||
[license-url]: LICENSE | ||
[downloads-image]: https://img.shields.io/npm/dm/is-async-function.svg | ||
[downloads-url]: https://npm-stat.com/charts.html?package=is-async-function | ||
[codecov-image]: https://codecov.io/gh/inspect-js/is-async-function/branch/main/graphs/badge.svg | ||
[codecov-url]: https://app.codecov.io/gh/inspect-js/is-async-function/ | ||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-async-function | ||
[actions-url]: https://github.com/inspect-js/is-async-function/actions |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
1
9
124
0
0
19519
11
42
3
+ Addedhas-tostringtag@^1.0.0
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
- Removedarr-includes@^2.2.0
- Removedarrify@^2.0.1
- Removedcommon-callback-names@^2.0.1
- Removedfunction-arguments@^1.0.8
- Removedarr-includes@2.3.8(transitive)
- Removedarrify@2.0.1(transitive)
- Removedcommon-callback-names@2.0.1(transitive)
- Removedfunction-arguments@1.0.9(transitive)