@leankylin-sheet/formula-parser 3.1.28 → 3.1.30

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 (204) hide show
  1. package/{lib/grammar-parser/grammar-parser.js → dist/index.esm.js} +856 -46
  2. package/{es/grammar-parser/grammar-parser.js → dist/index.js} +903 -42
  3. package/dist/packages/core/src/api/cell.d.ts +10 -0
  4. package/dist/packages/core/src/api/common.d.ts +57 -0
  5. package/dist/packages/core/src/api/errors.d.ts +2 -0
  6. package/dist/packages/core/src/api/index.d.ts +9 -0
  7. package/dist/packages/core/src/api/merge.d.ts +5 -0
  8. package/dist/packages/core/src/api/range.d.ts +22 -0
  9. package/dist/packages/core/src/api/rowcol.d.ts +14 -0
  10. package/dist/packages/core/src/api/sheet.d.ts +10 -0
  11. package/dist/packages/core/src/api/workbook.d.ts +15 -0
  12. package/dist/packages/core/src/canvas.d.ts +56 -0
  13. package/dist/packages/core/src/context.d.ts +193 -0
  14. package/dist/packages/core/src/events/copy.d.ts +2 -0
  15. package/dist/packages/core/src/events/index.d.ts +4 -0
  16. package/dist/packages/core/src/events/keyboard.d.ts +6 -0
  17. package/dist/packages/core/src/events/mouse.d.ts +25 -0
  18. package/dist/packages/core/src/events/paste.d.ts +5 -0
  19. package/dist/packages/core/src/index.d.ts +10 -0
  20. package/dist/packages/core/src/locale/en.d.ts +1028 -0
  21. package/dist/packages/core/src/locale/es.d.ts +1132 -0
  22. package/dist/packages/core/src/locale/index.d.ts +1046 -0
  23. package/dist/packages/core/src/locale/zh.d.ts +1045 -0
  24. package/dist/packages/core/src/locale/zh_tw.d.ts +1185 -0
  25. package/dist/packages/core/src/modules/ConditionFormat.d.ts +17 -0
  26. package/dist/packages/core/src/modules/border.d.ts +3 -0
  27. package/dist/packages/core/src/modules/cell.d.ts +32 -0
  28. package/dist/packages/core/src/modules/clipboard.d.ts +3 -0
  29. package/dist/packages/core/src/modules/color.d.ts +1 -0
  30. package/dist/packages/core/src/modules/comment.d.ts +96 -0
  31. package/dist/packages/core/src/modules/conditionalFormat.d.ts +2 -0
  32. package/dist/packages/core/src/modules/cursor.d.ts +3 -0
  33. package/dist/packages/core/src/modules/dataVerification.d.ts +11 -0
  34. package/dist/packages/core/src/modules/dropCell.d.ts +10 -0
  35. package/dist/packages/core/src/modules/filter.d.ts +45 -0
  36. package/dist/packages/core/src/modules/format.d.ts +6 -0
  37. package/dist/packages/core/src/modules/formula.d.ts +53 -0
  38. package/dist/packages/core/src/modules/freeze.d.ts +5 -0
  39. package/dist/packages/core/src/modules/hyperlink.d.ts +21 -0
  40. package/dist/packages/core/src/modules/image.d.ts +31 -0
  41. package/dist/packages/core/src/modules/index.d.ts +35 -0
  42. package/dist/packages/core/src/modules/inline-string.d.ts +36 -0
  43. package/dist/packages/core/src/modules/location.d.ts +6 -0
  44. package/dist/packages/core/src/modules/locationCondition.d.ts +21 -0
  45. package/dist/packages/core/src/modules/merge.d.ts +3 -0
  46. package/dist/packages/core/src/modules/mobile.d.ts +5 -0
  47. package/dist/packages/core/src/modules/moveCells.d.ts +5 -0
  48. package/dist/packages/core/src/modules/protection.d.ts +5 -0
  49. package/dist/packages/core/src/modules/refresh.d.ts +3 -0
  50. package/dist/packages/core/src/modules/rowcol.d.ts +19 -0
  51. package/dist/packages/core/src/modules/screenshot.d.ts +2 -0
  52. package/dist/packages/core/src/modules/searchReplace.d.ts +36 -0
  53. package/dist/packages/core/src/modules/selection.d.ts +47 -0
  54. package/dist/packages/core/src/modules/sheet.d.ts +10 -0
  55. package/dist/packages/core/src/modules/sort.d.ts +7 -0
  56. package/dist/packages/core/src/modules/splitColumn.d.ts +5 -0
  57. package/dist/packages/core/src/modules/ssf.d.ts +2 -0
  58. package/dist/packages/core/src/modules/text.d.ts +10 -0
  59. package/dist/packages/core/src/modules/toolbar.d.ts +32 -0
  60. package/dist/packages/core/src/modules/validation.d.ts +19 -0
  61. package/dist/packages/core/src/modules/zoom.d.ts +3 -0
  62. package/dist/packages/core/src/settings.d.ts +132 -0
  63. package/dist/packages/core/src/types.d.ts +351 -0
  64. package/dist/packages/core/src/utils/index.d.ts +17 -0
  65. package/dist/packages/core/src/utils/patch.d.ts +37 -0
  66. package/dist/packages/formula-parser/src/error.d.ts +10 -0
  67. package/dist/packages/formula-parser/src/evaluate-by-operator/evaluate-by-operator.d.ts +2 -0
  68. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/add.d.ts +6 -0
  69. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/ampersand.d.ts +6 -0
  70. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/divide.d.ts +6 -0
  71. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/equal.d.ts +6 -0
  72. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/formula-function.d.ts +7 -0
  73. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/greater-than-or-equal.d.ts +6 -0
  74. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/greater-than.d.ts +6 -0
  75. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/less-than-or-equal.d.ts +6 -0
  76. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/less-than.d.ts +6 -0
  77. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/minus.d.ts +6 -0
  78. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/multiply.d.ts +6 -0
  79. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/not-equal.d.ts +6 -0
  80. package/dist/packages/formula-parser/src/evaluate-by-operator/operator/power.d.ts +6 -0
  81. package/dist/packages/formula-parser/src/grammar-parser/grammar-parser.d.ts +4 -0
  82. package/dist/packages/formula-parser/src/helper/cell.d.ts +6 -0
  83. package/dist/packages/formula-parser/src/helper/number.d.ts +2 -0
  84. package/dist/packages/formula-parser/src/helper/string.d.ts +1 -0
  85. package/{es/index.js → dist/packages/formula-parser/src/index.d.ts} +5 -5
  86. package/dist/packages/formula-parser/src/parser.d.ts +20 -0
  87. package/dist/packages/formula-parser/src/supported-formulas.d.ts +2 -0
  88. package/dist/packages/react/src/components/CellOptions/index.d.ts +4 -0
  89. package/dist/packages/react/src/components/ChangeColor/index.d.ts +7 -0
  90. package/dist/packages/react/src/components/ConditionFormat/ConditionRules.d.ts +6 -0
  91. package/dist/packages/react/src/components/ConditionFormat/index.d.ts +7 -0
  92. package/dist/packages/react/src/components/ContextMenu/Divider.d.ts +3 -0
  93. package/dist/packages/react/src/components/ContextMenu/FilterMenu.d.ts +3 -0
  94. package/dist/packages/react/src/components/ContextMenu/Menu.d.ts +8 -0
  95. package/dist/packages/react/src/components/ContextMenu/SheetTab.d.ts +4 -0
  96. package/dist/packages/react/src/components/ContextMenu/index.d.ts +4 -0
  97. package/dist/packages/react/src/components/CustomSort/index.d.ts +4 -0
  98. package/dist/packages/react/src/components/DataVerification/DropdownList.d.ts +4 -0
  99. package/dist/packages/react/src/components/DataVerification/RangeDialog.d.ts +4 -0
  100. package/dist/packages/react/src/components/DataVerification/index.d.ts +4 -0
  101. package/dist/packages/react/src/components/Dialog/index.d.ts +12 -0
  102. package/dist/packages/react/src/components/FilterOption/index.d.ts +5 -0
  103. package/dist/packages/react/src/components/FormatSearch/index.d.ts +6 -0
  104. package/dist/packages/react/src/components/FormulaSearch/index.d.ts +5 -0
  105. package/dist/packages/react/src/components/FxEditor/CalcInfo.d.ts +3 -0
  106. package/dist/packages/react/src/components/FxEditor/NameBox.d.ts +3 -0
  107. package/dist/packages/react/src/components/FxEditor/index.d.ts +4 -0
  108. package/dist/packages/react/src/components/ImgBoxs/index.d.ts +3 -0
  109. package/dist/packages/react/src/components/LinkEidtCard/index.d.ts +5 -0
  110. package/dist/packages/react/src/components/LocationCondition/index.d.ts +3 -0
  111. package/dist/packages/react/src/components/MessageBox/index.d.ts +9 -0
  112. package/dist/packages/react/src/components/NotationBoxes/index.d.ts +3 -0
  113. package/dist/packages/react/src/components/SVGDefines.d.ts +3 -0
  114. package/dist/packages/react/src/components/SVGIcon.d.ts +9 -0
  115. package/dist/packages/react/src/components/SearchReplace/index.d.ts +4 -0
  116. package/dist/packages/react/src/components/Sheet/index.d.ts +8 -0
  117. package/dist/packages/react/src/components/SheetList/SheetHiddenButton.d.ts +8 -0
  118. package/dist/packages/react/src/components/SheetList/SheetListItem.d.ts +9 -0
  119. package/dist/packages/react/src/components/SheetList/index.d.ts +4 -0
  120. package/dist/packages/react/src/components/SheetOverlay/ColumnHeader.d.ts +3 -0
  121. package/dist/packages/react/src/components/SheetOverlay/ContentEditable.d.ts +11 -0
  122. package/dist/packages/react/src/components/SheetOverlay/FormulaHint/index.d.ts +4 -0
  123. package/dist/packages/react/src/components/SheetOverlay/FormulaSearch/index.d.ts +4 -0
  124. package/dist/packages/react/src/components/SheetOverlay/InputBox.d.ts +3 -0
  125. package/dist/packages/react/src/components/SheetOverlay/RowHeader.d.ts +3 -0
  126. package/dist/packages/react/src/components/SheetOverlay/ScrollBar/index.d.ts +7 -0
  127. package/dist/packages/react/src/components/SheetOverlay/index.d.ts +4 -0
  128. package/dist/packages/react/src/components/SheetTab/SheetItem.d.ts +8 -0
  129. package/dist/packages/react/src/components/SheetTab/index.d.ts +4 -0
  130. package/dist/packages/react/src/components/SplitColumn/index.d.ts +3 -0
  131. package/dist/packages/react/src/components/Toolbar/Button.d.ts +11 -0
  132. package/dist/packages/react/src/components/Toolbar/ColorPicker.d.ts +6 -0
  133. package/dist/packages/react/src/components/Toolbar/Combo.d.ts +10 -0
  134. package/dist/packages/react/src/components/Toolbar/CustomBorder.d.ts +7 -0
  135. package/dist/packages/react/src/components/Toolbar/CustomButton.d.ts +11 -0
  136. package/dist/packages/react/src/components/Toolbar/CustomColor.d.ts +8 -0
  137. package/dist/packages/react/src/components/Toolbar/CustomIcon.d.ts +9 -0
  138. package/dist/packages/react/src/components/Toolbar/Divider.d.ts +4 -0
  139. package/dist/packages/react/src/components/Toolbar/MoreItemsContainer.d.ts +6 -0
  140. package/dist/packages/react/src/components/Toolbar/Select.d.ts +14 -0
  141. package/dist/packages/react/src/components/Toolbar/index.d.ts +7 -0
  142. package/dist/packages/react/src/components/Workbook/api.d.ts +121 -0
  143. package/dist/packages/react/src/components/Workbook/index.d.ts +130 -0
  144. package/dist/packages/react/src/components/ZoomControl/index.d.ts +4 -0
  145. package/dist/packages/react/src/components/index.d.ts +3 -0
  146. package/dist/packages/react/src/context/index.d.ts +25 -0
  147. package/dist/packages/react/src/context/modal.d.ts +10 -0
  148. package/dist/packages/react/src/hooks/useAlert.d.ts +4 -0
  149. package/dist/packages/react/src/hooks/useDialog.d.ts +5 -0
  150. package/dist/packages/react/src/hooks/useOutsideClick.d.ts +2 -0
  151. package/dist/packages/react/src/hooks/usePrevious.d.ts +2 -0
  152. package/dist/packages/react/src/index.d.ts +1 -0
  153. package/dist/stories/data/cell.d.ts +1180 -0
  154. package/dist/stories/data/dataVerification.d.ts +131 -0
  155. package/dist/stories/data/empty.d.ts +10 -0
  156. package/dist/stories/data/formula.d.ts +362 -0
  157. package/dist/stories/data/freeze.d.ts +34 -0
  158. package/dist/stories/data/protected.d.ts +40 -0
  159. package/dist/stories/utils.d.ts +1 -0
  160. package/package.json +6 -18
  161. package/LICENSE +0 -21
  162. package/es/error.js +0 -45
  163. package/es/evaluate-by-operator/evaluate-by-operator.js +0 -70
  164. package/es/evaluate-by-operator/operator/add.js +0 -16
  165. package/es/evaluate-by-operator/operator/ampersand.js +0 -10
  166. package/es/evaluate-by-operator/operator/divide.js +0 -21
  167. package/es/evaluate-by-operator/operator/equal.js +0 -5
  168. package/es/evaluate-by-operator/operator/formula-function.js +0 -40
  169. package/es/evaluate-by-operator/operator/greater-than-or-equal.js +0 -5
  170. package/es/evaluate-by-operator/operator/greater-than.js +0 -5
  171. package/es/evaluate-by-operator/operator/less-than-or-equal.js +0 -5
  172. package/es/evaluate-by-operator/operator/less-than.js +0 -5
  173. package/es/evaluate-by-operator/operator/minus.js +0 -16
  174. package/es/evaluate-by-operator/operator/multiply.js +0 -16
  175. package/es/evaluate-by-operator/operator/not-equal.js +0 -5
  176. package/es/evaluate-by-operator/operator/power.js +0 -11
  177. package/es/grammar-parser/grammar-parser.jison +0 -230
  178. package/es/helper/cell.js +0 -117
  179. package/es/helper/number.js +0 -25
  180. package/es/helper/string.js +0 -13
  181. package/es/parser.js +0 -306
  182. package/es/supported-formulas.js +0 -3
  183. package/lib/error.js +0 -53
  184. package/lib/evaluate-by-operator/evaluate-by-operator.js +0 -77
  185. package/lib/evaluate-by-operator/operator/add.js +0 -23
  186. package/lib/evaluate-by-operator/operator/ampersand.js +0 -17
  187. package/lib/evaluate-by-operator/operator/divide.js +0 -28
  188. package/lib/evaluate-by-operator/operator/equal.js +0 -12
  189. package/lib/evaluate-by-operator/operator/formula-function.js +0 -51
  190. package/lib/evaluate-by-operator/operator/greater-than-or-equal.js +0 -12
  191. package/lib/evaluate-by-operator/operator/greater-than.js +0 -12
  192. package/lib/evaluate-by-operator/operator/less-than-or-equal.js +0 -12
  193. package/lib/evaluate-by-operator/operator/less-than.js +0 -12
  194. package/lib/evaluate-by-operator/operator/minus.js +0 -23
  195. package/lib/evaluate-by-operator/operator/multiply.js +0 -23
  196. package/lib/evaluate-by-operator/operator/not-equal.js +0 -12
  197. package/lib/evaluate-by-operator/operator/power.js +0 -18
  198. package/lib/grammar-parser/grammar-parser.jison +0 -230
  199. package/lib/helper/cell.js +0 -128
  200. package/lib/helper/number.js +0 -32
  201. package/lib/helper/string.js +0 -19
  202. package/lib/index.js +0 -115
  203. package/lib/parser.js +0 -314
  204. package/lib/supported-formulas.js +0 -12
