Skip to content

Commit

Permalink
cleanup and update metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Mar 18, 2016
1 parent bc7d85e commit e09ab8b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [is-async-function][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url]

> Is function really asynchronous (callback) function? Trying to guess that based on check if `callback`, `cb`, `done`, `next` exists as function arguments names or you can pass your custom.
> 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.
[![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url]

Expand All @@ -16,14 +16,13 @@ npm i is-async-function --save
const isAsyncFunction = require('is-async-function')
```

### [isAsyncFunction](index.js#L38)
### [isAsyncFunction](index.js#L37)
> Trying to guess is function asynchronous (callback) function or not.
**Params**

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

**Example**
Expand All @@ -45,10 +44,13 @@ console.log(isAsyncFunction(fs.readFile, ['callback', 'next']))
```

## Related
* [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)
* [fn-args](https://www.npmjs.com/package/fn-args): Get the arguments of a function | [homepage](https://github.com/sindresorhus/fn-args)
* [fn-name](https://www.npmjs.com/package/fn-name): Get the name of a named function | [homepage](https://github.com/sindresorhus/fn-name)
* [function-arguments](https://www.npmjs.com/package/function-arguments): Get arguments of a function, useful for and used in dependency injectors.… [more](https://www.npmjs.com/package/function-arguments) | [homepage](https://github.com/tunnckocore/function-arguments)
* [get-fn-name](https://www.npmjs.com/package/get-fn-name): Get function name with strictness and correctness in mind. Also works for… [more](https://www.npmjs.com/package/get-fn-name) | [homepage](https://github.com/tunnckocore/get-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… [more](https://www.npmjs.com/package/is-callback-function) | [homepage](https://github.com/tunnckocore/is-callback-function)
* [parse-function](https://www.npmjs.com/package/parse-function): Parse a function, arrow function or string to object with name, args,… [more](https://www.npmjs.com/package/parse-function) | [homepage](https://github.com/tunnckocore/parse-function)

## 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).
Expand All @@ -58,9 +60,8 @@ But before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md)

[![tunnckoCore.tk][author-www-img]][author-www-url] [![keybase tunnckoCore][keybase-img]][keybase-url] [![tunnckoCore npm][author-npm-img]][author-npm-url] [![tunnckoCore twitter][author-twitter-img]][author-twitter-url] [![tunnckoCore github][author-github-img]][author-github-url]

[arr-includes]: https://github.com/tunnckocore/arr-includes
[function-arguments]: https://github.com/tunnckocore/function-arguments
[isarray]: https://github.com/juliangruber/isarray
[common-callback-names]: https://github.com/tunnckocore/common-callback-names

[npmjs-url]: https://www.npmjs.com/package/is-async-function
[npmjs-img]: https://img.shields.io/npm/v/is-async-function.svg?label=is-async-function
Expand Down
11 changes: 5 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@
* ```
*
* @param {Function} `fn` Is this `fn` a callback function.
* @param {Array} `ignores` Arguments names, default are `['callback', 'callback_', 'done', 'next', 'cb']`.
* @param {Number} `max` How many characters to cut from `fn`s toString, default `250`. Passed to [function-arguments][].
* @param {Array} `names` Arguments names, default are [common-callback-names][].
* @return {Boolean}
* @api public
*/

module.exports = function isAsyncFunction (fn, ignores, max) {
module.exports = function isAsyncFunction (fn, names) {
if (typeof fn !== 'function') {
throw new TypeError('is-async-function expect a function')
}

var defaults = ['callback', 'callback_', 'done', 'next', 'cb']
var args = require('function-arguments')(fn, max || 250)
var args = require('function-arguments')(fn)

ignores = require('isarray')(ignores) ? ignores : defaults
return require('arr-includes')(args, ignores)
names = require('isarray')(names) ? names : defaults
return require('arr-includes')(args, names)
}

29 changes: 25 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "is-async-function",
"version": "1.1.1",
"description": "Is function really asynchronous (callback) function? Trying to guess that based on check if `callback`, `cb`, `done`, `next` exists as function arguments names or you can pass your custom.",
"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> (http://www.tunnckocore.tk)",
"precommit.silent": true,
Expand All @@ -27,7 +27,24 @@
"index.js"
],
"keywords": [
"is-async-function"
"assume",
"async",
"callback",
"cb",
"check",
"common",
"done",
"exist",
"fn",
"func",
"function",
"is",
"is-async-function",
"names",
"next",
"really",
"util",
"validate"
],
"verb": {
"run": true,
Expand All @@ -41,11 +58,15 @@
"function-arguments",
"fn-args",
"get-fn-name",
"fn-name"
"fn-name",
"parse-function",
"is-callback-function",
"common-callback-names"
]
},
"reflinks": [
"function-arguments"
"function-arguments",
"common-callback-names"
],
"lint": {
"reflinks": true
Expand Down

0 comments on commit e09ab8b

Please sign in to comment.