Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

breakable

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

breakable - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

18

breakable.js
// breakable.js
// MIT licensed, see LICENSE file
// Copyright (c) 2013 Olov Lassus <olov.lassus@gmail.com>
// Copyright (c) 2013-2014 Olov Lassus <olov.lassus@gmail.com>

@@ -8,15 +8,19 @@ var breakable = (function() {

function Val(val) {
function Val(val, brk) {
this.val = val;
this.brk = brk;
}
function brk(val) {
throw new Val(val);
function make_brk() {
return function brk(val) {
throw new Val(val, brk);
};
}
function breakable(fn) {
var brk = make_brk();
try {
return fn(brk);
} catch (e) {
if (e instanceof Val) {
if (e instanceof Val && e.brk === brk) {
return e.val;

@@ -28,6 +32,2 @@ }

breakable.fn = function breakablefn(fn) {
return breakable.bind(null, fn);
};
return breakable;

@@ -34,0 +34,0 @@ })();

{
"name": "breakable",
"version": "0.1.0",
"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.",

@@ -5,0 +5,0 @@ "main": "breakable.js",

@@ -35,6 +35,6 @@ "use strict";

test("simple-throws", function(t) {
t.throws(breakable.fn(function(brk) {
t.throws(breakable.bind(null, function(brk) {
throw 1;
}));
t.doesNotThrow(breakable.fn(function(brk) {
t.doesNotThrow(breakable.bind(null, function(brk) {
brk(1);

@@ -98,1 +98,23 @@ throw 2;

});
test("nested-breakables-1", function(t) {
var res = breakable(function(brk1) {
breakable(function(brk2) {
brk1(13);
});
});
t.equal(res, 13);
t.end();
});
test("nested-breakables-2", function(t) {
t.plan(2);
var res1 = breakable(function(brk1) {
var res2 = breakable(function(brk2) {
brk2(13);
});
t.equal(res2, 13);
});
t.equal(res1, undefined);
t.end();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc