DimensionError.js 1.2 KB

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.DimensionError = DimensionError;
  6. /**
  7. * Create a range error with the message:
  8. * 'Dimension mismatch (<actual size> != <expected size>)'
  9. * @param {number | number[]} actual The actual size
  10. * @param {number | number[]} expected The expected size
  11. * @param {string} [relation='!='] Optional relation between actual
  12. * and expected size: '!=', '<', etc.
  13. * @extends RangeError
  14. */
  15. function DimensionError(actual, expected, relation) {
  16. if (!(this instanceof DimensionError)) {
  17. throw new SyntaxError('Constructor must be called with the new operator');
  18. }
  19. this.actual = actual;
  20. this.expected = expected;
  21. this.relation = relation;
  22. this.message = 'Dimension mismatch (' + (Array.isArray(actual) ? '[' + actual.join(', ') + ']' : actual) + ' ' + (this.relation || '!=') + ' ' + (Array.isArray(expected) ? '[' + expected.join(', ') + ']' : expected) + ')';
  23. this.stack = new Error().stack;
  24. }
  25. DimensionError.prototype = new RangeError();
  26. DimensionError.prototype.constructor = RangeError;
  27. DimensionError.prototype.name = 'DimensionError';
  28. DimensionError.prototype.isDimensionError = true;