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

bimodal

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

bimodal

bimodal eliminates try/catch boilerplate and replaces it with a two-channel [err, result] array

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

bimodal

bimodal is an experiment in replacing try/catch boilerplate with an [err, result] array, inspired by error return values in Go.

Installation

# npm
npm i --save bimodal

# yarn
yarn add bimodal

Usage

const bimodal = require('bimodal')

const [err, result] = await bimodal (fnThatMayThrowError, arg1, arg2, ...)

Rationale

This is annoying:

let result

try {
  result = await fnThatMayThrowError()
}
catch (err) {
  // ...
}

// use result

This is nicer:

let [err, result] = await bimodal (fnThatMayThrowError)

if (err) {
  // ...
}

// use result

What's it doing?

Not much:

module.exports = async (fn, ...args) => {
  const channels = [undefined, undefined]

  try {
    channels[1] = await fn.apply(null, args)
  }
  catch (err) {
    channels[0] = err
  }
  finally {
    return channels
  }
}

Keywords

FAQs

Package last updated on 29 Oct 2019

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