cbd

Callback default. Return a noop function for when no callback function has been passed.

npm install cbd
2 downloads in the last week
4 downloads in the last month

cbd Build Status devDependency Status

For functions with optional callbacks.

Callback default. Return a noop function for when no callback function has been passed.

Usage

Instead of

function foo (arg1, cb) {
  // Do work
  if (cb) {
    cb()
  }
}

You do

var cbd = require("cbd")

function foo (arg1, cb) {
  // Do work
  cbd(cb)()
}

Set default cb

var cbd = require("cbd")

cbd.setDefault(function (er, res) {
  if (er) return console.error(er)
  console.log(res)
})

Pass default cb

var cbd = require("cbd")

function foo (arg1, cb) {
  // Do work
  cbd(cb, function () { console.log("foo callback", arguments) })()
}
npm loves you