{"_id":"switchback","_rev":"207154","name":"switchback","description":"Normalize callback fns to switchbacks and vice versa","dist-tags":{"latest":"2.0.5"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"time":{"modified":"2021-06-03T13:39:24.000Z","created":"2011-12-28T23:33:54.841Z","2.0.5":"2019-04-15T23:08:47.832Z","2.0.4":"2019-04-15T22:57:53.005Z","2.0.2":"2016-10-07T07:59:39.273Z","2.0.1":"2016-05-03T14:17:47.547Z","2.0.0":"2015-07-13T19:34:12.230Z","1.1.3":"2015-02-25T02:02:56.071Z","1.1.2":"2015-02-08T00:45:24.328Z","1.1.1":"2015-01-19T19:41:19.219Z","1.1.0":"2014-12-30T17:04:00.450Z","1.0.1":"2014-11-23T04:14:43.029Z","1.0.0":"2014-11-13T02:27:31.380Z","0.2.0":"2012-01-16T08:33:24.104Z","0.0.1":"2011-12-28T23:33:54.841Z"},"users":{"itonyyo":true,"sails":true},"author":{"name":"Mike McNeil"},"repository":{"type":"git","url":"git://github.com/node-machine/switchback.git"},"versions":{"2.0.5":{"name":"switchback","version":"2.0.5","description":"Normalize callback fns to switchbacks and vice versa","main":"lib/index.js","directories":{"test":"test"},"repository":{"type":"git","url":"git://github.com/node-machine/switchback.git"},"scripts":{"test":"mocha"},"keywords":["switchback","handlers","success","error","switcher","async.if","sails"],"author":{"name":"Mike McNeil"},"license":"MIT","dependencies":{"@sailshq/lodash":"^3.10.3"},"devDependencies":{"mocha":"6.1.3","should":"2.1.1"},"gitHead":"3fcec8c380b5a6ab25935450c47c1f5e4c10f4f9","bugs":{"url":"https://github.com/node-machine/switchback/issues"},"homepage":"https://github.com/node-machine/switchback#readme","_id":"switchback@2.0.5","_nodeVersion":"8.9.4","_npmVersion":"6.9.0","dist":{"shasum":"2f50c91118f659c42e03c0f2bdb094f868c45336","size":12233,"noattachment":false,"key":"/switchback/-/switchback-2.0.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-2.0.5.tgz"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"_npmUser":{"name":"rachaelshaw","email":"rachaelshaw@treeline.io"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/switchback_2.0.5_1555369727692_0.9510414647241541"},"_hasShrinkwrap":false,"publish_time":1555369727832,"_cnpm_publish_time":1555369727832},"2.0.4":{"name":"switchback","version":"2.0.4","description":"Normalize callback fns to switchbacks and vice versa","main":"lib/index.js","directories":{"test":"test"},"repository":{"type":"git","url":"git://github.com/node-machine/switchback.git"},"scripts":{"test":"mocha"},"keywords":["switchback","handlers","success","error","switcher","async.if","sails"],"author":{"name":"Mike McNeil"},"license":"MIT","dependencies":{"@sailshq/lodash":"^3.10.3"},"devDependencies":{"mocha":"6.1.3","should":"2.1.1"},"gitHead":"05c57a73a62cc1d9f0dd37bfc076f81885077cf7","bugs":{"url":"https://github.com/node-machine/switchback/issues"},"homepage":"https://github.com/node-machine/switchback#readme","_id":"switchback@2.0.4","_nodeVersion":"8.9.4","_npmVersion":"6.9.0","dist":{"shasum":"80baa10e6386f9c6a88fd88a0037fe46e1f098f2","size":12240,"noattachment":false,"key":"/switchback/-/switchback-2.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-2.0.4.tgz"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"_npmUser":{"name":"rachaelshaw","email":"rachaelshaw@treeline.io"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/switchback_2.0.4_1555369072810_0.8512200224789281"},"_hasShrinkwrap":false,"publish_time":1555369073005,"_cnpm_publish_time":1555369073005},"2.0.2":{"name":"switchback","version":"2.0.2","description":"Normalize callback fns to switchbacks and vice versa","main":"lib/index.js","directories":{"test":"test"},"repository":{"type":"git","url":"git://github.com/node-machine/switchback.git"},"scripts":{"test":"mocha"},"keywords":["switchback","handlers","success","error","switcher","async.if","sails"],"author":{"name":"Mike McNeil"},"license":"MIT","dependencies":{"lodash":"3.10.1"},"devDependencies":{"mocha":"3.0.2","should":"2.1.1"},"gitHead":"c7c4bbbf43638c466e2c7aaf8143a665ace6d435","bugs":{"url":"https://github.com/node-machine/switchback/issues"},"homepage":"https://github.com/node-machine/switchback#readme","_id":"switchback@2.0.2","_shasum":"96cf0e0d363b559d0bb7ff21b62a7aa910ec6079","_from":".","_npmVersion":"2.14.12","_nodeVersion":"4.3.0","_npmUser":{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},"dist":{"shasum":"96cf0e0d363b559d0bb7ff21b62a7aa910ec6079","size":12424,"noattachment":false,"key":"/switchback/-/switchback-2.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-2.0.2.tgz"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/switchback-2.0.2.tgz_1475827176604_0.28636814723722637"},"publish_time":1475827179273,"_cnpm_publish_time":1475827179273,"_hasShrinkwrap":false},"2.0.1":{"name":"switchback","version":"2.0.1","description":"Normalize callback fns to switchbacks and vice versa","main":"lib/index.js","directories":{"test":"test"},"repository":{"type":"git","url":"git://github.com/node-machine/switchback.git"},"scripts":{"test":"mocha"},"keywords":["switchback","handlers","success","error","switcher","async.if","sails"],"author":{"name":"Mike McNeil"},"license":"MIT","dependencies":{"lodash":"3.10.1"},"devDependencies":{"should":"~2.1.1","mocha":"~1.18.2"},"gitHead":"8b0da6d9464cc48a973d242cfb97494a6bda547f","bugs":{"url":"https://github.com/node-machine/switchback/issues"},"homepage":"https://github.com/node-machine/switchback#readme","_id":"switchback@2.0.1","_shasum":"df30805220cec06d50ad4013aede42d50397a8e6","_from":".","_npmVersion":"2.14.12","_nodeVersion":"4.3.2","_npmUser":{"name":"sgress454","email":"sgress454@treeline.io"},"dist":{"shasum":"df30805220cec06d50ad4013aede42d50397a8e6","size":10274,"noattachment":false,"key":"/switchback/-/switchback-2.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-2.0.1.tgz"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/switchback-2.0.1.tgz_1462285065097_0.8245878668967634"},"publish_time":1462285067547,"_cnpm_publish_time":1462285067547,"_hasShrinkwrap":false},"2.0.0":{"name":"switchback","version":"2.0.0","description":"Normalize callback fns to switchbacks and vice versa","main":"lib/index.js","directories":{"test":"test"},"repository":{"type":"git","url":"git://github.com/node-machine/switchback.git"},"scripts":{"test":"mocha"},"keywords":["switchback","handlers","success","error","switcher","async.if","sails"],"author":{"name":"Mike McNeil"},"license":"MIT","dependencies":{"lodash":"~2.4.1"},"devDependencies":{"should":"~2.1.1","mocha":"~1.18.2"},"gitHead":"05af4a33b53fc181124a3190f0c8f7d7f79a876f","bugs":{"url":"https://github.com/node-machine/switchback/issues"},"homepage":"https://github.com/node-machine/switchback#readme","_id":"switchback@2.0.0","_shasum":"2a27d90333def305a7521dcc1e32f6a8e3ad7205","_from":".","_npmVersion":"2.8.4","_nodeVersion":"0.10.26","_npmUser":{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},"dist":{"shasum":"2a27d90333def305a7521dcc1e32f6a8e3ad7205","size":10196,"noattachment":false,"key":"/switchback/-/switchback-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-2.0.0.tgz"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"publish_time":1436816052230,"_cnpm_publish_time":1436816052230,"_hasShrinkwrap":false},"1.1.3":{"name":"switchback","version":"1.1.3","description":"Normalize callback fns to switchbacks and vice versa","main":"lib/index.js","directories":{"test":"test"},"repository":{"type":"git","url":"git://github.com/node-machine/switchback.git"},"scripts":{"test":"mocha"},"keywords":["switchback","handlers","success","error","switcher","async.if","sails"],"author":{"name":"Mike McNeil"},"license":"MIT","dependencies":{"lodash":"~2.4.1"},"devDependencies":{"should":"~2.1.1","mocha":"~1.18.2"},"bugs":{"url":"https://github.com/node-machine/switchback/issues"},"homepage":"https://github.com/node-machine/switchback","_id":"switchback@1.1.3","dist":{"shasum":"12c70109348d6a296f739ba910eeb853f8b6e631","size":9899,"noattachment":false,"key":"/switchback/-/switchback-1.1.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-1.1.3.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"publish_time":1424829776071,"_cnpm_publish_time":1424829776071,"_hasShrinkwrap":false},"1.1.2":{"name":"switchback","version":"1.1.2","description":"Normalize callback fns to switchbacks and vice versa","main":"lib/index.js","directories":{"test":"test"},"repository":{"type":"git","url":"git://github.com/node-machine/switchback.git"},"scripts":{"test":"mocha"},"keywords":["switchback","handlers","success","error","switcher","async.if","sails"],"author":{"name":"Mike McNeil"},"license":"MIT","dependencies":{"lodash":"~2.4.1"},"devDependencies":{"should":"~2.1.1","mocha":"~1.18.2"},"bugs":{"url":"https://github.com/node-machine/switchback/issues"},"homepage":"https://github.com/node-machine/switchback","_id":"switchback@1.1.2","dist":{"shasum":"187b86153fc8e2ea5c0a87130b13acc16f9a1f7b","size":9567,"noattachment":false,"key":"/switchback/-/switchback-1.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-1.1.2.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"publish_time":1423356324328,"_cnpm_publish_time":1423356324328,"_hasShrinkwrap":false},"1.1.1":{"name":"switchback","version":"1.1.1","description":"Normalize callback fns to switchbacks and vice versa","main":"lib/index.js","directories":{"test":"test"},"repository":{"type":"git","url":"git://github.com/node-machine/switchback.git"},"scripts":{"test":"mocha"},"keywords":["switchback","handlers","success","error","switcher","async.if","sails"],"author":{"name":"Mike McNeil"},"license":"MIT","dependencies":{"lodash":"~2.4.1"},"devDependencies":{"should":"~2.1.1","mocha":"~1.18.2"},"bugs":{"url":"https://github.com/node-machine/switchback/issues"},"homepage":"https://github.com/node-machine/switchback","_id":"switchback@1.1.1","dist":{"shasum":"3c41b4e3cbfe892f0d3796f7cd9ef1cb3ad20ccb","size":9465,"noattachment":false,"key":"/switchback/-/switchback-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-1.1.1.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"balderdashy","email":"mike@balderdash.co"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"publish_time":1421696479219,"_cnpm_publish_time":1421696479219,"_hasShrinkwrap":false},"1.1.0":{"name":"switchback","version":"1.1.0","description":"Normalize callback fns to switchbacks and vice versa","main":"lib/index.js","directories":{"test":"test"},"repository":{"type":"git","url":"git://github.com/node-machine/switchback.git"},"scripts":{"test":"mocha"},"keywords":["switchback","handlers","success","error","switcher","async.if","sails"],"author":{"name":"Mike McNeil"},"license":"MIT","dependencies":{"lodash":"~2.4.1"},"devDependencies":{"should":"~2.1.1","mocha":"~1.18.2"},"bugs":{"url":"https://github.com/node-machine/switchback/issues"},"homepage":"https://github.com/node-machine/switchback","_id":"switchback@1.1.0","dist":{"shasum":"2981c79fc7704d2d4f019de550f909d75a840913","size":8884,"noattachment":false,"key":"/switchback/-/switchback-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-1.1.0.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"balderdashy","email":"mike@balderdash.co"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"publish_time":1419959040450,"_cnpm_publish_time":1419959040450,"_hasShrinkwrap":false},"1.0.1":{"name":"switchback","version":"1.0.1","description":"Normalize callback fns to switchbacks and vice versa","main":"lib/index.js","directories":{"test":"test"},"repository":{"type":"git","url":"git://github.com/node-machine/switchback.git"},"scripts":{"test":"mocha"},"keywords":["switchback","handlers","success","error","switcher","async.if","sails"],"author":{"name":"Mike McNeil"},"license":"MIT","dependencies":{"lodash":"~2.4.1"},"devDependencies":{"should":"~2.1.1","mocha":"~1.18.2"},"bugs":{"url":"https://github.com/node-machine/switchback/issues"},"homepage":"https://github.com/node-machine/switchback","_id":"switchback@1.0.1","dist":{"shasum":"7441ed2130252e6b83ea81068d7fbde8fe1cca7d","size":8453,"noattachment":false,"key":"/switchback/-/switchback-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-1.0.1.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"balderdashy","email":"mike@balderdash.co"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"publish_time":1416716083029,"_cnpm_publish_time":1416716083029,"_hasShrinkwrap":false},"1.0.0":{"name":"switchback","version":"1.0.0","description":"Normalize callback fns to switchbacks and vice versa","main":"lib/index.js","directories":{"test":"test"},"repository":{"type":"git","url":"git://github.com/mikermcneil/switchback.git"},"scripts":{"test":"mocha"},"keywords":["switchback","handlers","success","error","switcher","async.if","sails"],"author":{"name":"Mike McNeil"},"license":"MIT","dependencies":{"lodash":"~2.4.1"},"devDependencies":{"should":"~2.1.1","mocha":"~1.18.2"},"bugs":{"url":"https://github.com/mikermcneil/switchback/issues"},"homepage":"https://github.com/mikermcneil/switchback","_id":"switchback@1.0.0","dist":{"shasum":"55a1d798fe483eeda6f478c4f056da897b4677d3","size":8452,"noattachment":false,"key":"/switchback/-/switchback-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-1.0.0.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"balderdashy","email":"mike@balderdash.co"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"publish_time":1415845651380,"_cnpm_publish_time":1415845651380,"_hasShrinkwrap":false},"0.2.0":{"author":{"name":"Matt Insler","email":"matt.insler@gmail.com","url":"http://www.mattinsler.com"},"name":"switchback","description":"Command-line library for apps like heroku and jitsu","version":"0.2.0","repository":{"type":"git","url":"git://github.com/mattinsler/switchback.git"},"engines":{"node":">= 0.4.0"},"main":"lib/switchback","dependencies":{},"devDependencies":{},"_npmUser":{"name":"mattinsler","email":"matt.insler@gmail.com"},"_id":"switchback@0.2.0","_engineSupported":true,"_npmVersion":"1.1.0-beta-4","_nodeVersion":"v0.6.6","_defaultsLoaded":true,"dist":{"shasum":"4eac97f7044fab06925c8a90f61df714516fe56b","size":2526,"noattachment":false,"key":"/switchback/-/switchback-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-0.2.0.tgz"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"directories":{},"publish_time":1326702804104,"_cnpm_publish_time":1326702804104,"_hasShrinkwrap":false},"0.0.1":{"author":{"name":"Matt Insler","email":"matt.insler@gmail.com","url":"http://www.mattinsler.com"},"name":"switchback","description":"Command-line library for apps like heroku and jitsu","version":"0.0.1","repository":{"type":"git","url":"git://github.com/mattinsler/switchback.git"},"engines":{"node":">= 0.4.0"},"main":"lib/switchback","dependencies":{},"devDependencies":{},"_npmUser":{"name":"mattinsler","email":"matt.insler@gmail.com"},"_id":"switchback@0.0.1","_engineSupported":true,"_npmVersion":"1.1.0-beta-4","_nodeVersion":"v0.6.6","_defaultsLoaded":true,"dist":{"shasum":"808d8fdd322654d7bd6bc9ace2196705aa8ef604","size":2465,"noattachment":false,"key":"/switchback/-/switchback-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/switchback/download/switchback-0.0.1.tgz"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mattinsler","email":"matt.insler@gmail.com"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"}],"directories":{},"publish_time":1325115234841,"_cnpm_publish_time":1325115234841,"_hasShrinkwrap":false}},"readme":"# [<img title=\"switchback - Delinearizes flow control into a more realistic directed graph\" src=\"http://i.imgur.com/Jgrc9k2.png\" width=\"75px\" alt=\"image of a mountain switchback\"/>](https://github.com/node-machine/switchback) Switchback\n\n[![Bower version](https://badge.fury.io/bo/switchback.png)](http://badge.fury.io/bo/switchback)\n[![NPM version](https://badge.fury.io/js/switchback.png)](http://badge.fury.io/js/switchback) &nbsp; &nbsp;\n[![Build Status](https://travis-ci.org/node-machine/switchback.svg?branch=master)](https://travis-ci.org/node-machine/switchback)\n\nNormalize a callback to a \"switchback\" and vice versa.\n\n+ Allows your functions to **\"[b](http://en.wikipedia.org/wiki/Branch_table)[r](http://en.wikipedia.org/wiki/Monad_(functional_programming))[a](http://www.afralisp.net/autolisp/tutorials/cond-vs-if.php)[n](http://en.wikipedia.org/wiki/Dispatch_table)[ch](http://en.wikipedia.org/wiki/Virtual_method_table)\"**.\n+ Makes usage of branching functions **suck less**.\n+ Maintains **100% compatibility** with [node callbacks](http://nodeguide.com/style.html#callbacks).\n+ Helps keep users of your async functions from \"forgetting to return early\" **andthentimespaceparadox**\n+ Works w/ Node.js and in the browser.\n+ [Table the label, wear your own name.](http://news.moviefone.com/2010/05/26/cheesy-mr-t-clip-advises-you-to-table-the-label/)\n\n\n========================================\n\n## Contents\n\n|     | Jump to...        |\n|-----|-------------------------|\n| I   | [Usage for Users](#using-a-function-with-a-switchback)\n| II  | [Usage for Implementors](#implementing-a-function-with-a-switchback)\n| III | [Usage w/ Other Flow Control Libraries](#using-switchbacks-with-other-flow-control-libraries)\n| IV  | [Details](#details)\n| V   | [License](#license)\n\n\n\n========================================\n\n## Usage\n\n### Using a function with a switchback\n```javascript\n\n// So you heard about this new function called `mowLawn`\n// which accepts a switchback.  We know it has a `success`\n// handler, and a catch-all `error` handler, but turns out\n// it also has two others: `gasolineExplosion` and `sliceOffFinger`.\n\n// Let's try it!\n\n// Pass in a switchback:\nmowLawn('quickly', 'zigzags', {\n  // We can omit the `error` handler because the documentation for `mowLawn` says that it's optional.\n  // This varies function-to-function.\n  // (i.e. its only purpose is to act as a catch-all if the two explicit handlers are not specified)\n\n  gasolineExplosion: function () {\n    // Safety goggles next time.\n  },\n  sliceOffFinger: function (numFingersLost) {\n    // Oh my.\n  },\n  success: function (dollarsEarned) {\n    // Lawn was mowed, everything worked.\n  }\n});\n\n// Or we can pass in a callback function instead:\nmowLawn('quickly', 'zigzags', function (err, dollarsEarned) {\n  if (err) {\n    // Handle the error, count fingers to figure out what happened, etc.\n    // Also don't forget to return early or use `else` or something.\n    return;\n  }\n\n  // Lawn was mowed, everything worked.\n});\n\n// Both are cool.\n\n\n// Finally, it's worth noting that the return value is an EventEmitter:\nmowLawn('quickly', 'zigzags')\n.on('gasolineExplosion', function (err) {\n  // Safety goggles next time.\n})\n.on('sliceOffFinger', function (numFingersLost) {\n  // Oh my.\n})\n.on('success', function (dollarsEarned) {\n  // Lawn was mowed, everything worked.\n})\n```\n\n\n\n### Implementing a function with a switchback\n\n\nAdding an optional switchback interface to a function is pretty simple.  Just install:\n\n```sh\n$ npm install switchback --save\n```\n\nRequire:\n\n```js\nvar switchback = require('switchback');\n```\n\nAnd then call `switchback()` on the callback at the top of your function, overriding the original value:\n\n```javascript\ncb = switchback(cb);\n```\n\nTo enable complete, chainable usage, you should also return the switchback from your function:\n\n```javascript\nreturn cb;\n```\n\nFor example:\n\n```javascript\nvar switchback = require('switchback');\n\nfunction myFunction (stuff, cb) {\n  cb = switchback(cb);\n  // that's it!\n\n  // All the standard callback things work the same\n  if (err) return cb(err);\n\n  // But now you can call custom handlers too:\n  if (cb.someHandler) {\n\n  }\n\n  // Mix it up!\n  // Table the label!\n  // Wear your own name!\n  cb(null, 'whatever', 'you', 'want');\n\n  // Make it chainable\n  return cb;\n}\n\n```\n\n\n========================================\n\n\n## Details\n\nSwitchback is a JavaScript flow control library.  It works alongside async, promises, generators, and conventional Node callbacks to provide support for error negotiation via casefunctions.  It also makes your callbacks EventEmitters.  You might be familiar with a similar concept from `jQuery.ajax` (i.e. `$.ajax({ success: foo, error: bar });`).  It may be helpful to think about this module as the equivalent of something like `async.if()` or `async.switch()`.\n\n\n##### More examples of exactly what to expect\n\n```javascript\nfunction freeHouseholdPets (cb) {\n\n  // At the very top, upgrade the callback to a switchback.\n  // You can also do `var sb = switchback(cb)` to make the distinction explicit.\n  cb = switchback(cb);\n\n  // Do your stuff\n  // ...\n\n\n  // If cb was a switchback:\n  /////////////////////////////////////////////////\n\n  // Things that trigger the `success` handler:\n  return cb();\n  return cb(null);\n  return cb.success('the results!!!!');\n  return cb.success();\n\n\n  // Things that trigger the `error` handler:\n  return cb('bahh!');\n  return cb.error('bahh!');\n  return cb.error();\n\n\n  // If cb was a callback function:\n  /////////////////////////////////////////////////\n\n  // OK but what about usage with normal node callbacks?\n  //\n  // If a user of `freeHouseholdPets()` passes in an old-school callback,\n  // e.g. function (err, results) {console.log(err,results);}, here's what\n  // will get printed to the console in each case:\n\n  cb() // ---> null undefined\n  cb(null, 'the results!!!!') // ---> null the results!!!!\n  cb.success() // ---> null undefined\n  cb.success('the results!!!!'); // ---> null the results!!!!\n\n  cb('bahh!') // ---> bahh! undefined\n  cb('bahh!', 'foo') // ---> bahh! foo\n  cb.error() // ---> [Error] undefined\n  cb.error('bahh!') // ---> bahh! undefined\n}\n\n\n// Now everybody can use a good ole-fashioned callback function:\nfreeHouseholdPets(function (err, results) {\n  if (err) {\n    // Something came up, the pets were not freed.\n    //\n    // Handle the error, but don't forget to return early\n    // or use `else` or something..\n    return;\n  }\n\n  // Pets were freed, we can go about our business\n});\n\n// or a switchback:\nfreeHouseholdPets({\n  error: function (err) {\n    // Something came up, the pets were not freed.\n    // Handle the error.\n  },\n  success: function (results) {\n    // Pets were freed, we can go about our business\n  }\n});\n\n```\n\n========================================\n\n\n## Using switchbacks with other flow control libraries\n\nFor the examples below, imagine `juiceFruit(fruitName, sb)` is a switchback-enabled function (i.e. you can pass in exits or a callback for the `sb` argument).\n\n##### with `async`\n\n```javascript\nvar fruits = ['apples', 'oranges', 'miracle fruit'];\nasync.each(stuff, function (fruit, next){\n\n  // do stuff w/ fruit here...  (juice it, eat it, whatever you want)\n  juiceFruit(fruit, next);\n\n}, function afterwards(err){\n  if (err)  {\n    console.error('Oh no I made a mess:',err);\n    return;\n  }\n\n  console.log('mm mmm fruit');\n});\n```\n\n##### with `q` promises\n```javascript\n// TODO\n```\n\n##### with generators\n```javascript\n// TODO\n```\n\n\n========================================\n\n## License\n\n**[MIT](./LICENSE)**\n&copy; 2014\n[Mike McNeil](http://michaelmcneil.com), [Balderdash](http://balderdash.co) & contributors\n\nThis module is free and open-source under the [MIT License](http://sails.mit-license.org/).\n\n\n![image_squidhome@2x.png](http://i.imgur.com/RIvu9.png)\n\n\n[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/a22d3919de208c90c898986619efaa85 \"githalytics.com\")](http://githalytics.com/node-machine/switchback)\n","_attachments":{},"homepage":"https://github.com/node-machine/switchback#readme","bugs":{"url":"https://github.com/node-machine/switchback/issues"},"license":"MIT"}