Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dezonkey

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dezonkey

Make JavaScript callback functions call back rather than throwing.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

dezonkey

Build Status js-standard-style

dezonkey forbids callback style functions from throwing. It'll catch the exception and pass it to the callback instead.

Getting started

npm install dezonkey


var dezonkey = require('dezonkey');

or

<script src="node_modules/dezonkey/index.js"></script>
var dezonkey = window.dezonkey

Usage

// here is a an example of a zonkey function
function delay (time, cb) {
  if (typeof time !== 'number') {
    throw new Error(time + ' is not a number')
  }
  setTimeout(cb, time)
}

// what if the first argument is user input and we forgot a check? process will crash
delay('123', cb) // throws
// what if a user/program repeatedly sends that value?
// process will repeatedly crash

// we could do that
function onError(err) {
  ...
}
try {
  delay('123', function (err) {
    if (err) onError(err)
  })
} catch (err) {
  onError(err)
}

// but here is a nicer solution
var safeDelay = dezonkey(delay)
safeDelay('123', cb) // will not throw, passes the exception to the callback

// dezonkey is also pretty useful if you're writing your own functions
function myFunction (time, cb) {
  return dezonkey(function () {
    if (typeof time !== 'number') {
      // instead of `return cb(new Error(...))`
      // who never forgot that return keyword?
      throw new Error(time + ' is not a number')
    }
    setTimeout(cb, time)
  })
}

Example

See example.js

Benchmark

See benchmark

Test

npm install standard
npm test

Keywords

FAQs

Package last updated on 20 Apr 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc