cbd

1.0.0 • Public • Published

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) })()
}

Readme

Keywords

none

Package Sidebar

Install

npm i cbd

Weekly Downloads

3

Version

1.0.0

License

MIT

Last publish

Collaborators

  • alanshaw