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

boom-invariant

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boom-invariant

An implementation of Facebook's invariant() function built on top of Boom errors

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

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

boom-invariant

This is an implementation of Facebook's invariant() function built on top of Boom, a library for constructing error objects with HTTP status codes. Usage and behavior are similar to the original, but with two noteworthy changes:

  • Error messages are not formatted for you. You should use ES6 template literals to format your error message when calling the function.
  • The third argument is an optional HTTP status code. By default the status code is 400 Bad Request.

Installation

If you're using npm:

npm i --save boom-invariant

If you're using yarn:

yarn add boom-invariant`

Usage

// Throws a Boom error with a 400 `statusCode` when `someCondition` is not truthy.
invariant(someCondition, 'Uh oh! Condition was not met!');
// Throws a Boom error with a 418 `statusCode` when `someCondition` is not truthy.
invariant(someCondition, 'Uh oh! Condition was not met because I\'m a teapot!', 418);

Or if you don't enjoy recalling HTTP status codes:

// Throws a Boom error with a 400 `statusCode` when someCondition is not truthy.
invariant(someCondition, 'Uh oh! I can\'t find the resource!', Boom.notFound);

Note that the error message argument is required.

FAQs

Package last updated on 30 Jan 2020

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