New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cond

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cond

Restartable error handling system

  • 0.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

CondJS

cond is hosted at Github. mona is a public domain work, dedicated using CC0 1.0. Feel free to do whatever you want with it.

Quickstart

Install

$ npm install cond or $ bower install cond

Example

Execute the following in a browser session, with developer tools open, and follow the instructions:


var availableFlavors = ["chocolate", "vanilla", "mint chocolate chip"];
function getIceCream(flavor) {
    if (availableFlavors.indexOf(flavor) !== -1) {
        return flavor + " ice cream ゲットー!";
    } else {
        // Just like throw new Error("something"), but we provide a way
        // the user can recover from it.
        return cond.error("Sorry, that flavor is not available", [
            "different-flavor", "Try a different flavor", getIceCream
        ], [
            "add-flavor", "Add this flavor to available ones and retry", function() {
                availableFlavors.push(flavor);
                return getIceCream(flavor);
            }
        ]);
    }
}

console.log(getIceCream("coffee"));
console.log("I really like this flavor!");

// In the console, do:

// > showRecoveries();
// > recover(0, "chocolate");

// You can also access recoveries programmatically:
console.log(cond.handlerBind(function() {
    return getIceCream("bubblegum");
}, [Error, function(e) { return cond.recover("add-flavor"); }]));

Introduction

cond is a JavaScript implementation of Common Lisp's condition system, a system for handling errors and other conditions of interest that handles signals at the call site, before the stack is unwound -- allowing you to repair or alter what happens at the callsite, and continuing executing as if nothing had been signaled/thrown.

Keywords

FAQs

Package last updated on 13 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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