tiny-invariant

  • Version 1.3.3
  • Published
  • 14.8 kB
  • No dependencies
  • MIT license

Install

npm i tiny-invariant
yarn add tiny-invariant
pnpm add tiny-invariant

Overview

A tiny invariant function

Index

Functions

Functions

function invariant

invariant: (
condition: any,
message?: string | (() => string)
) => asserts condition;
  • invariant is used to [assert](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions) that the condition is [truthy](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy).

    💥 invariant will throw an Error if the condition is [falsey](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy)

    🤏 messages are not displayed in production environments to help keep bundles small

    Example 1

    const value: Person | null = { name: 'Alex' };
    invariant(value, 'Expected value to be a person');
    // type of `value`` has been narrowed to `Person`

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (16)

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/tiny-invariant.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/tiny-invariant)
  • HTML
    <a href="https://www.jsdocs.io/package/tiny-invariant"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>