🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

has-callback

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

has-callback

Check if function takes callback as argument

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
2
-90%
Maintainers
1
Weekly downloads
 
Created
Source

hasCallback

Check if function takes callback as argument.

Will check for common callback names in argument footprint:

  • callback
  • cb
  • done
  • next

API

hasCallback(fn, [userDefinedNames])

fn

Type: function

(Required)

The function to be tested.

userDefinedNames

Type: string | array

User-defined callback name string or list of strings.

Example Usage

import hasCallback from 'has-callback';

hasCallback(JSON.stringify);
// => false

hasCallback(fs.rename);
// => true

Limitations

This function merely checks the name of function arguments, it is not a reliable way of checking if a function is asynchronous, for example it will not detect if a function returns a Promise.

FAQs

Package last updated on 16 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts