@leankylin-sheet/formula-parser 4.0.56 → 4.0.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +246 -246
  2. package/dist/index.esm.js +137 -137
  3. package/dist/index.js +137 -137
  4. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -169,11 +169,11 @@ function _nonIterableRest() {
169
169
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
170
170
  }
171
171
 
172
- /**
173
- * Convert value into number.
174
- *
175
- * @param {String|Number} number
176
- * @returns {*}
172
+ /**
173
+ * Convert value into number.
174
+ *
175
+ * @param {String|Number} number
176
+ * @returns {*}
177
177
  */
178
178
  function toNumber(number) {
179
179
  var _result;
@@ -189,11 +189,11 @@ function toNumber(number) {
189
189
  return (_result = result) !== null && _result !== void 0 ? _result : 0;
190
190
  }
191
191
 
192
- /**
193
- * Invert provided number.
194
- *
195
- * @param {Number} number
196
- * @returns {Number} Returns inverted number.
192
+ /**
193
+ * Invert provided number.
194
+ *
195
+ * @param {Number} number
196
+ * @returns {Number} Returns inverted number.
197
197
  */
198
198
  function invertNumber(number) {
199
199
  return -1 * toNumber(number);
@@ -226,11 +226,11 @@ var ERROR_VALUE = 'VALUE';
226
226
  var errors_formula_map = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ERROR, utils.errors.error), ERROR_DIV_ZERO, utils.errors.div0), ERROR_NAME, utils.errors.name), ERROR_NOT_AVAILABLE, utils.errors.na), ERROR_NULL, utils.errors.nil), ERROR_NUM, utils.errors.num), ERROR_REF, utils.errors.ref), ERROR_VALUE, utils.errors.value);
227
227
  var errors = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ERROR, '#ERROR!'), ERROR_DIV_ZERO, '#DIV/0!'), ERROR_NAME, '#NAME?'), ERROR_NOT_AVAILABLE, '#N/A'), ERROR_NULL, '#NULL!'), ERROR_NUM, '#NUM!'), ERROR_REF, '#REF!'), ERROR_VALUE, '#VALUE!');
228
228
 
229
- /**
230
- * Return error type based on provided error id.
231
- *
232
- * @param {String} type Error type.
233
- * @returns {String|null} Returns error id.
229
+ /**
230
+ * Return error type based on provided error id.
231
+ *
232
+ * @param {String} type Error type.
233
+ * @returns {String|null} Returns error id.
234
234
  */