@@ -1,9 +1,452 @@
1
- "use strict";
1
+ import Emitter from 'tiny-emitter';
2
+ import * as formulajs from '@formulajs/formulajs';
3
+
4
+ function _callSuper(t, o, e) {
5
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
6
+ }
7
+ function _isNativeReflectConstruct() {
8
+ try {
9
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
10
+ } catch (t) {}
11
+ return (_isNativeReflectConstruct = function () {
12
+ return !!t;
13
+ })();
14
+ }
15
+ function _iterableToArrayLimit(r, l) {
16
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
17
+ if (null != t) {
18
+ var e,
19
+ n,
20
+ i,
21
+ u,
22
+ a = [],
23
+ f = !0,
24
+ o = !1;
25
+ try {
26
+ if (i = (t = t.call(r)).next, 0 === l) {
27
+ if (Object(t) !== t) return;
28
+ f = !1;
29
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
30
+ } catch (r) {
31
+ o = !0, n = r;
32
+ } finally {
33
+ try {
34
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
35
+ } finally {
36
+ if (o) throw n;
37
+ }
38
+ }
39
+ return a;
40
+ }
41
+ }
42
+ function _toPrimitive(t, r) {
43
+ if ("object" != typeof t || !t) return t;
44
+ var e = t[Symbol.toPrimitive];
45
+ if (void 0 !== e) {
46
+ var i = e.call(t, r || "default");
47
+ if ("object" != typeof i) return i;
48
+ throw new TypeError("@@toPrimitive must return a primitive value.");
49
+ }
50
+ return ("string" === r ? String : Number)(t);
51
+ }
52
+ function _toPropertyKey(t) {
53
+ var i = _toPrimitive(t, "string");
54
+ return "symbol" == typeof i ? i : i + "";
55
+ }
56
+ function _classCallCheck(instance, Constructor) {
57
+ if (!(instance instanceof Constructor)) {
58
+ throw new TypeError("Cannot call a class as a function");
59
+ }
60
+ }
61
+ function _defineProperties(target, props) {
62
+ for (var i = 0; i < props.length; i++) {
63
+ var descriptor = props[i];
64
+ descriptor.enumerable = descriptor.enumerable || false;
65
+ descriptor.configurable = true;
66
+ if ("value" in descriptor) descriptor.writable = true;
67
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
68
+ }
69
+ }
70
+ function _createClass(Constructor, protoProps, staticProps) {
71
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
72
+ if (staticProps) _defineProperties(Constructor, staticProps);
73
+ Object.defineProperty(Constructor, "prototype", {
74
+ writable: false
75
+ });
76
+ return Constructor;
77
+ }
78
+ function _defineProperty(obj, key, value) {
79
+ key = _toPropertyKey(key);
80
+ if (key in obj) {
81
+ Object.defineProperty(obj, key, {
82
+ value: value,
83
+ enumerable: true,
84
+ configurable: true,
85
+ writable: true
86
+ });
87
+ } else {
88
+ obj[key] = value;
89
+ }
90
+ return obj;
91
+ }
92
+ function _inherits(subClass, superClass) {
93
+ if (typeof superClass !== "function" && superClass !== null) {
94
+ throw new TypeError("Super expression must either be null or a function");
95
+ }
96
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
97
+ constructor: {
98
+ value: subClass,
99
+ writable: true,
100
+ configurable: true
101
+ }
102
+ });
103
+ Object.defineProperty(subClass, "prototype", {
104
+ writable: false
105
+ });
106
+ if (superClass) _setPrototypeOf(subClass, superClass);
107
+ }
108
+ function _getPrototypeOf(o) {
109
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
110
+ return o.__proto__ || Object.getPrototypeOf(o);
111
+ };
112
+ return _getPrototypeOf(o);
113
+ }
114
+ function _setPrototypeOf(o, p) {
115
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
116
+ o.__proto__ = p;
117
+ return o;
118
+ };
119
+ return _setPrototypeOf(o, p);
120
+ }
121
+ function _assertThisInitialized(self) {
122
+ if (self === void 0) {
123
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
124
+ }
125
+ return self;
126
+ }
127
+ function _possibleConstructorReturn(self, call) {
128
+ if (call && (typeof call === "object" || typeof call === "function")) {
129
+ return call;
130
+ } else if (call !== void 0) {
131
+ throw new TypeError("Derived constructors may only return object or undefined");
132
+ }
133
+ return _assertThisInitialized(self);
134
+ }
135
+ function _slicedToArray(arr, i) {
136
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
137
+ }
138
+ function _toConsumableArray(arr) {
139
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
140
+ }
141
+ function _arrayWithoutHoles(arr) {
142
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
143
+ }
144
+ function _arrayWithHoles(arr) {
145
+ if (Array.isArray(arr)) return arr;
146
+ }
147
+ function _iterableToArray(iter) {
148
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
149
+ }
150
+ function _unsupportedIterableToArray(o, minLen) {
151
+ if (!o) return;
152
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
153
+ var n = Object.prototype.toString.call(o).slice(8, -1);
154
+ if (n === "Object" && o.constructor) n = o.constructor.name;
155
+ if (n === "Map" || n === "Set") return Array.from(o);
156
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
157
+ }
158
+ function _arrayLikeToArray(arr, len) {
159
+ if (len == null || len > arr.length) len = arr.length;
160
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
161
+ return arr2;
162
+ }
163
+ function _nonIterableSpread() {
164
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
165
+ }
166
+ function _nonIterableRest() {
167
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
168
+ }
169
+
170
+ /**
171
+ * Convert value into number.
172
+ *
173
+ * @param {String|Number} number
174
+ * @returns {*}
175
+ */
176
+ function toNumber(number) {
177
+ var result;
178
+ if (typeof number === 'number') {
179
+ result = number;
180
+ } else if (typeof number === 'string') {
181
+ result = number.indexOf('.') > -1 ? parseFloat(number) : parseInt(number, 10);
182
+ }
183
+ return result;
184
+ }
185
+
186
+ /**
187
+ * Invert provided number.
188
+ *
189
+ * @param {Number} number
190
+ * @returns {Number} Returns inverted number.
191
+ */
192
+ function invertNumber(number) {
193
+ return -1 * toNumber(number);
194
+ }
195
+
196
+ var ERROR = 'ERROR';
197
+ var ERROR_DIV_ZERO = 'DIV/0';
198
+ var ERROR_NAME = 'NAME';
199
+ var ERROR_NOT_AVAILABLE = 'N/A';
200
+ var ERROR_NULL = 'NULL';
201
+ var ERROR_NUM = 'NUM';
202
+ var ERROR_REF = 'REF';
203
+ var ERROR_VALUE = 'VALUE';
204
+ 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!');
205
+
206
+ /**
207
+ * Return error type based on provided error id.
208
+ *
209
+ * @param {String} type Error type.
210
+ * @returns {String|null} Returns error id.
211
+ */
212
+ function error(type) {
213
+ var result;
214
+ type = (type + '').replace(/#|!|\?/g, '');
215
+ if (errors[type]) {
216
+ result = errors[type];
217
+ }
218
+ return result ? result : null;
219
+ }
220
+
221
+ /**
222
+ * Check if error type is strict valid with knows errors.
223
+ *
224
+ * @param {String} Error type.
225
+ * @return {Boolean}
226
+ */
227
+ function isValidStrict(type) {
228
+ var valid = false;
229
+ for (var i in errors) {
230
+ if (Object.prototype.hasOwnProperty.call(errors, i) && errors[i] === type) {
231
+ valid = true;
232
+ break;
233
+ }
234
+ }
235
+ return valid;
236
+ }
237
+
238
+ var SYMBOL = '+';
239
+ function func(first) {
240
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
241
+ rest[_key - 1] = arguments[_key];
242
+ }
243
+ var result = rest.reduce(function (acc, value) {
244
+ return acc + toNumber(value || 0);
245
+ }, toNumber(first || 0));
246
+ if (isNaN(result)) {
247
+ throw Error(ERROR_VALUE);
248
+ }
249
+ return result;
250
+ }
251
+ func.SYMBOL = SYMBOL;
252
+
253
+ var SYMBOL$1 = '&';
254
+ function func$1() {
255
+ for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
256
+ params[_key] = arguments[_key];
257
+ }
258
+ return params.reduce(function (acc, value) {
259
+ return acc + value.toString();
260
+ }, '');
261
+ }
262
+ func$1.SYMBOL = SYMBOL$1;
263
+
264
+ var SYMBOL$2 = '/';
265
+ function func$2(first) {
266
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
267
+ rest[_key - 1] = arguments[_key];
268
+ }
269
+ var result = rest.reduce(function (acc, value) {
270
+ return acc / toNumber(value);
271
+ }, toNumber(first));
272
+ if (result === Infinity) {
273
+ return ERROR_DIV_ZERO;
274
+ // throw Error(ERROR_DIV_ZERO);
275
+ }
276
+ if (isNaN(result)) {
277
+ return ERROR_VALUE;
278
+ // throw Error(ERROR_VALUE);
279
+ }
280
+ return result;
281
+ }
282
+ func$2.SYMBOL = SYMBOL$2;
283
+
284
+ var SYMBOL$3 = '=';
285
+ function func$3(exp1, exp2) {
286
+ return exp1 === exp2;
287
+ }
288
+ func$3.SYMBOL = SYMBOL$3;
289
+
290
+ var SUPPORTED_FORMULAS = Object.keys(formulajs);
291
+
292
+ var SYMBOL$4 = SUPPORTED_FORMULAS;
293
+ function func$4(symbol) {
294
+ return function __formulaFunction() {
295
+ symbol = symbol.toUpperCase();
296
+ var symbolParts = symbol.split('.');
297
+ var foundFormula = false;
298
+ var result;
299
+ if (symbolParts.length === 1) {
300
+ if (formulajs[symbolParts[0]]) {
301
+ foundFormula = true;
302
+ result = formulajs[symbolParts[0]].apply(formulajs, arguments);
303
+ }
304
+ } else {
305
+ var length = symbolParts.length;
306
+ var index = 0;
307
+ var nestedFormula = formulajs;
308
+ while (index < length) {
309
+ nestedFormula = nestedFormula[symbolParts[index]];
310
+ index++;
311
+ if (!nestedFormula) {
312
+ nestedFormula = null;
313
+ break;
314
+ }
315
+ }
316
+ if (nestedFormula) {
317
+ foundFormula = true;
318
+ result = nestedFormula.apply(void 0, arguments);
319
+ }
320
+ }
321
+ if (!foundFormula) {
322
+ throw Error(ERROR_NAME);
323
+ }
324
+ return result;
325
+ };
326
+ }
327
+ func$4.isFactory = true;
328
+ func$4.SYMBOL = SYMBOL$4;
329
+
330
+ var SYMBOL$5 = '>';
331
+ function func$5(exp1, exp2) {
332
+ return exp1 > exp2;
333
+ }
334
+ func$5.SYMBOL = SYMBOL$5;
335
+
336
+ var SYMBOL$6 = '>=';
337
+ function func$6(exp1, exp2) {
338
+ return exp1 >= exp2;
339
+ }
340
+ func$6.SYMBOL = SYMBOL$6;
341
+
342
+ var SYMBOL$7 = '<';
343
+ function func$7(exp1, exp2) {
344
+ return exp1 < exp2;
345
+ }
346
+ func$7.SYMBOL = SYMBOL$7;
347
+
348
+ var SYMBOL$8 = '<=';
349
+ function func$8(exp1, exp2) {
350
+ return exp1 <= exp2;
351
+ }
352
+ func$8.SYMBOL = SYMBOL$8;
353
+
354
+ var SYMBOL$9 = '-';
355
+ function func$9(first) {
356
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
357
+ rest[_key - 1] = arguments[_key];
358
+ }
359
+ var result = rest.reduce(function (acc, value) {
360
+ return acc - toNumber(value);
361
+ }, toNumber(first));
362
+ if (isNaN(result)) {
363
+ throw Error(ERROR_VALUE);
364
+ }
365
+ return result;
366
+ }
367
+ func$9.SYMBOL = SYMBOL$9;
368
+
369
+ var SYMBOL$a = '*';
370
+ function func$a(first) {
371
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
372
+ rest[_key - 1] = arguments[_key];
373
+ }
374
+ var result = rest.reduce(function (acc, value) {
375
+ return acc * toNumber(value);
376
+ }, toNumber(first));
377
+ if (isNaN(result)) {
378
+ throw Error(ERROR_VALUE);
379
+ }
380
+ return result;
381
+ }
382
+ func$a.SYMBOL = SYMBOL$a;
383
+
384
+ var SYMBOL$b = '<>';
385
+ function func$b(exp1, exp2) {
386
+ return exp1 !== exp2;
387
+ }
388
+ func$b.SYMBOL = SYMBOL$b;
389
+
390
+ var SYMBOL$c = '^';
391
+ function func$c(exp1, exp2) {
392
+ var result = Math.pow(toNumber(exp1), toNumber(exp2));
393
+ if (isNaN(result)) {
394
+ throw Error(ERROR_VALUE);
395
+ }
396
+ return result;
397
+ }
398
+ func$c.SYMBOL = SYMBOL$c;
399
+
400
+ var availableOperators = Object.create(null);
401
+
402
+ /**
403
+ * Evaluate values by operator id.git
404
+ *
405
+ * @param {String} operator Operator id.
406
+ * @param {Array} [params=[]] Arguments to evaluate.
407
+ * @returns {*}
408
+ */
409
+ function evaluateByOperator(operator) {
410
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
411
+ operator = operator.toUpperCase();
412
+ if (!availableOperators[operator]) {
413
+ throw Error(ERROR_NAME);
414
+ }
415
+ return availableOperators[operator].apply(availableOperators, _toConsumableArray(params));
416
+ }
417
+
418
+ /**
419
+ * Register operator.
420
+ *
421
+ * @param {String|Array} symbol Symbol to register.
422
+ * @param {Function} func Logic to register for this symbol.
423
+ */
424
+ function registerOperation(symbol, func) {
425
+ if (!Array.isArray(symbol)) {
426
+ symbol = [symbol.toUpperCase()];
427
+ }
428
+ symbol.forEach(function (s) {
429
+ if (func.isFactory) {
430
+ availableOperators[s] = func(s);
431
+ } else {
432
+ availableOperators[s] = func;
433
+ }
434
+ });
435
+ }
436
+ registerOperation(func.SYMBOL, func);
437
+ registerOperation(func$1.SYMBOL, func$1);
438
+ registerOperation(func$2.SYMBOL, func$2);
439
+ registerOperation(func$3.SYMBOL, func$3);
440
+ registerOperation(func$c.SYMBOL, func$c);
441
+ registerOperation(func$4.SYMBOL, func$4);
442
+ registerOperation(func$5.SYMBOL, func$5);
443
+ registerOperation(func$6.SYMBOL, func$6);
444
+ registerOperation(func$7.SYMBOL, func$7);
445
+ registerOperation(func$8.SYMBOL, func$8);
446
+ registerOperation(func$a.SYMBOL, func$a);
447
+ registerOperation(func$b.SYMBOL, func$b);
448
+ registerOperation(func$9.SYMBOL, func$9);
2
449
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Parser = Parser;
7
450
  /* parser generated by jison 0.4.18 */
