Socket
Socket
Sign inDemoInstall

tiny-promisify

Package Overview
Dependencies
3
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tiny-promisify

Tiny library to promisify functions expecting node-style callbacks


Version published
Weekly downloads
73
decreased by-6.41%
Maintainers
1
Install size
2.24 MB
Created
Weekly downloads
 

Readme

Source

Tiny Node Promisify

Minimalist library to promisify functions expecting node-style callbacks.

Install

npm install tiny-promisify

Usage

Given a fn that uses the node-style callbacks, expecting a callback as the last parameter and this callback expecting an err as the first parameter, you can obtain a new function that return promises as follows:

var promisify = require('tiny-promisify');

function fn (args, callback) {
  // fn code here...
  callback(err, results);
}

var fnAsync = promisify(fn);
fnAsync(args).then(function (result) {
  // your code here...
}).catch(function (err) {
  // handle error here...
});

API

promisify(fn, [options])

  • fn is a function that receives a callback as the last. argument. The callback will receive an err object as the first argument.
  • options is an optional object having the following properties:
    • multiArgs set to true will make the promise resolve to an array containing all the parameters passed to the callback. Otherwise, only the first non-error parameter is passed to the promise success callback. Defaults to false.
    • context is the object uses as this when calling fn. Defaults to {}.

Returns a new function that wraps fn in a promise.

Notes

The module uses Babel's polyfills for Promise and Object.assign() when not found in the current execution environment.

You can require the ES2015 version of the lib by specifying the source file: require('tiny-promisify/lib').

License

WTFPL

Keywords

FAQs

Last updated on 18 Oct 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc