项目作者: gggauravgandhi

项目描述 :
A way to provide descriptive errors in development but generic errors in production.
高级语言: JavaScript
项目地址: git://github.com/gggauravgandhi/invariants.git
创建时间: 2017-12-17T07:27:33Z
项目社区:https://github.com/gggauravgandhi/invariants

开源协议:MIT License

下载


invariants

Used Underscore.js‘s way of making universal module, and used codebase of zertosh’s invariants repo, to make it usable everywhere.

A mirror of Facebook’s invariant (e.g. React, flux).

A way to provide descriptive errors in development but generic errors in production.

Install

NPM

  1. npm install invariants

Bower

  1. bower install invariants

Browser

  1. <script src="invariants.js"></script>
  2. <script>
  3. invariants(false, 'This will always fail');
  4. </script>

invariants(condition, message)

  1. const invariants = require('invariants');
  2. invariants(someTruthyVal, 'This will not throw');
  3. // No errors
  4. invariants(someFalseyVal, 'This will throw an error with this message');
  5. // Error: Invariants Violation: This will throw an error with this message

Note: When process.env.NODE_ENV is not production, the message is required. If omitted, invariants will throw regardless of the truthiness of the condition. When process.env.NODE_ENV is production, the message is optional – so they can be minified away.