UNPKG

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