New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

simple-guards

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

simple-guards

Utils to add guard clauses to JS code

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Simple Guards

Description

Simple utilities to add guard clauses to yout JS code.

Guards raises an Error if a given condition is truthy.

Features

  • Guards not executed in production environment (process.env.NODE_ENV !== "production")
  • Guards can be checked lazily

Install

npm instal simple-guards

Usage

To set a simple guard:

import { guard } from "simple-guards";

function division(numerator, denominator) {
  guard(denominator === 0, "denominator cannot be zero");

  // more awful code
}

You can also pass a function to lazy evaluate an expensive guard:


function division(numerator, denominator) {
  guard(() => expensiveDetectionOfZero(denominator), "denominator cannot be zero");

  // more awful code
}

If you want to lazy evaluate many guards you can use the guards method to avoid excessive wrapper functions:

import { guards } from "simple-guards";

function division(numerator, denominator) {
  guards((guard) => {
    guard(expensiveDetectionOfZero(numerator), "we don't want numerator to be zero");
    guard(expensiveDetectionOfZero(denominator), "denominator cannot be zero");
  })

  // more awful code
}

FAQs

Package last updated on 14 Feb 2017

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