Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-async-function

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-async-function - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

10

CHANGELOG.md

@@ -5,2 +5,12 @@ # Change Log

<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)
### Bug Fixes
* **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)
<a name="1.2.1"></a>

@@ -7,0 +17,0 @@ ## [1.2.1](https://github.com/tunnckocore/is-async-function/compare/v1.2.0...v1.2.1) (2016-10-27)

2

package.json
{
"name": "is-async-function",
"version": "1.2.1",
"version": "1.2.2",
"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.",

@@ -5,0 +5,0 @@ "repository": "tunnckoCore/is-async-function",

@@ -26,2 +26,9 @@ # [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]

**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**

@@ -45,9 +52,2 @@

**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**

@@ -69,2 +69,25 @@

**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

@@ -71,0 +94,0 @@ - [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.")

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc