@fileverse-dev/formula-parser 0.2.49-patch-2 → 0.2.49-patch-4

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 (47) hide show
  1. package/package.json +2 -2
  2. package/es/error.js +0 -45
  3. package/es/evaluate-by-operator/evaluate-by-operator.js +0 -70
  4. package/es/evaluate-by-operator/operator/add.js +0 -16
  5. package/es/evaluate-by-operator/operator/ampersand.js +0 -10
  6. package/es/evaluate-by-operator/operator/divide.js +0 -21
  7. package/es/evaluate-by-operator/operator/equal.js +0 -5
  8. package/es/evaluate-by-operator/operator/formula-function.js +0 -40
  9. package/es/evaluate-by-operator/operator/greater-than-or-equal.js +0 -5
  10. package/es/evaluate-by-operator/operator/greater-than.js +0 -5
  11. package/es/evaluate-by-operator/operator/less-than-or-equal.js +0 -5
  12. package/es/evaluate-by-operator/operator/less-than.js +0 -5
  13. package/es/evaluate-by-operator/operator/minus.js +0 -16
  14. package/es/evaluate-by-operator/operator/multiply.js +0 -16
  15. package/es/evaluate-by-operator/operator/not-equal.js +0 -5
  16. package/es/evaluate-by-operator/operator/power.js +0 -11
  17. package/es/grammar-parser/grammar-parser.jison +0 -230
  18. package/es/grammar-parser/grammar-parser.js +0 -1522
  19. package/es/helper/cell.js +0 -117
  20. package/es/helper/number.js +0 -25
  21. package/es/helper/string.js +0 -13
  22. package/es/index.js +0 -5
  23. package/es/parser.js +0 -318
  24. package/es/supported-formulas.js +0 -3
  25. package/lib/error.js +0 -53
  26. package/lib/evaluate-by-operator/evaluate-by-operator.js +0 -77
  27. package/lib/evaluate-by-operator/operator/add.js +0 -23
  28. package/lib/evaluate-by-operator/operator/ampersand.js +0 -17
  29. package/lib/evaluate-by-operator/operator/divide.js +0 -28
  30. package/lib/evaluate-by-operator/operator/equal.js +0 -12
  31. package/lib/evaluate-by-operator/operator/formula-function.js +0 -50
  32. package/lib/evaluate-by-operator/operator/greater-than-or-equal.js +0 -12
  33. package/lib/evaluate-by-operator/operator/greater-than.js +0 -12
  34. package/lib/evaluate-by-operator/operator/less-than-or-equal.js +0 -12
  35. package/lib/evaluate-by-operator/operator/less-than.js +0 -12
  36. package/lib/evaluate-by-operator/operator/minus.js +0 -23
  37. package/lib/evaluate-by-operator/operator/multiply.js +0 -23
  38. package/lib/evaluate-by-operator/operator/not-equal.js +0 -12
  39. package/lib/evaluate-by-operator/operator/power.js +0 -18
  40. package/lib/grammar-parser/grammar-parser.jison +0 -230
  41. package/lib/grammar-parser/grammar-parser.js +0 -1528
  42. package/lib/helper/cell.js +0 -128
  43. package/lib/helper/number.js +0 -32
  44. package/lib/helper/string.js +0 -19
  45. package/lib/index.js +0 -114
  46. package/lib/parser.js +0 -326
  47. package/lib/supported-formulas.js +0 -11
