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