invariant
    Overview
    Documentation
    Tutorials
    Insights
    Code
    Dependencies
    Contributors
    Jobs

invariant

invariant

2.2.4  •  Updated 10 months ago  •  by Andres Suarez  •  MIT License

Build Status

A mirror of Facebook’s invariant (e.g. React, flux).

A way to provide descriptive errors in development but generic errors in production.

Install

With npm do:

npm install invariant

invariant(condition, message)

var invariant = require('invariant');

invariant(someTruthyVal, 'This will not throw');
// No errors

invariant(someFalseyVal, 'This will throw an error with this message');
// Error: Invariant Violation: This will throw an error with this message

Note: When process.env.NODE_ENV is not production, the message is required. If omitted, invariant will throw regardless of the truthiness of the condition. When process.env.NODE_ENV is production, the message is optional – so they can be minified away.

Browser

When used with browserify, it’ll use browser.js (instead of invariant.js) and the envify transform will inline the value of process.env.NODE_ENV.

Node

The node version is optimized around the performance implications of accessing process.env. The value of process.env.NODE_ENV is cached, and repeatedly used instead of reading process.env. See Server rendering is slower with npm react #812

Popularity

Weekly Downloads
7.6M
Stars
915

Maintenance

Development

Last ver 2 years ago
Created 6 years ago
Last commit 2 years ago
25 days between commits

Technology

Node version: 9.5.0
7.6K unpacked

Compliance

MIT License
OSI Approved
0 vulnerabilities

Contributors

10 contributors
Andres Suarez
Maintainer, 42 commits, 11 merges, 1 PRs
Works at facebook
Jan Kassens
Maintainer, 2 commits, 2 PRs
Works at Facebook
NothingEverHappens
1 commits, 1 PRs
Polgár András
1 commits, 1 PRs
Alex McLeod
1 commits, 1 PRs
Works at Myagi
Nick Williams
1 commits, 1 PRs

Tags

test
invariant
Openbase helps developers choose among and use millions of open-source packages, so they can build amazing products faster.
FacebookTwitterLinkedIn
© 2020 Devstore, Inc.