Skip to content

Commit 90654c9

Browse files
author
tunnckoCore
committed
update docs
1 parent ce2e97b commit 90654c9

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

README.md

+22-5
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,34 @@ npm i is-async-function --save
1616
const isAsyncFunction = require('is-async-function')
1717
```
1818

19-
### [isAsyncFn](index.js#L20)
20-
19+
### [isAsyncFunction](index.js#L38)
2120
> Trying to guess is function asynchronous (callback) function or not.
2221
2322
**Params**
2423

25-
* `fn` **{Function}**
26-
* `ignores` **{Array}**
27-
* `max` **{Number}**
24+
* `fn` **{Function}**: Is this `fn` a callback function.
25+
* `ignores` **{Array}**: Arguments names, default are `['callback', 'callback_', 'done', 'next', 'cb']`.
26+
* `max` **{Number}**: How many characters to cut from `fn`s toString, default `250`. Passed to [function-arguments][].
2827
* `returns` **{Boolean}**
2928

29+
**Example**
30+
31+
```js
32+
var fs = require('fs')
33+
var isAsyncFn = require('is-async-function')
34+
35+
console.log(isAsyncFunction(fs.readFile)) // => true
36+
console.log(isAsyncFunction(fs.stat)) // => true
37+
38+
console.log(isAsyncFunction(fs.readFileSync)) // => false
39+
console.log(isAsyncFunction(fs.statSync)) // => false
40+
41+
// or pass custom names to recognize as `async`
42+
console.log(isAsyncFunction(fs.stat, ['cb'])) // => false
43+
console.log(isAsyncFunction(fs.readFile, ['callback', 'next']))
44+
// => false, because fs.readFile uses `callback_`
45+
```
46+
3047
## Contributing
3148
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).
3249
But before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines.

index.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,32 @@
1010
/**
1111
* > Trying to guess is function asynchronous (callback) function or not.
1212
*
13-
* @param {Function} `fn`
14-
* @param {Array} `ignores`
15-
* @param {Number} `max`
13+
* **Example**
14+
*
15+
* ```js
16+
* var fs = require('fs')
17+
* var isAsyncFn = require('is-async-function')
18+
*
19+
* console.log(isAsyncFunction(fs.readFile)) // => true
20+
* console.log(isAsyncFunction(fs.stat)) // => true
21+
*
22+
* console.log(isAsyncFunction(fs.readFileSync)) // => false
23+
* console.log(isAsyncFunction(fs.statSync)) // => false
24+
*
25+
* // or pass custom names to recognize as `async`
26+
* console.log(isAsyncFunction(fs.stat, ['cb'])) // => false
27+
* console.log(isAsyncFunction(fs.readFile, ['callback', 'next']))
28+
* // => false, because fs.readFile uses `callback_`
29+
* ```
30+
*
31+
* @param {Function} `fn` Is this `fn` a callback function.
32+
* @param {Array} `ignores` Arguments names, default are `['callback', 'callback_', 'done', 'next', 'cb']`.
33+
* @param {Number} `max` How many characters to cut from `fn`s toString, default `250`. Passed to [function-arguments][].
1634
* @return {Boolean}
1735
* @api public
1836
*/
1937

20-
module.exports = function isAsyncFn (fn, ignores, max) {
38+
module.exports = function isAsyncFunction (fn, ignores, max) {
2139
if (typeof fn !== 'function') {
2240
throw new TypeError('is-async-function expect a function')
2341
}

0 commit comments

Comments
 (0)