Proxmis.js
Proxmis is a very simple library to generate promises that can be used directly as typical two argument, error first, node.js callbacks.
##Node.js
To install:
npm install proxmis
To use:
var proxmis = require('proxmis');
##Usage
var proxmis = require('proxmis');
var fs = require('fs');
var callback = proxmis();
fs.stat('/var', callback);
callback.then(function (stats) {
});
The first argument on proxmis()
can optionally be another callback to be invoked before the promise resolves, or an object containing extra options for how the promise will be resolved.
function fileStatWithCallbackOrPromise(cb) {
var prox = proxmis(cb);
fs.stat('/var', prox);
return prox;
}
var prox = proxmis({noError: true});
prox('first argument resolves', 'all other arguments ignored');
prox.then(function (result) {
});
var prox = proxmis({allArgs: true});
prox('each argument resolves', 'together as', 'an array');
prox.then(function (result) {
});
Proxmis also provides a routine for wrapping a traditional call in a closure, directly returning a promise.
proxmis.wrap(function (callback) {
fs.stat('/var', callback);
}).then(function (stats) {
});
Proxmis uses the ES6 Promise Polyfill to generate the promise it returns.