8
451
  /*
9
452
  Returns a Parser object of the following structure:
@@ -198,7 +641,6 @@ var parser = {
198
641
  switch (yystate) {
199
642
  case 1:
200
643
  return $$[$0 - 1];
201
- break;
202
644
  case 2:
203
645
  this.$ = yy.callVariable($$[$0][0]);
204
646
  break;
@@ -860,7 +1302,6 @@ var parser = {
860
1302
  var _this = this;
861
1303
  var self = this,
862
1304
  stack = [0],
863
- tstack = [],
864
1305
  // token stack
865
1306
  vstack = [null],
866
1307
  // semantic value stack
@@ -919,7 +1360,6 @@ var parser = {
919
1360
  preErrorSymbol,
920
1361
  state,
921
1362
  action,
922
- a,
923
1363
  r,
924
1364
  yyval = {},
925
1365
  p,
@@ -1396,119 +1836,82 @@ var lexer = function () {
1396
1836
  },
1397
1837
  options: {},
1398
1838
  performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
1399
- var YYSTATE = YY_START;
1400
1839
  switch ($avoiding_name_collisions) {
1401
1840
  case 0:
1402
1841
  /* skip whitespace */
1403
1842
  break;
1404
1843
  case 1:
1405
1844
  return 8;
1406
- break;
1407
1845
  case 2:
