optback.js
Extract options and a callback function from arguments
;/*=> { 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
.
Installation
Package managers
npm
npm install --save optback
bower
bower install --save optback
Standalone
Download the script file directly.
API
optback(args)
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.
{ var argv = ; argvoptions; //=> {some: 'options'} argvcallback; //=> [Function: cb]}'foo' some: 'options' {/* ... */};
License
Copyright (c) 2014 Shinnosuke Watanabe
Licensed under the MIT License.