1.0.1 • Published 10 years ago

shift-arguments v1.0.1

Weekly downloads
5
License
ISC
Repository
github
Last release
10 years ago

shift-arguments

Build Status

Shift javascript function arguments for better integration with different frameworks

npm install shift-arguments

Usage

Delete arguments

var shiftArguments = require('shift-arguments');

function testFunc (result) {

}

function doSthAsync (callback) {
  callback('error', 'result');
}

doSthAsync(shiftArguments(testFunc, -1));

Add empty arguments

var shiftArguments = require('shift-arguments');

function testFunc (error, result) {

}

function doSthAsync (callback) {
  callback('result');
}

doSthAsync(shiftArguments(testFunc, 1));

Examples

Promise to callback

var Promise = require('bluebird');
var shiftArguments = require('shift-arguments');

var fs = Promise.promisifyAll(require('fs'));

function getConfig(callback) {
  fs.readFileAsync('myfile.json')
    .then(JSON.parse)
    .then(shiftArguments(callback, 1))
    .catch(callback);
}

getConfig(function(error, config)) {
  //Handle error and result as expected
});
1.0.1

10 years ago

1.0.0

10 years ago