Extract options and a callback function from arguments
optback(['foo', {bar: 'baz'}, function qux() {/* ... */}]);
/*
=> {
options: {bar: 'baz'},
callback: [Function: qux]
}
*/
This module is useful to create a function which takes an option object and a callback function as its arguments, like Node's fs.readFile
.
npm install --save optback
bower install --save optback
Download the script file directly.
args: Array
or array-like object (e.g. arguments
)
Return: Object
It returns an object in the form {options: [Object], callback: [Function]}
:
options
is the penultimate element of args, or{}
if that is not an object.callback
is the last element of args.
It throws an error when the last element is not a function.
(function() {
var argv = getCallback(arguments);
argv.options; //=> {some: 'options'}
argv.callback; //=> [Function: cb]
})('foo', {some: 'options'}, function cb() {/* ... */});
Copyright (c) 2014 Shinnosuke Watanabe
Licensed under the MIT License.