$ cnpm install @octetstream/invariant
Declarative errors throwing for Node.js
invariant(predicate, error) -> {void}true.invatiant(predicate, message[, ...format]) -> {void}true.invariant(predicate, Error, message[, ...format]) -> {void}true.invariant.reject(predicate, message[, ...format]) -> {Promise<void>}Do the same things as invariant, but returns Promise that will be rejected when predicate is true.
This function have same API as invariant.
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)
invariant(typeof value !== "string", "The value should be a string, but given type is: %s", typeof value)
invariant(typeof value !== "string", new TypeError(`The value should be a string, but given type is: ${typeof value}`))
// Will return rejected Promise instead of throw error synchronously
invariant.reject(typeof value !== "string", TypeError, "The value should be a string, but given type is: %s", typeof value)
.catch(err => console.error(err))
Copyright 2013 - present © cnpmjs.org | Home |