1408
1846
  return 8;
1409
- break;
1410
1847
  case 3:
1411
1848
  return 21;
1412
- break;
1413
1849
  case 4:
1414
1850
  return 35;
1415
- break;
1416
1851
  case 5:
1417
1852
  return 24;
1418
- break;
1419
1853
  case 6:
1420
1854
  return 26;
1421
- break;
1422
1855
  case 7:
1423
1856
  return 26;
1424
- break;
1425
1857
  case 8:
1426
1858
  return 25;
1427
- break;
1428
1859
  case 9:
1429
1860
  return 21;
1430
- break;
1431
1861
  case 10:
1432
1862
  return 31;
1433
- break;
1434
1863
  case 11:
1435
1864
  return 31;
1436
- break;
1437
1865
  case 12:
1438
1866
  return 33;
1439
- break;
1440
1867
  case 13:
1441
1868
  return 28;
1442
- break;
1443
1869
  case 14:
1444
1870
  return 9;
1445
- break;
1446
1871
  case 15:
1447
1872
  return ' ';
1448
- break;
1449
1873
  case 16:
1450
1874
  return 32;
1451
- break;
1452
1875
  case 17:
1453
1876
  return 27;
1454
- break;
1455
1877
  case 18:
1456
1878
  return 29;
1457
- break;
1458
1879
  case 19:
