Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Invariant assertions implemented as babel-plugin-macros macro.

License

Notifications You must be signed in to change notification settings

vasiliicuhar/invariant.macro

Repository files navigation

deprecated: use babel-plugin-dev-expression instead.

invariant.macro

Invariant assertions implemented as babel-plugin-macros macro.


build version downloads MIT License

Install

# npm
npm install @vasiliicuhar/invariant.macro

# yarn
yarn add @vasiliicuhar/invariant.macro

Usage

import invariant from "@vasiliicuhar/invariant.macro"

let sum = 2 + 3
invariant(sum === 4, `expected 4, got ${sum}`)
// throws new InvariantError('Invariant failed: expected 4, got 5')

In production error messages are stripped from resulting bundle

invariant(condition, `error message ${prettyPrint(obj)}`)
// is transpiled to
invariant(condition)

Development only invariants

invariant(condition, "invariant failed", { env: "development" })