package/es/helper/cell.js DELETED
@@ -1,117 +0,0 @@
1
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
7
- /**
8
- * Convert row label to index.
9
- *
10
- * @param {String} label Row label (eq. '1', '5')
11
- * @returns {Number} Returns -1 if label is not recognized otherwise proper row index.
12
- */
13
- export function rowLabelToIndex(label) {
14
- var result = parseInt(label, 10);
15
- if (isNaN(result)) {
16
- result = -1;
17
- } else {
18
- result = Math.max(result - 1, -1);
19
- }
20
- return result;
21
- }
22
-
23
- /**
24
- * Convert row index to label.
25
- *
26
- * @param {Number} row Row index.
27
- * @returns {String} Returns row label (eq. '1', '7').
28
- */
29
- export function rowIndexToLabel(row) {
30
- var result = "";
31
- if (row >= 0) {
32
- result = "".concat(row + 1);
33
- }
34
- return result;
35
- }
36
- var COLUMN_LABEL_BASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
37
- var COLUMN_LABEL_BASE_LENGTH = COLUMN_LABEL_BASE.length;
38
-
39
- /**
40
- * Convert column label to index.
41
- *
42
- * @param {String} label Column label (eq. 'ABB', 'CNQ')
43
- * @returns {Number} Returns -1 if label is not recognized otherwise proper column index.
44
- */
45
- export function columnLabelToIndex(label) {
46
- var result = 0;
47
- if (typeof label === "string") {
48
- label = label.toUpperCase();
49
- for (var i = 0, j = label.length - 1; i < label.length; i += 1, j -= 1) {
50
- result += Math.pow(COLUMN_LABEL_BASE_LENGTH, j) * (COLUMN_LABEL_BASE.indexOf(label[i]) + 1);
51
- }
52
- }
53
- --result;
54
- return result;
55
- }
56
-
57
- /**
58
- * Convert column index to label.
59
- *
60
- * @param {Number} column Column index.
61
- * @returns {String} Returns column label (eq. 'ABB', 'CNQ').
62
- */
63
- export function columnIndexToLabel(column) {
64
- var result = "";
65
- while (column >= 0) {
66
- result = String.fromCharCode(column % COLUMN_LABEL_BASE_LENGTH + 97) + result;
67
- column = Math.floor(column / COLUMN_LABEL_BASE_LENGTH) - 1;
68
- }
69
- return result.toUpperCase();
70
- }
71
- var simpleSheetName = "[A-Za-z0-9_\xC0-\u02AF]+";
72
- var quotedSheetName = "'(?:(?!').|'')*'";
73
- var sheetNameRegexp = "(".concat(simpleSheetName, "|").concat(quotedSheetName, ")!");
74
- var LABEL_EXTRACT_REGEXP = new RegExp("^(?:".concat(sheetNameRegexp, ")?([$])?([A-Za-z]*)([$])?([0-9]*)$"));
75
-
76
- /**
77
- * Extract cell coordinates.
78
- *
79
- * @param {String} label Cell coordinates (eq. 'A1', '$B6', '$N$98').
80
- * @returns {Array} Returns an array of objects.
81
- */
82
- export function extractLabel(label) {
83
- if (typeof label !== "string" || !LABEL_EXTRACT_REGEXP.test(label)) {
84
- return [];
85
- }
86
- var _label$toUpperCase$ma = label.toUpperCase().match(LABEL_EXTRACT_REGEXP),
87
- _label$toUpperCase$ma2 = _slicedToArray(_label$toUpperCase$ma, 6),
88
- sheetNameStr = _label$toUpperCase$ma2[1],
89
- columnAbs = _label$toUpperCase$ma2[2],
90
- column = _label$toUpperCase$ma2[3],
91
- rowAbs = _label$toUpperCase$ma2[4],
92
- row = _label$toUpperCase$ma2[5];
93
- if (column == null && row == null) return [];
94
- var sheetName = sheetNameStr == null ? null : label.slice(0, sheetNameStr.length).replace(/^'|'$/g, "").replace(/''/g, "'");
95
- return [{
96
- index: rowLabelToIndex(row),
97
- label: row,
98
- isAbsolute: rowAbs === "$"
99
- }, {
100
- index: columnLabelToIndex(column),
101
- label: column,
102
- isAbsolute: columnAbs === "$"
103
- }, sheetName];
104
- }
105
-
106
- /**
107
- * Convert row and column indexes into cell label.
108
- *
109
- * @param {Object} row Object with `index` and `isAbsolute` properties.
110
- * @param {Object} column Object with `index` and `isAbsolute` properties.
111
- * @returns {String} Returns cell label.
112
- */
113
- export function toLabel(row, column) {
114
- var rowLabel = (row.isAbsolute ? "$" : "") + rowIndexToLabel(row.index);
115
- var columnLabel = (column.isAbsolute ? "$" : "") + columnIndexToLabel(column.index);
116
- return columnLabel + rowLabel;
117
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Convert value into number.
3
- *
4
- * @param {String|Number} number
5
- * @returns {*}
6
- */
7
- export function toNumber(number) {
8
- var result;
9
- if (typeof number === "number") {
10
- result = number;
11
- } else if (typeof number === "string") {
12
- result = number.indexOf(".") > -1 ? parseFloat(number) : parseInt(number, 10);
13
- }
14
- return result;
15
- }
16
-
17
- /**
18
- * Invert provided number.
19
- *
20
- * @param {Number} number
21
- * @returns {Number} Returns inverted number.
22
- */
23
- export function invertNumber(number) {
24
- return -1 * toNumber(number);
25
- }
@@ -1,13 +0,0 @@
1
- /* eslint-disable import/prefer-default-export */
2
- /**
3
- * Trim value by cutting character starting from the beginning and ending at the same time.
4
- *
5
- * @param {String} string String to trimming.
6
- * @param {Number} [margin=1] Number of character to cut.
7
- * @returns {String}
8
- */
9
- export function trimEdges(string) {
10
- var margin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
11
- string = string.substring(margin, string.length - margin);
12
- return string;
13
- }
package/es/index.js DELETED
@@ -1,5 +0,0 @@
1
- import Parser from "./parser";
2
- import SUPPORTED_FORMULAS from "./supported-formulas";
3
- import error, { ERROR, ERROR_DIV_ZERO, ERROR_NAME, ERROR_NOT_AVAILABLE, ERROR_NULL, ERROR_NUM, ERROR_REF, ERROR_VALUE } from "./error";
4
- import { extractLabel, toLabel, columnIndexToLabel, columnLabelToIndex, rowIndexToLabel, rowLabelToIndex } from "./helper/cell";
5
- export { SUPPORTED_FORMULAS, ERROR, ERROR_DIV_ZERO, ERROR_NAME, ERROR_NOT_AVAILABLE, ERROR_NULL, ERROR_NUM, ERROR_REF, ERROR_VALUE, Parser, error, extractLabel, toLabel, columnIndexToLabel, columnLabelToIndex, rowIndexToLabel, rowLabelToIndex };
package/es/parser.js DELETED
@@ -1,318 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
6
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
8
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
9
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
10
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
11
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
14
- function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
15
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
16
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
17
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
18
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
19
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
20
- import Emitter from "tiny-emitter";
21
- import evaluateByOperator from "./evaluate-by-operator/evaluate-by-operator";
22
- import { Parser as GrammarParser } from "./grammar-parser/grammar-parser";
23
- import { trimEdges } from "./helper/string";
24
- import { toNumber, invertNumber } from "./helper/number";
25
- import errorParser, { isValidStrict as isErrorValid, ERROR, ERROR_NAME, ERROR_VALUE } from "./error";
26
- import { extractLabel, toLabel } from "./helper/cell";
27
- function normalizeQuotes(text) {
28
- return text.replace(/[\u201C\u201D]/g, '"').replace(/[\u2018\u2019]/g, "'");
29
- }
30
-
31
- /**
32
- * @class Parser
33
- */
34
- var Parser = /*#__PURE__*/function (_Emitter) {
35
- function Parser() {
36
- var _this;
37
- _classCallCheck(this, Parser);
38
- _this = _callSuper(this, Parser);
39
- _this.parser = new GrammarParser();
40
- _this.cryptoDenomination = "";
41
- _this.cryptoDecimals = 0;
42
- _this.parser.yy = {
43
- toNumber: toNumber,
44
- trimEdges: trimEdges,
45
- invertNumber: invertNumber,
46
- throwError: function throwError(errorName) {
47
- return _this._throwError(errorName);
48
- },
49
- callVariable: function callVariable(variable) {
50
- return _this._callVariable(variable);
51
- },
52
- evaluateByOperator: evaluateByOperator,
53
- callFunction: function callFunction(name, params) {
54
- return _this._callFunction(name, params);
55
- },
56
- cellValue: function cellValue(value) {
57
- return _this._callCellValue(value);
58
- },
59
- rangeValue: function rangeValue(start, end) {
60
- return _this._callRangeValue(start, end);
61
- }
62
- };
63
- _this.variables = Object.create(null);
64
- _this.functions = Object.create(null);
65
- _this.options = Object.create(null);
66
- _this.setVariable("TRUE", true).setVariable("FALSE", false).setVariable("NULL", null);
67
- return _this;
68
- }
69
-
70
- /**
71
- * Parse formula expression.
72
- *
73
- * @param {string} expression to parse.
74
- * @param {object} options additional params.
75
- * @param {string} options.sheetId id of sheet which the formula expression belongs to.
76
- * @return {*} Returns an object with tow properties `error` and `result`.
77
- */
78
- _inherits(Parser, _Emitter);
79
- return _createClass(Parser, [{
80
- key: "parse",
81
- value: function parse(expression, options) {
82
- //return
83
- expression = normalizeQuotes(expression);
84
- var result = null;
85
- var error = null;
86
- this.options = options;
87
- try {
88
- if (expression === "") {
89
- result = "";
90
- } else {
91
- result = this.parser.parse(expression);
92
- }
93
- } catch (ex) {
94
- var message = errorParser(ex.message);
95
- if (message) {
96
- error = message;
97
- } else {
98
- error = errorParser(ERROR);
99
- }
100
- }
101
- if (result instanceof Error) {
102
- error = errorParser(result.message) || errorParser(ERROR);
103
- result = null;
104
- }
105
- return {
106
- error: error,
107
- result: result
108
- };
109
- }
110
-
111
- /**
112
- * Set predefined variable name which can be visible while parsing formula expression.
113
- *
114
- * @param {String} name Variable name.
115
- * @param {*} value Variable value.
116
- * @returns {Parser}
117
- */
118
- }, {
119
- key: "setVariable",
120
- value: function setVariable(name, value) {
121
- this.variables[name] = value;
122
- return this;
123
- }
124
-
125
- /**
126
- * Get variable name.
127
- *
128
- * @param {String} name Variable name.
129
- * @returns {*}
130
- */
131
- }, {
132
- key: "getVariable",
133
- value: function getVariable(name) {
134
- return this.variables[name];
135
- }
136
-
137
- /**
138
- * Retrieve variable value by its name.
139
- *
140
- * @param name Variable name.
141
- * @returns {*}
142
- * @private
143
- */
144
- }, {
145
- key: "_callVariable",
146
- value: function _callVariable(name) {
147
- var value = this.getVariable(name);
148
- this.emit("callVariable", name, function (newValue) {
149
- if (newValue !== void 0) {
150
- value = newValue;
151
- }
152
- });
153
- if (value === void 0) {
154
- throw Error(ERROR_NAME);
155
- }
156
- return value;
157
- }
158
-
159
- /**
160
- * Set custom function which can be visible while parsing formula expression.
161
- *
162
- * @param {String} name Custom function name.
163
- * @param {Function} fn Custom function.
164
- * @returns {Parser}
165
- */
166
- }, {
167
- key: "setFunction",
168
- value: function setFunction(name, fn) {
169
- this.functions[name] = fn;
170
- return this;
171
- }
172
-
173
- /**
174
- * Get custom function.
175
- *
176
- * @param {String} name Custom function name.
177
- * @returns {*}
178
- */
179
- }, {
180
- key: "getFunction",
181
- value: function getFunction(name) {
182
- return this.functions[name];
183
- }
184
-
185
- /**
186
- * Call function with provided params.
187
- *
188
- * @param name Function name.
189
- * @param params Function params.
190
- * @returns {*}
191
- * @private
192
- */
193
- }, {
194
- key: "_callFunction",
195
- value: function _callFunction(name) {
196
- var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
197
- var fn = this.getFunction(name);
198
- var value;
199
- if (fn) {
200
- value = fn(params);
201
- }
202
- this.emit("callFunction", name, params, function (newValue) {
203
- if (newValue !== void 0) {
204
- value = newValue;
205
- }
206
- });
207
- return value === void 0 ? evaluateByOperator(name, params) : value;
208
- }
209
-
210
- /**
211
- * Retrieve value by its label (`B3`, `B$3`, `B$3`, `$B$3`).
212
- *
213
- * @param {String} label Coordinates.
214
- * @returns {*}
215
- * @private
216
- */
217
- }, {
218
- key: "_callCellValue",
219
- value: function _callCellValue(label) {
220
- var _extractLabel = extractLabel(label),
221
- _extractLabel2 = _slicedToArray(_extractLabel, 3),
222
- row = _extractLabel2[0],
223
- column = _extractLabel2[1],
224
- sheetName = _extractLabel2[2];
225
- if ((column === null || column === void 0 ? void 0 : column.index) === -1) {
226
- if (row.isAbsolute || column.isAbsolute) {
227
- throw Error(ERROR_NAME);
228
- }
229
- return row.index + 1;
230
- } else if ((row === null || row === void 0 ? void 0 : row.index) === -1) {
231
- throw Error(ERROR_NAME);
232
- }
233
- var value = void 0;
234
- this.emit("callCellValue", {
235
- label: label,
236
- row: row,
237
- column: column,
238
- sheetName: sheetName
239
- }, this.options, function (_value) {
240
- value = _value;
241
- });
242
- return value;
243
- }
244
-
245
- /**
246
- * Retrieve value by its label (`B3:A1`, `B$3:A1`, `B$3:$A1`, `$B$3:A$1`).
247
- *
248
- * @param {String} startLabel Coordinates of the first cell.
249
- * @param {String} endLabel Coordinates of the last cell.
250
- * @returns {Array} Returns an array of mixed values.
251
- * @private
252
- */
253
- }, {
254
- key: "_callRangeValue",
255
- value: function _callRangeValue(startLabel, endLabel) {
256
- var _this2 = this;
257
- var _extractLabel3 = extractLabel(startLabel),
258
- _extractLabel4 = _slicedToArray(_extractLabel3, 3),
259
- startRow = _extractLabel4[0],
260
- startColumn = _extractLabel4[1],
261
- startSheetName = _extractLabel4[2];
262
- var _extractLabel5 = extractLabel(endLabel),
263
- _extractLabel6 = _slicedToArray(_extractLabel5, 3),
264
- endRow = _extractLabel6[0],
265
- endColumn = _extractLabel6[1],
266
- endSheetName = _extractLabel6[2];
267
- if (endSheetName != null && startSheetName != endSheetName) {
268
- throw Error(ERROR_VALUE);
269
- }
270
- var startCell = {};
271
- var endCell = {};
272
- startCell.sheetName = startSheetName;
273
- if (startRow.index <= endRow.index) {
274
- startCell.row = startRow;
275
- endCell.row = endRow;
276
- } else {
277
- startCell.row = endRow;
278
- endCell.row = startRow;
279
- }
280
- if (startColumn.index <= endColumn.index) {
281
- startCell.column = startColumn;
282
- endCell.column = endColumn;
283
- } else {
284
- startCell.column = endColumn;
285
- endCell.column = startColumn;
286
- }
287
- startCell.label = toLabel(startCell.row, startCell.column);
288
- endCell.label = toLabel(endCell.row, endCell.column);
289
- var value = [];
290
- this.emit("callRangeValue", startCell, endCell, this.options, function () {
291
- var _value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
292
- var _cryptoDenomination = arguments.length > 1 ? arguments[1] : undefined;
293
- var _cryptoDecimals = arguments.length > 2 ? arguments[2] : undefined;
294
- value = _value;
295
- _this2.cryptoDenomination = _cryptoDenomination;
296
- _this2.cryptoDecimals = _cryptoDecimals;
297
- });
298
- return value;
299
- }
300
-
301
- /**
302
- * Try to throw error by its name.
303
- *
304
- * @param {String} errorName Error name.
305
- * @returns {String}
306
- * @private
307
- */
308
- }, {
309
- key: "_throwError",
310
- value: function _throwError(errorName) {
311
- if (isErrorValid(errorName)) {
312
- throw Error(errorName);
313
- }
314
- throw Error(ERROR);
315
- }
316
- }]);
317
- }(Emitter);
318
- export default Parser;
@@ -1,3 +0,0 @@
1
- import * as formulajs from "@fileverse-dev/formulajs";
2
- var SUPPORTED_FORMULAS = Object.keys(formulajs);
3
- export default SUPPORTED_FORMULAS;
package/lib/error.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ERROR_VALUE = exports.ERROR_REF = exports.ERROR_NUM = exports.ERROR_NULL = exports.ERROR_NOT_AVAILABLE = exports.ERROR_NAME = exports.ERROR_DIV_ZERO = exports.ERROR = void 0;
7
- exports["default"] = error;
8
- exports.isValidStrict = isValidStrict;
9
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
11
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- var ERROR = exports.ERROR = "ERROR";
14
- var ERROR_DIV_ZERO = exports.ERROR_DIV_ZERO = "DIV/0";
15
- var ERROR_NAME = exports.ERROR_NAME = "NAME";
16
- var ERROR_NOT_AVAILABLE = exports.ERROR_NOT_AVAILABLE = "N/A";
17
- var ERROR_NULL = exports.ERROR_NULL = "NULL";
18
- var ERROR_NUM = exports.ERROR_NUM = "NUM";
19
- var ERROR_REF = exports.ERROR_REF = "REF";
20
- var ERROR_VALUE = exports.ERROR_VALUE = "VALUE";
21
- var errors = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ERROR, "Syntax error"), ERROR_DIV_ZERO, "#DIV/0!"), ERROR_NAME, "Wrong function name or parameter"), ERROR_NOT_AVAILABLE, "#N/A"), ERROR_NULL, "#NULL!"), ERROR_NUM, "#NUM!"), ERROR_REF, "#REF!"), ERROR_VALUE, "#VALUE!");
22
-
23
- /**
24
- * Return error type based on provided error id.
25
- *
26
- * @param {String} type Error type.
27
- * @returns {String|null} Returns error id.
28
- */
29
- function error(type) {
30
- var result;
31
- type = (type + "").replace(/#|!|\?/g, "");
32
- if (errors[type]) {
33
- result = errors[type];
34
- }
35
- return result ? result : null;
36
- }
37
-
38
- /**
39
- * Check if error type is strict valid with knows errors.
40
- *
41
- * @param {String} Error type.
42
- * @return {Boolean}
43
- */
44
- function isValidStrict(type) {
45
- var valid = false;
46
- for (var i in errors) {
47
- if (Object.prototype.hasOwnProperty.call(errors, i) && errors[i] === type) {
48
- valid = true;
49
- break;
50
- }
51
- }
52
- return valid;
53
- }
@@ -1,77 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = evaluateByOperator;
7
- exports.registerOperation = registerOperation;
8
- var _add = _interopRequireDefault(require("./operator/add"));
9
- var _ampersand = _interopRequireDefault(require("./operator/ampersand"));
10
- var _divide = _interopRequireDefault(require("./operator/divide"));
11
- var _equal = _interopRequireDefault(require("./operator/equal"));
12
- var _formulaFunction = _interopRequireDefault(require("./operator/formula-function"));
13
- var _greaterThan = _interopRequireDefault(require("./operator/greater-than"));
14
- var _greaterThanOrEqual = _interopRequireDefault(require("./operator/greater-than-or-equal"));
15
- var _lessThan = _interopRequireDefault(require("./operator/less-than"));
16
- var _lessThanOrEqual = _interopRequireDefault(require("./operator/less-than-or-equal"));
17
- var _minus = _interopRequireDefault(require("./operator/minus"));
18
- var _multiply = _interopRequireDefault(require("./operator/multiply"));
19
- var _notEqual = _interopRequireDefault(require("./operator/not-equal"));
20
- var _power = _interopRequireDefault(require("./operator/power"));
21
- var _error = require("./../error");
22
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
23
- function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
24
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
25
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
26
- function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
27
- function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
28
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } /* eslint-disable import/no-named-as-default-member */
29
- var availableOperators = Object.create(null);
30
-
31
- /**
32
- * Evaluate values by operator id.git
33
- *
34
- * @param {String} operator Operator id.
35
- * @param {Array} [params=[]] Arguments to evaluate.
36
- * @returns {*}
37
- */
38
- function evaluateByOperator(operator) {
39
- var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
40
- operator = operator.toUpperCase();
41
- if (!availableOperators[operator]) {
42
- throw Error(_error.ERROR_NAME);
43
- }
44
- return availableOperators[operator].apply(availableOperators, _toConsumableArray(params));
45
- }
46
-
47
- /**
48
- * Register operator.
49
- *
50
- * @param {String|Array} symbol Symbol to register.
51
- * @param {Function} func Logic to register for this symbol.
52
- */
53
- function registerOperation(symbol, func) {
54
- if (!Array.isArray(symbol)) {
55
- symbol = [symbol.toUpperCase()];
56
- }
57
- symbol.forEach(function (s) {
58
- if (func.isFactory) {
59
- availableOperators[s] = func(s);
60
- } else {
61
- availableOperators[s] = func;
62
- }
63
- });
64
- }
65
- registerOperation(_add["default"].SYMBOL, _add["default"]);
66
- registerOperation(_ampersand["default"].SYMBOL, _ampersand["default"]);
67
- registerOperation(_divide["default"].SYMBOL, _divide["default"]);
68
- registerOperation(_equal["default"].SYMBOL, _equal["default"]);
69
- registerOperation(_power["default"].SYMBOL, _power["default"]);
70
- registerOperation(_formulaFunction["default"].SYMBOL, _formulaFunction["default"]);
71
- registerOperation(_greaterThan["default"].SYMBOL, _greaterThan["default"]);
72
- registerOperation(_greaterThanOrEqual["default"].SYMBOL, _greaterThanOrEqual["default"]);
73
- registerOperation(_lessThan["default"].SYMBOL, _lessThan["default"]);
74
- registerOperation(_lessThanOrEqual["default"].SYMBOL, _lessThanOrEqual["default"]);
75
- registerOperation(_multiply["default"].SYMBOL, _multiply["default"]);
76
- registerOperation(_notEqual["default"].SYMBOL, _notEqual["default"]);
77
- registerOperation(_minus["default"].SYMBOL, _minus["default"]);
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SYMBOL = void 0;
7
- exports["default"] = func;
8
- var _number = require("./../../helper/number");
9
- var _error = require("./../../error");
10
- var SYMBOL = exports.SYMBOL = "+";
11
- function func(first) {
12
- for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
13
- rest[_key - 1] = arguments[_key];
14
- }
15
- var result = rest.reduce(function (acc, value) {
16
- return acc + (0, _number.toNumber)(value || 0);
17
- }, (0, _number.toNumber)(first || 0));
18
- if (isNaN(result)) {
19
- throw Error(_error.ERROR_VALUE);
20
- }
21
- return result;
22
- }
23
- func.SYMBOL = SYMBOL;
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SYMBOL = void 0;
7
- exports["default"] = func;
8
- var SYMBOL = exports.SYMBOL = "&";
9
- function func() {
10
- for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
11
- params[_key] = arguments[_key];
12
- }
13
- return params.reduce(function (acc, value) {
14
- return acc + value.toString();
15
- }, "");
16
- }
17
- func.SYMBOL = SYMBOL;