{"_id":"breakable","_rev":"82898","name":"breakable","description":"Break out of functions, recursive or not, in a more composable way than by using exceptions explicitly. Non-local return.","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"olov","email":"olov.lassus@gmail.com"}],"time":{"modified":"2021-06-03T10:26:24.000Z","created":"2013-09-20T22:49:31.870Z","1.0.0":"2014-05-06T13:54:10.760Z","0.1.0":"2013-09-20T22:49:31.870Z"},"users":{"bojand":true,"rexpan":true},"author":{"name":"Olov Lassus","email":"olov.lassus@gmail.com"},"repository":{"type":"git","url":"https://github.com/olov/breakable.git"},"versions":{"1.0.0":{"name":"breakable","version":"1.0.0","description":"Break out of functions, recursive or not, in a more composable way than by using exceptions explicitly. Non-local return.","main":"breakable.js","repository":{"type":"git","url":"https://github.com/olov/breakable.git"},"keywords":["throw","try","catch","exception","non-local","return","break","breakable"],"scripts":{"test":"tap test/*.js"},"devDependencies":{"tap":"~0.4.4"},"author":{"name":"Olov Lassus","email":"olov.lassus@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/olov/breakable/issues"},"homepage":"https://github.com/olov/breakable","_id":"breakable@1.0.0","dist":{"shasum":"784a797915a38ead27bad456b5572cb4bbaa78c1","size":2735,"noattachment":false,"key":"/breakable/-/breakable-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/breakable/download/breakable-1.0.0.tgz"},"_resolved":"breakable.tgz","_from":"breakable.tgz","_npmVersion":"1.3.25","_npmUser":{"name":"olov","email":"olov.lassus@gmail.com"},"maintainers":[{"name":"olov","email":"olov.lassus@gmail.com"}],"directories":{},"publish_time":1399384450760,"_cnpm_publish_time":1399384450760,"_hasShrinkwrap":false},"0.1.0":{"name":"breakable","version":"0.1.0","description":"Break out of functions, recursive or not, in a more composable way than by using exceptions explicitly. Non-local return.","main":"breakable.js","repository":{"type":"git","url":"https://github.com/olov/breakable.git"},"keywords":["throw","try","catch","exception","non-local","return","break","breakable"],"scripts":{"test":"tap test/*.js"},"devDependencies":{"tap":"~0.4.4"},"author":{"name":"Olov Lassus","email":"olov.lassus@gmail.com"},"license":"MIT","readmeFilename":"README.md","_id":"breakable@0.1.0","dist":{"shasum":"fe6325427b2662bd6e024009bf232f3e35fab7f5","size":2630,"noattachment":false,"key":"/breakable/-/breakable-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/breakable/download/breakable-0.1.0.tgz"},"_resolved":"/tmp/breakable.tgz.tgz","_from":"/tmp/breakable.tgz.tgz","_npmVersion":"1.2.18","_npmUser":{"name":"olov","email":"olov.lassus@gmail.com"},"maintainers":[{"name":"olov","email":"olov.lassus@gmail.com"}],"directories":{},"publish_time":1379717371870,"_cnpm_publish_time":1379717371870,"_hasShrinkwrap":false}},"readme":"# breakable.js\nBreak out of functions, recursive or not, in a more composable way\nthan by using exceptions explicitly. Non-local return.\n\n\n\n## Usage\nYou can use breakable to break out of simple loops like this example\nbut note that it is often simpler to just use `.some` instead. Anyways,\nhere's a minimal example.\n\n```javascript\nvar breakable = require(\"breakable\");\n\nbreakable(function(brk) {\n    arr.forEach(function(v) {\n        if (...) {\n           brk();\n        }\n    });\n});\n```\n\nPass a value to `brk` and it becomes the return-value of breakable.\n\n\nbreakable is useful when you want to break out of a deep recursion,\npassing a value, without riddling your code with exception ceremony.\n\nInstead of:\n\n```javascript\nvar esprima = require(\"esprima\").parse;\nvar traverse = require(\"ast-traverse\");\nvar ast = esprima(\"f(!x, y)\");\n\nvar val;\ntry {\n    traverse(ast, {pre: function(node) {\n        if (node.type === \"UnaryExpression\" && node.operator === \"!\") {\n            val = node.argument;\n            throw 0;\n        }\n    }});\n} catch(e) {\n    if (val === undefined) {\n        throw e; // re-throw if it wasn't our exception\n    }\n}\n\nconsole.dir(val); // { type: 'Identifier', name: 'x' }\n```\n\nyou use breakable and do:\n\n```javascript\nvar breakable = require(\"breakable\");\nvar esprima = require(\"esprima\").parse;\nvar traverse = require(\"ast-traverse\");\nvar ast = esprima(\"f(!x, y)\");\n\nvar val = breakable(function(brk) {\n    traverse(ast, {pre: function(node) {\n        if (node.type === \"UnaryExpression\" && node.operator === \"!\") {\n            brk(node.argument);\n        }\n    }});\n});\n\nconsole.dir(val); // { type: 'Identifier', name: 'x' }\n```\n\n\n\n## Installation\n\n### Node\nInstall using npm\n\n    npm install breakable\n\n```javascript\nvar breakable = require(\"breakable\");\n```\n\n### Browser\nClone the repo and include it in a script tag\n\n    git clone https://github.com/olov/breakable.git\n\n```html\n<script src=\"breakable/breakable.js\"></script>\n```\n","_attachments":{},"homepage":"https://github.com/olov/breakable","bugs":{"url":"https://github.com/olov/breakable/issues"},"license":"MIT"}