invariant.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. var root = require('./root');
  2. exports = function(condition, format, a, b, c, d, e, f) {
  3. var process = root.process || {
  4. env: {
  5. NODE_ENV: 'development'
  6. }
  7. };
  8. if (process.env.NODE_ENV !== 'production') {
  9. if (format === undefined) {
  10. throw new Error('invariant requires an error message argument');
  11. }
  12. }
  13. if (!condition) {
  14. var error;
  15. if (format === undefined) {
  16. error = new Error(
  17. 'Minified exception occurred; use the non-minified dev environment ' +
  18. 'for the full error message and additional helpful warnings.'
  19. );
  20. } else {
  21. var args = [a, b, c, d, e, f];
  22. var argIndex = 0;
  23. error = new Error(
  24. format.replace(/%s/g, function() {
  25. return args[argIndex++];
  26. })
  27. );
  28. error.name = 'Invariant Violation';
  29. }
  30. error.framesToPop = 1;
  31. throw error;
  32. }
  33. };
  34. module.exports = exports;