JSPM

@octetstream/invariant

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2619
  • Score
    100M100P100Q113486F
  • License MIT

Declarative errors throwing for Node.js

Package Exports

  • @octetstream/invariant

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@octetstream/invariant) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@octetstream/invariant

Declarative errors throwing for Node.js

dependencies Status devDependencies Status Build Status Code Coverage

API

This library have two little bit different APIs:

invatiant(predicate, message[, ...format])

  • boolean predicate – a result of some condition. Error will threw if predicate is true.
  • string message – an error message
  • any format – see more about the format in a sprintf-js documentation

invariant(predicate, Error, message[, ...format])

  • Function Error – custom error class that will be used as an error constructor

Example

  import invariant from "@octetstream/invariant"

  // some of your code...

  // Will threw a TypeError if "value" is not a string
  invariant(typeof value !== "string", TypeError, "The value should be a string, but given type is: %s", typeof value)