tiny-invariant.js 841 B

1234567891011121314151617181920212223
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.invariant = factory());
  5. })(this, (function () { 'use strict';
  6. var isProduction = process.env.NODE_ENV === 'production';
  7. var prefix = 'Invariant failed';
  8. function invariant(condition, message) {
  9. if (condition) {
  10. return;
  11. }
  12. if (isProduction) {
  13. throw new Error(prefix);
  14. }
  15. var provided = typeof message === 'function' ? message() : message;
  16. var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
  17. throw new Error(value);
  18. }
  19. return invariant;
  20. }));