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