is-async-function
Advanced tools
Comparing version 1.1.5 to 1.2.0
@@ -0,3 +1,17 @@ | ||
# Change Log | ||
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. | ||
<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) | ||
### Features | ||
* **strict:** introduce strict mode ([ef8526f](https://github.com/tunnckocore/is-async-function/commit/ef8526f)) | ||
## 1.1.5 - 2016-09-21 | ||
@@ -4,0 +18,0 @@ - Release v1.1.5 / npm@v1.1.5 |
27
index.js
@@ -30,13 +30,20 @@ /*! | ||
* console.log(isAsyncFunction(fs.stat, ['cb'])) // => false | ||
* console.log(isAsyncFunction(fs.readFile, ['callback', 'next'])) | ||
* // => false, because fs.readFile uses `callback_` | ||
* 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][]. | ||
* @return {Boolean} | ||
* @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) { | ||
module.exports = function isAsyncFunction (fn, names, strict) { | ||
if (typeof fn !== 'function') { | ||
@@ -46,5 +53,11 @@ 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 = utils.isArray(names) ? names : utils.arrayify(names) | ||
names = names.length ? names : utils.callbackNames | ||
return utils.arrIncludes(utils.fnArgs(fn), names) | ||
var idx = utils.arrIncludes(utils.fnArgs(fn), names) | ||
return strict ? Boolean(idx) : idx | ||
} |
{ | ||
"name": "is-async-function", | ||
"version": "1.1.5", | ||
"version": "1.2.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.", | ||
@@ -16,9 +16,13 @@ "repository": "tunnckoCore/is-async-function", | ||
"coverage": "nyc node test.js", | ||
"lint:coverage": "nyc check-coverage --statements 100 --functions 100 --lines 100", | ||
"report-coverage": "nyc report --reporter=text-lcov | coveralls" | ||
"lint:coverage": "nyc check-coverage --lines 100 --branches 100 --statements 100 --functions 100", | ||
"report-coverage": "nyc report --reporter=text-lcov | coveralls", | ||
"prerelease": "npm test", | ||
"release": "standard-version --sign --no-verify", | ||
"precommit": "git add --all", | ||
"commit": "git-cz" | ||
}, | ||
"dependencies": { | ||
"arr-includes": "^1.0.1", | ||
"arr-includes": "^2.0.0", | ||
"common-callback-names": "^1.0.2", | ||
"function-arguments": "^1.0.5", | ||
"function-arguments": "^1.0.6", | ||
"lazy-arrayify": "^1.0.3", | ||
@@ -28,11 +32,11 @@ "lazy-cache": "^2.0.1" | ||
"devDependencies": { | ||
"coveralls": "^2.11.14", | ||
"gh-got": "^1.1.0", | ||
"got": "^3.2.0", | ||
"commitizen": "^2.8.6", | ||
"coveralls": "^2.11.12", | ||
"cz-conventional-changelog": "^1.2.0", | ||
"is-match": "^0.4.1", | ||
"mukla": "^0.4.4", | ||
"nyc": "^8.3.0", | ||
"mukla": "^0.4.1", | ||
"nyc": "^8.1.0", | ||
"pre-commit": "^1.1.3", | ||
"request": "^2.57.0", | ||
"standard": "^8.1.0" | ||
"standard": "^8.4.0", | ||
"standard-version": "^2.4.0" | ||
}, | ||
@@ -63,2 +67,7 @@ "files": [ | ||
], | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"verb": { | ||
@@ -65,0 +74,0 @@ "run": true, |
@@ -1,2 +0,2 @@ | ||
# [is-async-function][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] | ||
# [is-async-function][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] [![npm downloads][downloads-img]][downloads-url] | ||
@@ -8,4 +8,6 @@ > 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. | ||
## Install | ||
> Install with [npm](https://www.npmjs.com/) | ||
``` | ||
npm i is-async-function --save | ||
$ npm i is-async-function --save | ||
``` | ||
@@ -20,11 +22,7 @@ | ||
### [isAsyncFunction](index.js#L40) | ||
## API | ||
### [isAsyncFunction](index.js#L47) | ||
> 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][]. | ||
* `returns` **{Boolean}** | ||
**Example** | ||
@@ -44,6 +42,29 @@ | ||
console.log(isAsyncFunction(fs.stat, ['cb'])) // => false | ||
console.log(isAsyncFunction(fs.readFile, ['callback', 'next'])) | ||
// => false, because fs.readFile uses `callback_` | ||
console.log(isAsyncFunction(fs.readFile, ['foo', 'bar'])) | ||
// => false, because fs.readFile uses `cb` | ||
``` | ||
**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. | ||
**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 | ||
``` | ||
## Related | ||
@@ -74,4 +95,7 @@ - [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.") | ||
[license-url]: https://github.com/tunnckoCore/is-async-function/blob/master/LICENSE | ||
[license-img]: https://img.shields.io/badge/license-MIT-blue.svg | ||
[license-img]: https://img.shields.io/npm/l/is-async-function.svg | ||
[downloads-url]: https://www.npmjs.com/package/is-async-function | ||
[downloads-img]: https://img.shields.io/npm/dm/is-async-function.svg | ||
[codeclimate-url]: https://codeclimate.com/github/tunnckoCore/is-async-function | ||
@@ -78,0 +102,0 @@ [codeclimate-img]: https://img.shields.io/codeclimate/github/tunnckoCore/is-async-function.svg |
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
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
16023
71
133
+ Addedarr-includes@2.3.8(transitive)
+ Addedarrify@2.0.1(transitive)
- Removedarr-includes@1.0.2(transitive)
- Removedin-array@0.1.2(transitive)
Updatedarr-includes@^2.0.0
Updatedfunction-arguments@^1.0.6