# invariant

> invariant

Latest version **2.2.4** (published 2018-03-13) · MIT license · 0 weekly downloads

> **Better alternative:** See documentation for alternatives (https://github.com/AikidoSec/module-replacements/blob/main/docs/invariant)

## Install

```sh
npm install invariant
pnpm add invariant
yarn add invariant
bun add invariant
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.4 |
| Published | 2018-03-13 |
| First published | 2014-09-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/invariant) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1228 |
| Author | Andres Suarez |
| Maintainers | cpojer, zertosh |
| Keywords | test, invariant |

## Links

- npm: https://www.npmjs.com/package/invariant
- Repository: https://github.com/zertosh/invariant
- Homepage: https://github.com/zertosh/invariant#readme
- Issues: https://github.com/zertosh/invariant/issues
- npm.io page: https://npm.io/package/invariant

## Dependencies (1)

- [loose-envify](https://npm.io/package/loose-envify.md) ^1.0.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 2.2.4 (latest) — 2018-03-13
- 2.2.3 — 2018-02-19
- 2.2.2 — 2016-11-15
- 2.2.1 — 2016-03-09
- 2.2.0 — 2015-11-17
- 2.1.3 — 2015-11-17
- 2.1.2 — 2015-10-27
- 2.1.1 — 2015-09-21
- 2.1.0 — 2015-06-03
- 2.0.0 — 2015-02-21
- 1.0.2 — 2014-09-24
- 1.0.1 — 2014-09-24
- 1.0.0 — 2014-09-24

## README

# invariant

[![Build Status](https://travis-ci.org/zertosh/invariant.svg?branch=master)](https://travis-ci.org/zertosh/invariant)

A mirror of Facebook's `invariant` (e.g. [React](https://github.com/facebook/react/blob/v0.13.3/src/vendor/core/invariant.js), [flux](https://github.com/facebook/flux/blob/2.0.2/src/invariant.js)).

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

## Install

With [npm](http://npmjs.org) do:

```sh
npm install invariant
```

## `invariant(condition, message)`

```js
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](https://github.com/substack/node-browserify), it'll use `browser.js` (instead of `invariant.js`) and the [envify](https://github.com/hughsk/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](https://github.com/facebook/react/issues/812)

---
_Source: https://npm.io/package/invariant · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
