Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@octetstream/invariant

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@octetstream/invariant

Declarative errors throwing for Node.js

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@octetstream/invariant

Declarative errors throwing for Node.js

dependencies Status devDependencies Status Build Status Code Coverage

API

invariant(predicate, error) -> {void}

  • boolean predicate – a result of some condition. Error will threw if predicate is true.
  • object error – some error object

invatiant(predicate, message[, ...format]) -> {void}

  • 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]) -> {void}

  • boolean predicate – a result of some condition. Error will threw if predicate is true.
  • Function Error – custom error class that will be used as an error constructor
  • string message – an error message
  • any format – see more about the format in a sprintf-js documentation

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.

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)

  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))

Keywords

FAQs

Package last updated on 18 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc