Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

invariant-slim

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

invariant-slim

A simpler version of Facebook's invariant implementation from React

latest
Source
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

invariant-slim

A simpler version of Facebook's invariant implementation from React.

Installation

invariant-slim is available as an npm package. Simply run npm install invariant-slim command.

To use it in your project:

import invariant from 'invariant-slim'; // ES6 syntax
var invariant = require('invariant-slim'); // ES5 syntax

Usage

Use invariant() to assert state which your program assumes to be true.

Pass in a condition to be evaluated and a format to be displayed as an error message. The format respects the sprintf-style syntax ('%s' will be replaced by whatever arguments are passed in).

Examples:

The following code will not throw:

invariant(
  true,
  'Demo message'
);

The following code will throw with a static message and will output the following error in the console - 'Invariant Violation: A static error message':

invariant(
  false,
  'A static error message'
);

The following code will throw with a dynamic formatted error message and will output the following error in the console - 'Invariant Violation: A dynamic error message arg1,arg2':

invariant(
  false,
  'A dynamic error message %s',
  ['arg1', 'arg2']
);

License

This software is released under the terms of WTFPL v2.0 license.

Keywords

invariant

FAQs

Package last updated on 19 Aug 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