Socket
Book a DemoInstallSign in
Socket

func-it

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

func-it

Returns an empty function if one isn't present. Useful for optional callback parameters inside methods.

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

Func-It

Returns an empty function if one isn't present. Useful for optional callback parameters inside methods.

Usage

To ensure your callback parameter is actually a function and not another value or undefined follow this example. This allows you to make callbacks optional in your methods.

/*
 * Calculates a result and saves it in the database. The callback is optional.
 * callback(err, doc);
 */
function thisIsMyMethod (x, y, callback) {

  // Ensure callback is an empty fn if the parameter isn't provided.
  callback = require('func-it')(callback);

  // Do something...
  var result = x * y;
  return database.save(result, callback);  //no need to check typeof callback === 'function'.

}

Shorthand Empty Function

If you just need quick access to an empty function:

var funcIt  = require('func-it');
var emptyFn = funcIt.emptyFn;

function doSomething() {
  return emptyFn(result);
}

Keywords

function

FAQs

Package last updated on 30 May 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