Package Exports
- handle-arguments
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (handle-arguments) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Handles given Arguments object - return separatly last argument (commonly callback) and other arguments as Array. Useful in node-style callback flow.
Install
npm install handle-arguments --save
npm test
API
For more use-cases see the tests
handleArguments
<argsObject>
{Arguments} the arguments objectreturn
{Object}callback
{Function} last argument if function orundefined
cb
{Function} alias ofcallback
arguments
{Array} all arguments without last (the callback)args
{Array} alias ofarguments
Example:
var handleArguments = require('handle-arguments')
function fixture() {
return handleArguments(arguments)
}
console.log(fixture(1, 2, 3))
//=> {callback: undefined, cb: undefined
// arguments: [1, 2, 3], args: [1, 2, 3]}
console.log(fixture(1, 2, function _callback_ () {}))
//=> {callback: [Function: _callback_], cb: [Function: _callback_],
// arguments: [1, 2], args: [1, 2]}
instead of commonly used pattern
function fixture() {
var args = [].slice.call(arguments)
var len = args.length
var callback = args[len - 1]
if (typeof callback === 'function') {
args = args.slice(0, -1)
callback.apply(undefined, [null].concat(args))
}
return args
}
Or more real world examples callback-and-promise, thenify, thenify-all and a lot more...
Author
Charlike Mike Reagent
License 
Copyright (c) 2015 Charlike Mike Reagent, contributors.
Released under the MIT
license.
Proudly generated by docks(1) on May 9, 2015.