1459
1880
  return 30;
1460
- break;
1461
1881
  case 20:
1462
1882
  return 18;
1463
- break;
1464
1883
  case 21:
1465
1884
  return 19;
1466
- break;
1467
1885
  case 22:
1468
1886
  return 17;
1469
- break;
1470
1887
  case 23:
1471
1888
  return 11;
1472
- break;
1473
1889
  case 24:
1474
1890
  return 20;
1475
- break;
1476
1891
  case 25:
1477
1892
  return 12;
1478
- break;
1479
1893
  case 26:
1480
1894
  return 13;
1481
- break;
1482
1895
  case 27:
1483
1896
  return 15;
1484
- break;
1485
1897
  case 28:
1486
1898
  return 14;
1487
- break;
1488
1899
  case 29:
1489
1900
  return 16;
1490
- break;
1491
1901
  case 30:
1492
1902
  return '"';
1493
- break;
1494
1903
  case 31:
1495
1904
  return "'";
1496
- break;
1497
1905
  case 32:
1498
1906
  return "!";
1499
- break;
1500
1907
  case 33:
1501
1908
  return 10;
1502
- break;
1503
1909
  case 34:
1504
1910
  return 34;
1505
- break;
1506
1911
  case 35:
1507
1912
  return '#';
1508
- break;
1509
1913
  case 36:
