simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

DimensionError.js (1254B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.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  */
     17 function 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 
     29 DimensionError.prototype = new RangeError();
     30 DimensionError.prototype.constructor = RangeError;
     31 DimensionError.prototype.name = 'DimensionError';
     32 DimensionError.prototype.isDimensionError = true;