promisify-api

1.1.1 • Public • Published

promisify-api

Changes interface of asynchronous functions to Promises. Functions should be designed using error-first callback pattern.

Installation

$ npm install promisify-api

Usage

promisify(fn, ctx, _)

Creates a wrapper function, which returns Promises.

const fs = require('fs');
const resolve = require('path').resolve;
const promisify = require('promisify-api');
 
// the second argument (which is context) is optional
const readFile = promisify(fs.readFile, fs);
 
readFile(resolve('index.js'), 'utf8')
  .then(console.log)
  .catch(console.error);

Arguments:

  • fn (function): The original function.
  • ctx (*): Predefines execution context of the original function.
  • ..._ (*): Possibility to provide additional arguments, that will be prepended to the function.

License

The MIT License

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.1
    3
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.1
    3
  • 1.1.0
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i promisify-api

Weekly Downloads

2

Version

1.1.1

License

MIT

Last publish

Collaborators

  • sullenor