0.1.4 • Published 11 years ago

promisemonkey v0.1.4

Weekly downloads
7
License
BSD
Repository
github
Last release
11 years ago

promisemonkey

Easily convert objects, functions and METHODs to the Q promise API

Installation

You can install promisemonkey through npm:

$ npm install promisemonkey

Example

Access standard node APIs as promises

You can easily acccess the standard node APIs as promises:

var promisify = require('promisemonkey');
var fs = promisify('fs');
fs.stat(filePath)
  .then(function (stats) {
    expect(stats.size).to.be.above(0);
  });

Convert an object

You can pass through a object with methods and then an array of the method names to promisify:

var promisify = require('promisemonkey');

// Pass through an object and array of method names
var fs = promisify.convert(require('fs'), ['readFile', 'stat']);

// All the underlying functions should be accessible
var contents = fs.readFileSync(filePath).toString();
expect(contents.length).to.be.above(0);

// You can then use the object methods which are now promisified
fs.stat(filePath)
  .then(function (stats) {
    expect(stats.size).to.be.above(0);
    return fs.readFile(filePath);
  })
  .then(function (contents) {
    expect(contents.length).to.be.above(0);
  })

Convert a function

And, of course you can promisify a plain old function

var readFile = promisify.convert(require('fs').readFile);
readFile(filePath)
  .then(function (contents) {
    expect(contents.length).to.be.above(0);
  })
0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.1

11 years ago