235
235
  function error(type) {
236
236
  var result;
@@ -241,11 +241,11 @@ function error(type) {
241
241
  return result ? result : null;
242
242
  }
243
243
 
244
- /**
245
- * Check if error type is strict valid with knows errors.
246
- *
247
- * @param {String} Error type.
248
- * @return {Boolean}
244
+ /**
245
+ * Check if error type is strict valid with knows errors.
246
+ *
247
+ * @param {String} Error type.
248
+ * @return {Boolean}
249
249
  */
250
250
  function isValidStrict(type) {
251
251
  var valid = false;
@@ -464,12 +464,12 @@ function func$9(first) {
464
464
  }
465
465
  func$9.SYMBOL = SYMBOL$9;
466
466
 
467
- /**
468
- * 解决js处理精度问题
469
- * 0.3 * 0.1 = 0.03
470
- * @param num1
471
- * @param num2
472
- * @returns
467
+ /**
468
+ * 解决js处理精度问题
469
+ * 0.3 * 0.1 = 0.03
470
+ * @param num1
471
+ * @param num2
472
+ * @returns
473
473
  */
474
474
  var multiplyNumber = function multiplyNumber() {
475
475
  var num1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
@@ -538,12 +538,12 @@ func$c.SYMBOL = SYMBOL$c;
538
538
 
539
539
  var availableOperators = Object.create(null);
540
540
 
541
- /**
542
- * Evaluate values by operator id.git
543
- *
544
- * @param {String} operator Operator id.
545
- * @param {Array} [params=[]] Arguments to evaluate.
546
- * @returns {*}
541
+ /**
542
+ * Evaluate values by operator id.git
543
+ *
544
+ * @param {String} operator Operator id.
545
+ * @param {Array} [params=[]] Arguments to evaluate.
546
+ * @returns {*}
547
547
  */
548
548
  function evaluateByOperator(operator) {
549
549
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
@@ -554,11 +554,11 @@ function evaluateByOperator(operator) {
554
554
  return availableOperators[operator].apply(availableOperators, _toConsumableArray(params));
555
555
  }
556
556
 
557
- /**
558
- * Register operator.
559
- *
560
- * @param {String|Array} symbol Symbol to register.
561
- * @param {Function} func Logic to register for this symbol.
557
+ /**
558
+ * Register operator.
559
+ *
560
+ * @param {String|Array} symbol Symbol to register.
561
+ * @param {Function} func Logic to register for this symbol.
562
562
  */
563
563
  function registerOperation(symbol, func) {
564
564
  if (!Array.isArray(symbol)) {
@@ -1994,12 +1994,12 @@ Parser.prototype = parser;
1994
1994
  parser.Parser = Parser;
1995
1995
 
1996
1996
  /* eslint-disable import/prefer-default-export */
1997
- /**
1998
- * Trim value by cutting character starting from the beginning and ending at the same time.
1999
- *
2000
- * @param {String} string String to trimming.
2001
- * @param {Number} [margin=1] Number of character to cut.
2002
- * @returns {String}
1997
+ /**
1998
+ * Trim value by cutting character starting from the beginning and ending at the same time.
1999
+ *
2000
+ * @param {String} string String to trimming.
2001
+ * @param {Number} [margin=1] Number of character to cut.
2002
+ * @returns {String}
2003
2003
  */
2004
2004
  function trimEdges(string) {
2005
2005
  var margin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
@@ -2007,11 +2007,11 @@ function trimEdges(string) {
2007
2007
  return string;
2008
2008
  }
2009
2009
 
2010
- /**
2011
- * Convert row label to index.
2012
- *
2013
- * @param {String} label Row label (eq. '1', '5')
2014
- * @returns {Number} Returns -1 if label is not recognized otherwise proper row index.
2010
+ /**
2011
+ * Convert row label to index.
2012
+ *
2013
+ * @param {String} label Row label (eq. '1', '5')
2014
+ * @returns {Number} Returns -1 if label is not recognized otherwise proper row index.
2015
2015
  */
2016
2016
  function rowLabelToIndex(label) {
2017
2017
  var result = parseInt(label, 10);
@@ -2023,11 +2023,11 @@ function rowLabelToIndex(label) {
2023
2023
  return result;
2024
2024
  }
2025
2025
 
2026
- /**
2027
- * Convert row index to label.
2028
- *
2029
- * @param {Number} row Row index.
2030
- * @returns {String} Returns row label (eq. '1', '7').
2026
+ /**
2027
+ * Convert row index to label.
2028
+ *
2029
+ * @param {Number} row Row index.
2030
+ * @returns {String} Returns row label (eq. '1', '7').
2031
2031
  */
2032
2032
  function rowIndexToLabel(row) {
2033
2033
  var result = "";
@@ -2039,11 +2039,11 @@ function rowIndexToLabel(row) {
2039
2039
  var COLUMN_LABEL_BASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2040
2040
  var COLUMN_LABEL_BASE_LENGTH = COLUMN_LABEL_BASE.length;
2041
2041
 
2042
- /**
2043
- * Convert column label to index.
2044
- *
2045
- * @param {String} label Column label (eq. 'ABB', 'CNQ')
2046
- * @returns {Number} Returns -1 if label is not recognized otherwise proper column index.
2042
+ /**
2043
+ * Convert column label to index.
2044
+ *
2045
+ * @param {String} label Column label (eq. 'ABB', 'CNQ')
2046
+ * @returns {Number} Returns -1 if label is not recognized otherwise proper column index.
2047
2047
  */
2048
2048
  function columnLabelToIndex(label) {
2049
2049
  var result = 0;
@@ -2057,11 +2057,11 @@ function columnLabelToIndex(label) {
2057
2057
  return result;
2058
2058
  }
2059
2059
 
2060
- /**
2061
- * Convert column index to label.
2062
- *
2063
- * @param {Number} column Column index.
2064
- * @returns {String} Returns column label (eq. 'ABB', 'CNQ').
2060
+ /**
2061
+ * Convert column index to label.
2062
+ *
2063
+ * @param {Number} column Column index.
2064
+ * @returns {String} Returns column label (eq. 'ABB', 'CNQ').
2065
2065
  */
2066
2066
  function columnIndexToLabel(column) {
2067
2067
  var result = "";
@@ -2076,11 +2076,11 @@ var quotedSheetName$1 = "'(?:(?!').|'')*'";
2076
2076
  var sheetNameRegexp$1 = "(".concat(simpleSheetName$1, "|").concat(quotedSheetName$1, ")!");
2077
2077
  var LABEL_EXTRACT_REGEXP = new RegExp("^(?:".concat(sheetNameRegexp$1, ")?([$])?([A-Za-z]*)([$])?([0-9]*)$"));
2078
2078
 
2079
- /**
2080
- * Extract cell coordinates.
2081
- *
2082
- * @param {String} label Cell coordinates (eq. 'A1', '$B6', '$N$98').
2083
- * @returns {Array} Returns an array of objects.
2079
+ /**
2080
+ * Extract cell coordinates.
2081
+ *
2082
+ * @param {String} label Cell coordinates (eq. 'A1', '$B6', '$N$98').
2083
+ * @returns {Array} Returns an array of objects.
2084
2084
  */
2085
2085
  function extractLabel(label) {
2086
2086
  if (typeof label !== "string" || !LABEL_EXTRACT_REGEXP.test(label)) {
@@ -2106,12 +2106,12 @@ function extractLabel(label) {
2106
2106
  }, sheetName];
2107
2107
  }
2108
2108
 
2109
- /**
2110
- * Convert row and column indexes into cell label.
2111
- *
2112
- * @param {Object} row Object with `index` and `isAbsolute` properties.
2113
- * @param {Object} column Object with `index` and `isAbsolute` properties.
2114
- * @returns {String} Returns cell label.
2109
+ /**
2110
+ * Convert row and column indexes into cell label.
2111
+ *
2112
+ * @param {Object} row Object with `index` and `isAbsolute` properties.
2113
+ * @param {Object} column Object with `index` and `isAbsolute` properties.
2114
+ * @returns {String} Returns cell label.
2115
2115
  */
2116
2116
  function toLabel(row, column) {
2117
2117
  var rowLabel = (row.isAbsolute ? "$" : "") + rowIndexToLabel(row.index);
@@ -2119,8 +2119,8 @@ function toLabel(row, column) {
2119
2119
  return columnLabel + rowLabel;
2120
2120
  }
2121
2121
 
2122
- /**
2123
- * @class Parser
2122
+ /**
2123
+ * @class Parser
2124
2124
  */
2125
2125
  var Parser$1 = /*#__PURE__*/function (_Emitter) {
2126
2126
  function Parser$1() {
@@ -2156,13 +2156,13 @@ var Parser$1 = /*#__PURE__*/function (_Emitter) {
2156
2156
  return _this;
2157
2157
  }
2158
2158
 
2159
- /**
2160
- * Parse formula expression.
2161
- *
2162
- * @param {string} expression to parse.
2163
- * @param {object} options additional params.
2164
- * @param {string} options.sheetId id of sheet which the formula expression belongs to.
2165
- * @return {*} Returns an object with tow properties `error` and `result`.
2159
+ /**
2160
+ * Parse formula expression.
2161
+ *
2162
+ * @param {string} expression to parse.
2163
+ * @param {object} options additional params.
2164
+ * @param {string} options.sheetId id of sheet which the formula expression belongs to.
2165
+ * @return {*} Returns an object with tow properties `error` and `result`.
2166
2166
  */
2167
2167
  _inherits(Parser$1, _Emitter);
2168
2168
  return _createClass(Parser$1, [{
@@ -2198,12 +2198,12 @@ var Parser$1 = /*#__PURE__*/function (_Emitter) {
2198
2198
  };
2199
2199
  }
2200
2200
 
2201
- /**
2202
- * Set predefined variable name which can be visible while parsing formula expression.
2203
- *
2204
- * @param {String} name Variable name.
2205
- * @param {*} value Variable value.
2206
- * @returns {Parser}
2201
+ /**
2202
+ * Set predefined variable name which can be visible while parsing formula expression.
2203
+ *
2204
+ * @param {String} name Variable name.
2205
+ * @param {*} value Variable value.
2206
+ * @returns {Parser}
2207
2207
  */
2208
2208
  }, {
2209
2209
  key: "setVariable",
@@ -2216,11 +2216,11 @@ var Parser$1 = /*#__PURE__*/function (_Emitter) {
2216
2216
  value: function replaceVariables(variables) {
2217
2217
  this.variables = variables;
2218
2218
  }
2219
- /**
2220
- * Get variable name.
2221
- *
2222
- * @param {String} name Variable name.
2223
- * @returns {*}
2219
+ /**
2220
+ * Get variable name.
2221
+ *
2222
+ * @param {String} name Variable name.
2223
+ * @returns {*}
2224
2224
  */
2225
2225
  }, {
2226
2226
  key: "getVariable",
@@ -2228,12 +2228,12 @@ var Parser$1 = /*#__PURE__*/function (_Emitter) {
2228
2228
  return this.variables[name];
2229
2229
  }
2230
2230
 
2231
- /**
2232
- * Retrieve variable value by its name.
2233
- *
2234
- * @param name Variable name.
2235
- * @returns {*}
2236
- * @private
2231
+ /**
2232
+ * Retrieve variable value by its name.
2233
+ *
2234
+ * @param name Variable name.
2235
+ * @returns {*}
2236
+ * @private
2237
2237
  */
2238
2238
  }, {
2239
2239
  key: "_callVariable",
@@ -2250,12 +2250,12 @@ var Parser$1 = /*#__PURE__*/function (_Emitter) {
2250
2250
  return value;
2251
2251
  }
2252
2252
 
2253
- /**
2254
- * Set custom function which can be visible while parsing formula expression.
2255
- *
2256
- * @param {String} name Custom function name.
2257
- * @param {Function} fn Custom function.
2258
- * @returns {Parser}
2253
+ /**
2254
+ * Set custom function which can be visible while parsing formula expression.
2255
+ *
2256
+ * @param {String} name Custom function name.
2257
+ * @param {Function} fn Custom function.
2258
+ * @returns {Parser}
2259
2259
  */
2260
2260
  }, {
2261
2261
  key: "setFunction",
@@ -2264,11 +2264,11 @@ var Parser$1 = /*#__PURE__*/function (_Emitter) {
2264
2264
  return this;
2265
2265
  }
2266
2266
 
2267
- /**
2268
- * Get custom function.
2269
- *
2270
- * @param {String} name Custom function name.
2271
- * @returns {*}
2267
+ /**
2268
+ * Get custom function.
2269
+ *
2270
+ * @param {String} name Custom function name.
2271
+ * @returns {*}
2272
2272
  */
2273
2273
  }, {
2274
2274
  key: "getFunction",
@@ -2276,13 +2276,13 @@ var Parser$1 = /*#__PURE__*/function (_Emitter) {
2276
2276
  return this.functions[name];
2277
2277
  }
2278
2278
 
2279
- /**
2280
- * Call function with provided params.
2281
- *
2282
- * @param name Function name.
2283
- * @param params Function params.
2284
- * @returns {*}
2285
- * @private
2279
+ /**
2280
+ * Call function with provided params.
2281
+ *
2282
+ * @param name Function name.
2283
+ * @param params Function params.
2284
+ * @returns {*}
2285
+ * @private
2286
2286
  */
2287
2287
  }, {
2288
2288
  key: "_callFunction",
@@ -2301,12 +2301,12 @@ var Parser$1 = /*#__PURE__*/function (_Emitter) {
2301
2301
  return value === void 0 ? evaluateByOperator(name, params) : value;
2302
2302
  }
2303
2303
 
2304
- /**
2305
- * Retrieve value by its label (`B3`, `B$3`, `B$3`, `$B$3`).
2306
- *
2307
- * @param {String} label Coordinates.
2308
- * @returns {*}
2309
- * @private
2304
+ /**
2305
+ * Retrieve value by its label (`B3`, `B$3`, `B$3`, `$B$3`).
2306
+ *
2307
+ * @param {String} label Coordinates.
2308
+ * @returns {*}
2309
+ * @private
2310
2310
  */
2311
2311
  }, {
2312
2312
  key: "_callCellValue",
@@ -2336,13 +2336,13 @@ var Parser$1 = /*#__PURE__*/function (_Emitter) {
2336
2336
  return value;
2337
2337
  }
2338
2338
 
2339
- /**
2340
- * Retrieve value by its label (`B3:A1`, `B$3:A1`, `B$3:$A1`, `$B$3:A$1`).
2341
- *
2342
- * @param {String} startLabel Coordinates of the first cell.
2343
- * @param {String} endLabel Coordinates of the last cell.
2344
- * @returns {Array} Returns an array of mixed values.
2345
- * @private
2339
+ /**
2340
+ * Retrieve value by its label (`B3:A1`, `B$3:A1`, `B$3:$A1`, `$B$3:A$1`).
2341
+ *
2342
+ * @param {String} startLabel Coordinates of the first cell.
2343
+ * @param {String} endLabel Coordinates of the last cell.
2344
+ * @returns {Array} Returns an array of mixed values.
2345
+ * @private
2346
2346
  */
2347
2347
  }, {
2348
2348
  key: "_callRangeValue",
@@ -2387,12 +2387,12 @@ var Parser$1 = /*#__PURE__*/function (_Emitter) {
2387
2387
  return value;
2388
2388
  }
2389
2389
 
2390
- /**
2391
- * Try to throw error by its name.
2392
- *
2393
- * @param {String} errorName Error name.
2394
- * @returns {String}
2395
- * @private
2390
+ /**
2391
+ * Try to throw error by its name.
2392
+ *
2393
+ * @param {String} errorName Error name.
2394
+ * @returns {String}
2395
+ * @private
2396
2396
  */
2397
2397
  }, {
2398
2398
  key: "_throwError",