@guanghechen/invariant
TypeScript icon, indicating that this package has built-in type declarations

6.0.0-alpha.1 • Public • Published

@guanghechen/invariant


An invariant function, which takes a condition and a optional message value, and throw an error when the given condition fails.

Install

  • npm

    npm install --save @guanghechen/invariant
  • yarn

    yarn add @guanghechen/invariant

Usage

  • Syntax

    function invariant(
      condition: boolean,
      message?: string | (() => string),
    ): asserts condition
  • Demo

    import invariant from '@guanghechen/invariant'
    
    invariant(typeof window !== 'undefined', '`window` is not defined.')
    invariant(typeof window !== 'undefined', () => '`window` is not defined:' + window)

Related

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @guanghechen/invariant

      Weekly Downloads

      375

      Version

      6.0.0-alpha.1

      License

      MIT

      Unpacked Size

      30.9 kB

      Total Files

      8

      Last publish

      Collaborators

      • lemonclown