Packages

tiny-invariant

1.3.3 · 23 Feb 2024MIT116.9M / weekRepositoryHomepagenpmAtom feed

Your version

1.2.0

31 Oct 2021Where it was published

1.3.3 is the newest release of 1.x.

Release note

New: Get message function

The message provided to invariant can now be a function that returns a string

- export default function invariant(condition: any, message?: string): asserts condition;
+ export default function invariant(condition: any, message?: string | (() => string)): asserts condition;

Using a function that returns a string is helpful in cases where your message is expensive to create. By using a function you only need to create the message when you need it.

import invariant from 'tiny-invariant';

invariant(value, () => getExpensiveMessage());

Keep in mind, that ideally the second argument to invariant is stripped away entirely in production builds.

We have a guide on how to do remove messages for production builds

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.