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.
npm i is-callback-function --save
For more use-cases see the tests
const isCallbackFunction = require('is-callback-function')
Check if given
fn
is callback function or not. Notice that "async" functions are notis-callback-function
, they are is-async-function - it may be consfusing, but they are different.
Params
fn
{Function}names
{Array}returns
{Boolean}
Example
var fs = require('fs')
var isCallback = require('is-callback-function')
var isAsync = require('is-async-function')
console.log(isCallback(fs.readFile)) // => false
console.log(isAsync(fs.readFile)) // => true
console.log(isCallback(function (foo, bar, cb) {})) // => false
console.log(isAsync(function (foo, bar, cb) {})) // => true
console.log(isCallback(function callback (foo, bar) {})) // => true
console.log(isAsync(function callback (foo, bar) {})) // => false
console.log(isCallback(function named (foo, cb) {})) // => false
console.log(isAsync(function named (foo, cb) {})) // => true
console.log(isCallback(function named (foo) {})) // => false
console.log(isAsync(function named (foo) {})) // => false
console.log(isCallback(function foo (bar) {}, ['baz', 'foo', 'qux'])) // => true
console.log(isAsync(function foo (bar, qux) {}, ['baz', 'qux', 'aaa'])) // => true
console.log(isAsync(function foo (bar, qux) {}, ['baz', 'aaa'])) // => false
Need clarification? Both signatures are equal.
is-callback-function
- checks the name of given functionis-async-function
- checks the arguments names of given function
- arr-includes: Return true if any of passed values exists in array. Using in-array. | homepage
- common-callback-names: List of common callback names - callback, cb, callback_, next, done. | homepage
- function-arguments: Get arguments of a function, useful for and used in dependency injectors.… more | homepage
- get-fn-name: Get function name with strictness and correctness in mind. Also works for… more | homepage
- in-array: Return true if a value exists in an array. Faster than using… more | homepage
- is-async-function: Is function really asynchronous function? Trying to guess that based on check… more | homepage
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.