optback

0.0.0 • Public • Published

optback.js

Build Status Build status Coverage Status devDependency Status

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.

Installation

Package managers

npm NPM version

npm install --save optback

bower Bower version

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.

(function() {
  var argv = getCallback(arguments);
  argv.options; //=> {some: 'options'}
  argv.callback; //=> [Function: cb]
})('foo', {some: 'options'}, function cb() {/* ... */});

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT License.

Package Sidebar

Install

npm i optback

Weekly Downloads

0

Version

0.0.0

License

none

Last publish

Collaborators

  • shinnn