JavaScript
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test Add tests May 26, 2017
.codeclimate.yml Add dotfiles May 26, 2017
.gitignore Add dotfiles May 26, 2017
.npmignore Add dotfiles May 26, 2017
.travis.yml Add dotfiles May 26, 2017
README.md Add badges to Readme May 26, 2017
index.js Add main script May 26, 2017
package.json 1.0.1 May 26, 2017

README.md

function-at

build status codecov Code Climate

Pass functions with adjusted arguments

Usage

require('function-at');

function thenable(name) {
  if (!name) return Promise.reject(
    new TypeError('name string required'));
  var greeting = 'Hello, ' + name + '!';
  return Promise.resolve(greeting);
}

// Normal callback
function callback(error, result) {
  console.log('calback ---------------');
  console.log('  error:', error);
  console.log('  result:', result);
}

thenable('Friday')
  // On fulfillment 
  // set error to null
  .then(callback.atfirst(null))

Output:

calback ---------------
  error: null
  result: Hello, Friday!

Catch example:

// Given the thenable() and callback()
// functions definitions...

thenable() 
  // On rejection 
  // set result to empty string
  .catch(callback.atlast(''));

Catch output:

calback ---------------
  error: [TypeError: name string required]
  result: