spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← All files
name: dist/Errors.js
-rw-r--r--
4983
  1"use strict";
  2var __extends = (this && this.__extends) || (function () {
  3    var extendStatics = Object.setPrototypeOf ||
  4        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6    return function (d, b) {
  7        extendStatics(d, b);
  8        function __() { this.constructor = d; }
  9        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
 10    };
 11})();
 12exports.__esModule = true;
 13var NULL_ERROR = "#NULL!";
 14exports.NULL_ERROR = NULL_ERROR;
 15var DIV_ZERO_ERROR = "#DIV/0!";
 16exports.DIV_ZERO_ERROR = DIV_ZERO_ERROR;
 17var VALUE_ERROR = "#VALUE!";
 18exports.VALUE_ERROR = VALUE_ERROR;
 19var REF_ERROR = "#REF!";
 20exports.REF_ERROR = REF_ERROR;
 21var NAME_ERROR = "#NAME!";
 22exports.NAME_ERROR = NAME_ERROR;
 23var NUM_ERROR = "#NUM!";
 24exports.NUM_ERROR = NUM_ERROR;
 25var NA_ERROR = "#N/A";
 26exports.NA_ERROR = NA_ERROR;
 27var PARSE_ERROR = "#ERROR";
 28exports.PARSE_ERROR = PARSE_ERROR;
 29/**
 30 * Execution or parsing produced a null value, or intersection of ranges produced zero cells.
 31 */
 32var NullError = /** @class */ (function (_super) {
 33    __extends(NullError, _super);
 34    function NullError(message) {
 35        var _this = _super.call(this, message) || this;
 36        _this.name = NULL_ERROR;
 37        return _this;
 38    }
 39    return NullError;
 40}(Error));
 41exports.NullError = NullError;
 42/**
 43 * Attempt to divide by zero, including division by an empty cell.
 44 */
 45var DivZeroError = /** @class */ (function (_super) {
 46    __extends(DivZeroError, _super);
 47    function DivZeroError(message) {
 48        var _this = _super.call(this, message) || this;
 49        _this.name = DIV_ZERO_ERROR;
 50        return _this;
 51    }
 52    return DivZeroError;
 53}(Error));
 54exports.DivZeroError = DivZeroError;
 55/**
 56 * Parameter is wrong type, or value is incompatible, or cannot be parsed, converted, or manipulated.
 57 */
 58var ValueError = /** @class */ (function (_super) {
 59    __extends(ValueError, _super);
 60    function ValueError(message) {
 61        var _this = _super.call(this, message) || this;
 62        _this.name = VALUE_ERROR;
 63        return _this;
 64    }
 65    return ValueError;
 66}(Error));
 67exports.ValueError = ValueError;
 68/**
 69 * Reference to invalid cell, range, or empty range.
 70 */
 71var RefError = /** @class */ (function (_super) {
 72    __extends(RefError, _super);
 73    function RefError(message) {
 74        var _this = _super.call(this, message) || this;
 75        _this.name = REF_ERROR;
 76        return _this;
 77    }
 78    return RefError;
 79}(Error));
 80exports.RefError = RefError;
 81/**
 82 * Unrecognized/deleted name.
 83 */
 84var NameError = /** @class */ (function (_super) {
 85    __extends(NameError, _super);
 86    function NameError(message) {
 87        var _this = _super.call(this, message) || this;
 88        _this.name = NAME_ERROR;
 89        return _this;
 90    }
 91    return NameError;
 92}(Error));
 93exports.NameError = NameError;
 94/**
 95 * Failed to meet domain constraints (e.g., input number too high or too low).
 96 */
 97var NumError = /** @class */ (function (_super) {
 98    __extends(NumError, _super);
 99    function NumError(message) {
100        var _this = _super.call(this, message) || this;
101        _this.name = NUM_ERROR;
102        return _this;
103    }
104    return NumError;
105}(Error));
106exports.NumError = NumError;
107/**
108 * Lookup functions which failed and NA() return this value.
109 */
110var NAError = /** @class */ (function (_super) {
111    __extends(NAError, _super);
112    function NAError(message) {
113        var _this = _super.call(this, message) || this;
114        _this.name = NA_ERROR;
115        return _this;
116    }
117    return NAError;
118}(Error));
119exports.NAError = NAError;
120/**
121 * Input could not be parsed.
122 */
123var ParseError = /** @class */ (function (_super) {
124    __extends(ParseError, _super);
125    function ParseError(message) {
126        var _this = _super.call(this, message) || this;
127        _this.name = PARSE_ERROR;
128        return _this;
129    }
130    return ParseError;
131}(Error));
132exports.ParseError = ParseError;
133/**
134 * Constructs an error by error name.
135 * @param {string} name - Name of error. If not one of DIV_ZERO_ERROR, NULL_ERROR, VALUE_ERROR, REF_ERROR, NAME_ERROR,
136 * NUM_ERROR,NA_ERROR, or PARSE_ERROR, will default to ParseError.
137 * @param {string} msg - Message for error, will default to empty string.
138 * @returns {Error}
139 */
140function constructErrorByName(name, msg) {
141    msg = msg || "";
142    switch (name) {
143        case DIV_ZERO_ERROR:
144            return new DivZeroError(msg);
145        case NULL_ERROR:
146            return new NullError(msg);
147        case VALUE_ERROR:
148            return new ValueError(msg);
149        case REF_ERROR:
150            return new RefError(msg);
151        case NAME_ERROR:
152            return new NameError(msg);
153        case NA_ERROR:
154            return new NAError(msg);
155        case NUM_ERROR:
156            return new NumError(msg);
157        default:
158            return new ParseError(msg);
159    }
160}
161exports.constructErrorByName = constructErrorByName;