Notably Polite Mariner

npm

Need private packages and team management tools?Check out npm Orgs. »

reverse-execution

1.0.5 • Public • Published

reverse-execution

npm package

Inspiration

Sometimes we need to convert from a callback function to Promise and we need to change the parameter ordering of their's callback. Because Promise's callback use second parameter to handle error and Callback-style is backwards. So I decided to write this function to help us.

Example:

var p = new Promise((resolve, reject) => {
  something.asyncOperation((err, result) => {
    if (err) {
      return reject(err);
    }
    
    return resolve(result);
  })
})

Now it's easier:

var p = new Promise(callback => something.asyncOperation(inverse(callback)));

Installation

npm install reverse-execution

Example:

// Normal function
function concatWord () {
    console.log(this.foo);
    const words = Array.prototype.slice.call(arguments);
    return words.join('_');
}
    
concatWord('one', 'two', 'three'); // return 'one_two_three'
 
const concatWord_RE = inverse(concatWord)
concatWord_RE('one', 'two', 'three'); // return 'three_two_one';
 

Bugs?

This is my first public package on NPM. If you found any bugs please create a pull request. Many thanks :)

install

npm i reverse-execution

Downloadsweekly downloads

1

version

1.0.5

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability