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 :)

/reverse-execution/

    Package Sidebar

    Install

    npm i reverse-execution

    Weekly Downloads

    2

    Version

    1.0.5

    License

    MIT

    Unpacked Size

    3.06 kB

    Total Files

    4

    Last publish

    Collaborators

    • thangtv611