UNPKG

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