1510
1914
  return 5;
1511
- break;
1512
1915
  }
1513
1916
  },
1514
1917
  rules: [/^(?:\s+)/, /^(?:"(\\["]|[^"])*")/, /^(?:'(\\[']|[^'])*'[^'!])/, /^(?:[A-Za-z]{1,}[A-Za-z_0-9\.]+(?=[(]))/, /^(?:#[A-Z0-9\/]+(!|\?)?)/, ABSOLUTE_CELL, MIXED_CELL_COL, MIXED_CELL_ROW, RELATIVE_CELL, /^(?:[A-Za-z\.]+(?=[(]))/, /^(?:[A-Za-z]{1,}[A-Za-z_0-9]+)/, /^(?:[A-Za-z_]+)/, /^(?:[0-9]+)/, /^(?:\[(.*)?\])/, /^(?:&)/, /^(?: )/, /^(?:[.])/, /^(?::)/, /^(?:;)/, /^(?:,)/, /^(?:\*)/, /^(?:\/)/, /^(?:-)/, /^(?:\+)/, /^(?:\^)/, /^(?:\()/, /^(?:\))/, /^(?:>)/, /^(?:<)/, /^(?:NOT\b)/, /^(?:")/, /^(?:')/, /^(?:!)/, /^(?:=)/, /^(?:%)/, /^(?:[#])/, /^(?:$)/],
@@ -1526,4 +1929,411 @@ function Parser() {
1526
1929
  this.yy = {};
1527
1930
  }
1528
1931
  Parser.prototype = parser;
1529
- parser.Parser = Parser;
1932
+ parser.Parser = Parser;
1933
+
1934
+ /* eslint-disable import/prefer-default-export */
1935
+ /**
1936
+ * Trim value by cutting character starting from the beginning and ending at the same time.
1937
+ *
1938
+ * @param {String} string String to trimming.
1939
+ * @param {Number} [margin=1] Number of character to cut.
1940
+ * @returns {String}
1941
+ */
1942
+ function trimEdges(string) {
1943
+ var margin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1944
+ string = string.substring(margin, string.length - margin);
1945
+ return string;
1946
+ }
1947
+
1948
+ /**
1949
+ * Convert row label to index.
1950
+ *
1951
+ * @param {String} label Row label (eq. '1', '5')
1952
+ * @returns {Number} Returns -1 if label is not recognized otherwise proper row index.
1953
+ */
1954
+ function rowLabelToIndex(label) {
1955
+ var result = parseInt(label, 10);
1956
+ if (isNaN(result)) {
1957
+ result = -1;
1958
+ } else {
1959
+ result = Math.max(result - 1, -1);
1960
+ }
1961
+ return result;
1962
+ }
1963
+
1964
+ /**
1965
+ * Convert row index to label.
1966
+ *
1967
+ * @param {Number} row Row index.
1968
+ * @returns {String} Returns row label (eq. '1', '7').
1969
+ */
1970
+ function rowIndexToLabel(row) {
1971
+ var result = '';
1972
+ if (row >= 0) {
1973
+ result = "".concat(row + 1);
1974
+ }
1975
+ return result;
1976
+ }
1977
+ var COLUMN_LABEL_BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
1978
+ var COLUMN_LABEL_BASE_LENGTH = COLUMN_LABEL_BASE.length;
1979
+
1980
+ /**
1981
+ * Convert column label to index.
1982
+ *
1983
+ * @param {String} label Column label (eq. 'ABB', 'CNQ')
1984
+ * @returns {Number} Returns -1 if label is not recognized otherwise proper column index.
1985
+ */
1986
+ function columnLabelToIndex(label) {
1987
+ var result = 0;
1988
+ if (typeof label === 'string') {
1989
+ label = label.toUpperCase();
1990
+ for (var i = 0, j = label.length - 1; i < label.length; i += 1, j -= 1) {
1991
+ result += Math.pow(COLUMN_LABEL_BASE_LENGTH, j) * (COLUMN_LABEL_BASE.indexOf(label[i]) + 1);
1992
+ }
1993
+ }
1994
+ --result;
1995
+ return result;
1996
+ }
1997
+
1998
+ /**
1999
+ * Convert column index to label.
2000
+ *
2001
+ * @param {Number} column Column index.
2002
+ * @returns {String} Returns column label (eq. 'ABB', 'CNQ').
2003
+ */
2004
+ function columnIndexToLabel(column) {
2005
+ var result = '';
2006
+ while (column >= 0) {
2007
+ result = String.fromCharCode(column % COLUMN_LABEL_BASE_LENGTH + 97) + result;
2008
+ column = Math.floor(column / COLUMN_LABEL_BASE_LENGTH) - 1;
2009
+ }
2010
+ return result.toUpperCase();
2011
+ }
2012
+ var simpleSheetName$1 = "[A-Za-z0-9_\xC0-\u02AF]+";
2013
+ var quotedSheetName$1 = "'(?:(?!').|'')*'";
2014
+ var sheetNameRegexp$1 = "(".concat(simpleSheetName$1, "|").concat(quotedSheetName$1, ")!");
2015
+ var LABEL_EXTRACT_REGEXP = new RegExp("^(?:".concat(sheetNameRegexp$1, ")?([$])?([A-Za-z]*)([$])?([0-9]*)$"));
2016
+
2017
+ /**
2018
+ * Extract cell coordinates.
2019
+ *
2020
+ * @param {String} label Cell coordinates (eq. 'A1', '$B6', '$N$98').
2021
+ * @returns {Array} Returns an array of objects.
2022
+ */
2023
+ function extractLabel(label) {
2024
+ if (typeof label !== 'string' || !LABEL_EXTRACT_REGEXP.test(label)) {
2025
+ return [];
2026
+ }
2027
+ var _label$toUpperCase$ma = label.toUpperCase().match(LABEL_EXTRACT_REGEXP),
2028
+ _label$toUpperCase$ma2 = _slicedToArray(_label$toUpperCase$ma, 6),
2029
+ sheetNameStr = _label$toUpperCase$ma2[1],
2030
+ columnAbs = _label$toUpperCase$ma2[2],
2031
+ column = _label$toUpperCase$ma2[3],
2032
+ rowAbs = _label$toUpperCase$ma2[4],
2033
+ row = _label$toUpperCase$ma2[5];
2034
+ if (column == null && row == null) return [];
2035
+ var sheetName = sheetNameStr == null ? null : label.slice(0, sheetNameStr.length).replace(/^'|'$/g, "").replace(/''/g, "'");
2036
+ return [{
2037
+ index: rowLabelToIndex(row),
2038
+ label: row,
2039
+ isAbsolute: rowAbs === '$'
2040
+ }, {
2041
+ index: columnLabelToIndex(column),
2042
+ label: column,
2043
+ isAbsolute: columnAbs === '$'
2044
+ }, sheetName];
2045
+ }
2046
+
2047
+ /**
2048
+ * Convert row and column indexes into cell label.
2049
+ *
2050
+ * @param {Object} row Object with `index` and `isAbsolute` properties.
2051
+ * @param {Object} column Object with `index` and `isAbsolute` properties.
2052
+ * @returns {String} Returns cell label.
2053
+ */
2054
+ function toLabel(row, column) {
2055
+ var rowLabel = (row.isAbsolute ? '$' : '') + rowIndexToLabel(row.index);
2056
+ var columnLabel = (column.isAbsolute ? '$' : '') + columnIndexToLabel(column.index);
2057
+ return columnLabel + rowLabel;
2058
+ }
2059
+
2060
+ /**
2061
+ * @class Parser
2062
+ */
2063
+ var Parser$1 = /*#__PURE__*/function (_Emitter) {
2064
+ function Parser$1() {
2065
+ var _this;
2066
+ _classCallCheck(this, Parser$1);
2067
+ _this = _callSuper(this, Parser$1);
2068
+ _this.parser = new Parser();
2069
+ _this.parser.yy = {
2070
+ toNumber: toNumber,
2071
+ trimEdges: trimEdges,
2072
+ invertNumber: invertNumber,
2073
+ throwError: function throwError(errorName) {
2074
+ return _this._throwError(errorName);
2075
+ },
2076
+ callVariable: function callVariable(variable) {
2077
+ return _this._callVariable(variable);
2078
+ },
2079
+ evaluateByOperator: evaluateByOperator,
2080
+ callFunction: function callFunction(name, params) {
2081
+ return _this._callFunction(name, params);
2082
+ },
2083
+ cellValue: function cellValue(value) {
2084
+ return _this._callCellValue(value);
2085
+ },
2086
+ rangeValue: function rangeValue(start, end) {
2087
+ return _this._callRangeValue(start, end);
2088
+ }
2089
+ };
2090
+ _this.variables = Object.create(null);
2091
+ _this.functions = Object.create(null);
2092
+ _this.options = Object.create(null);
2093
+ _this.setVariable('TRUE', true).setVariable('FALSE', false).setVariable('NULL', null);
2094
+ return _this;
2095
+ }
2096
+
2097
+ /**
2098
+ * Parse formula expression.
2099
+ *
2100
+ * @param {string} expression to parse.
2101
+ * @param {object} options additional params.
2102
+ * @param {string} options.sheetId id of sheet which the formula expression belongs to.
2103
+ * @return {*} Returns an object with tow properties `error` and `result`.
2104
+ */
2105
+ _inherits(Parser$1, _Emitter);
2106
+ return _createClass(Parser$1, [{
2107
+ key: "parse",
2108
+ value: function parse(expression, options) {
2109
+ var result = null;
2110
+ var error$1 = null;
2111
+ this.options = options;
2112
+ try {
2113
+ if (expression === '') {
2114
+ result = '';
2115
+ } else {
2116
+ result = this.parser.parse(expression);
2117
+ }
2118
+ } catch (ex) {
2119
+ var message = error(ex.message);
2120
+ if (message) {
2121
+ error$1 = message;
2122
+ } else {
2123
+ error$1 = error(ERROR);
2124
+ }
2125
+ }
2126
+ if (result instanceof Error) {
2127
+ error$1 = error(result.message) || error(ERROR);
2128
+ result = null;
2129
+ }
2130
+ return {
2131
+ error: error$1,
2132
+ result: result
2133
+ };
2134
+ }
2135
+
2136
+ /**
2137
+ * Set predefined variable name which can be visible while parsing formula expression.
2138
+ *
2139
+ * @param {String} name Variable name.
2140
+ * @param {*} value Variable value.
2141
+ * @returns {Parser}
2142
+ */
2143
+ }, {
2144
+ key: "setVariable",
2145
+ value: function setVariable(name, value) {
2146
+ this.variables[name] = value;
2147
+ return this;
2148
+ }
2149
+
2150
+ /**
2151
+ * Get variable name.
2152
+ *
2153
+ * @param {String} name Variable name.
2154
+ * @returns {*}
2155
+ */
2156
+ }, {
2157
+ key: "getVariable",
2158
+ value: function getVariable(name) {
2159
+ return this.variables[name];
2160
+ }
2161
+
2162
+ /**
2163
+ * Retrieve variable value by its name.
2164
+ *
2165
+ * @param name Variable name.
2166
+ * @returns {*}
2167
+ * @private
2168
+ */
2169
+ }, {
2170
+ key: "_callVariable",
2171
+ value: function _callVariable(name) {
2172
+ var value = this.getVariable(name);
2173
+ this.emit('callVariable', name, function (newValue) {
2174
+ if (newValue !== void 0) {
2175
+ value = newValue;
2176
+ }
2177
+ });
2178
+ if (value === void 0) {
2179
+ throw Error(ERROR_NAME);
2180
+ }
2181
+ return value;
2182
+ }
2183
+
2184
+ /**
2185
+ * Set custom function which can be visible while parsing formula expression.
2186
+ *
2187
+ * @param {String} name Custom function name.
2188
+ * @param {Function} fn Custom function.
2189
+ * @returns {Parser}
2190
+ */
2191
+ }, {
2192
+ key: "setFunction",
2193
+ value: function setFunction(name, fn) {
2194
+ this.functions[name] = fn;
2195
+ return this;
2196
+ }
2197
+
2198
+ /**
2199
+ * Get custom function.
2200
+ *
2201
+ * @param {String} name Custom function name.
2202
+ * @returns {*}
2203
+ */
2204
+ }, {
2205
+ key: "getFunction",
2206
+ value: function getFunction(name) {
2207
+ return this.functions[name];
2208
+ }
2209
+
2210
+ /**
2211
+ * Call function with provided params.
2212
+ *
2213
+ * @param name Function name.
2214
+ * @param params Function params.
2215
+ * @returns {*}
2216
+ * @private
2217
+ */
2218
+ }, {
2219
+ key: "_callFunction",
2220
+ value: function _callFunction(name) {
2221
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
2222
+ var fn = this.getFunction(name);
2223
+ var value;
2224
+ if (fn) {
2225
+ value = fn(params);
2226
+ }
2227
+ this.emit('callFunction', name, params, function (newValue) {
2228
+ if (newValue !== void 0) {
2229
+ value = newValue;
2230
+ }
2231
+ });
2232
+ return value === void 0 ? evaluateByOperator(name, params) : value;
2233
+ }
2234
+
2235
+ /**
2236
+ * Retrieve value by its label (`B3`, `B$3`, `B$3`, `$B$3`).
2237
+ *
2238
+ * @param {String} label Coordinates.
2239
+ * @returns {*}
2240
+ * @private
2241
+ */
2242
+ }, {
2243
+ key: "_callCellValue",
2244
+ value: function _callCellValue(label) {
2245
+ var _extractLabel = extractLabel(label),
2246
+ _extractLabel2 = _slicedToArray(_extractLabel, 3),
2247
+ row = _extractLabel2[0],
2248
+ column = _extractLabel2[1],
2249
+ sheetName = _extractLabel2[2];
2250
+ if ((column === null || column === void 0 ? void 0 : column.index) === -1) {
2251
+ if (row.isAbsolute || column.isAbsolute) {
2252
+ throw Error(ERROR_NAME);
2253
+ }
2254
+ return row.index + 1;
2255
+ } else if ((row === null || row === void 0 ? void 0 : row.index) === -1) {
2256
+ throw Error(ERROR_NAME);
2257
+ }
2258
+ var value = void 0;
2259
+ this.emit('callCellValue', {
2260
+ label: label,
2261
+ row: row,
2262
+ column: column,
2263
+ sheetName: sheetName
2264
+ }, this.options, function (_value) {
2265
+ value = _value;
2266
+ });
2267
+ return value;
2268
+ }
2269
+
2270
+ /**
2271
+ * Retrieve value by its label (`B3:A1`, `B$3:A1`, `B$3:$A1`, `$B$3:A$1`).
2272
+ *
2273
+ * @param {String} startLabel Coordinates of the first cell.
2274
+ * @param {String} endLabel Coordinates of the last cell.
2275
+ * @returns {Array} Returns an array of mixed values.
2276
+ * @private
2277
+ */
2278
+ }, {
2279
+ key: "_callRangeValue",
2280
+ value: function _callRangeValue(startLabel, endLabel) {
2281
+ var _extractLabel3 = extractLabel(startLabel),
2282
+ _extractLabel4 = _slicedToArray(_extractLabel3, 3),
2283
+ startRow = _extractLabel4[0],
2284
+ startColumn = _extractLabel4[1],
2285
+ startSheetName = _extractLabel4[2];
2286
+ var _extractLabel5 = extractLabel(endLabel),
2287
+ _extractLabel6 = _slicedToArray(_extractLabel5, 3),
2288
+ endRow = _extractLabel6[0],
2289
+ endColumn = _extractLabel6[1],
2290
+ endSheetName = _extractLabel6[2];
2291
+ if (endSheetName != null && startSheetName != endSheetName) {
2292
+ throw Error(ERROR_VALUE);
2293
+ }
2294
+ var startCell = {};
2295
+ var endCell = {};
2296
+ startCell.sheetName = startSheetName;
2297
+ if (startRow.index <= endRow.index) {
2298
+ startCell.row = startRow;
2299
+ endCell.row = endRow;
2300
+ } else {
2301
+ startCell.row = endRow;
2302
+ endCell.row = startRow;
2303
+ }
2304
+ if (startColumn.index <= endColumn.index) {
2305
+ startCell.column = startColumn;
2306
+ endCell.column = endColumn;
2307
+ } else {
2308
+ startCell.column = endColumn;
2309
+ endCell.column = startColumn;
2310
+ }
2311
+ startCell.label = toLabel(startCell.row, startCell.column);
2312
+ endCell.label = toLabel(endCell.row, endCell.column);
2313
+ var value = [];
2314
+ this.emit('callRangeValue', startCell, endCell, this.options, function () {
2315
+ var _value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2316
+ value = _value;
2317
+ });
2318
+ return value;
2319
+ }
2320
+
2321
+ /**
2322
+ * Try to throw error by its name.
2323
+ *
2324
+ * @param {String} errorName Error name.
2325
+ * @returns {String}
2326
+ * @private
2327
+ */
2328
+ }, {
2329
+ key: "_throwError",
2330
+ value: function _throwError(errorName) {
2331
+ if (isValidStrict(errorName)) {
2332
+ throw Error(errorName);
2333
+ }
2334
+ throw Error(ERROR);
2335
+ }
2336
+ }]);
2337
+ }(Emitter);
2338
+
2339
+ export { ERROR, ERROR_DIV_ZERO, ERROR_NAME, ERROR_NOT_AVAILABLE, ERROR_NULL, ERROR_NUM, ERROR_REF, ERROR_VALUE, Parser$1 as Parser, SUPPORTED_FORMULAS, columnIndexToLabel, columnLabelToIndex, error, extractLabel, rowIndexToLabel, rowLabelToIndex, toLabel };