@fileverse-dev/formula-parser 0.2.70 → 0.2.72

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.
package/es/error.js CHANGED
@@ -1,3 +1,4 @@
1
+ var _errors;
1
2
  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
3
  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; }
3
4
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
@@ -10,7 +11,7 @@ export var ERROR_NULL = "NULL";
10
11
  export var ERROR_NUM = "NUM";
11
12
  export var ERROR_REF = "REF";
12
13
  export var ERROR_VALUE = "VALUE";
13
- 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!");
14
+ var errors = (_errors = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_errors, 'Error: lookup_range and result_range are required', "Lookup range and result range are required"), 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!"), 'search_key', "Error: search_key is required"), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_errors, 'lookup_range', "Error: lookup_range is required"), 'result_range', "Error: result_range is required"), 'lookup_range_single', "Error: lookup_range must be a singular row or column"), 'result_range_invalid', "Error: result_range is invalid"), 'lookup_range_and_result_range', "Error: lookup_range and result_range must have the same number of columns"), 'match_mode_must', "Error: match_mode must be 0, 1, -1, or 2"), 'search_mode_must', "Error: search_mode must be 1, -1, 2, or -2"), 'binary_search_and_wildcard', "'Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)"));
14
15
 
15
16
  /**
16
17
  * Return error type based on provided error id.
@@ -1,3 +1,9 @@
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; }
1
7
  /* parser generated by jison 0.4.18 */
2
8
  /*
3
9
  Returns a Parser object of the following structure:
@@ -72,6 +78,24 @@
72
78
  }
73
79
  */
74
80
 
81
+ export function checkIsCol(str) {
82
+ if (!str) return null;
83
+ // match pattern like A1:B10
84
+ var match = str.match(/^([A-Z]+)(\d+):([A-Z]+)(\d+)$/i);
85
+ if (!match) return null;
86
+ var _match = _slicedToArray(match, 5),
87
+ col1 = _match[1],
88
+ row1 = _match[2],
89
+ col2 = _match[3],
90
+ row2 = _match[4];
91
+ // same column, different rows → false
92
+ if (col1 === col2 && row1 !== row2) return false;
93
+ // same row, different columns → true
94
+ if (row1 === row2 && col1 !== col2) return true;
95
+ // otherwise not a straight row/col selection
96
+ return null;
97
+ }
98
+
75
99
  /* addresses */
76
100
  var simpleSheetName = "[A-Za-z0-9_\xC0-\u02AF]+";
77
101
  var quotedSheetName = "'(?:(?!').|'')*'";
@@ -185,9 +209,15 @@ var parser = {
185
209
  35: "ERROR"
186
210
  },
187
211
  productions_: [0, [3, 2], [4, 1], [4, 1], [4, 1], [4, 3], [4, 3], [4, 3], [4, 3], [4, 4], [4, 4], [4, 4], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 2], [4, 2], [4, 3], [4, 4], [4, 1], [4, 1], [4, 2], [23, 1], [23, 1], [23, 1], [23, 3], [23, 3], [23, 3], [23, 3], [23, 3], [23, 3], [23, 3], [23, 3], [23, 3], [22, 1], [22, 1], [22, 3], [22, 3], [6, 1], [6, 3], [7, 1], [7, 3], [7, 2], [2, 1]],
188
- performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
212
+ performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */, initialInput) {
189
213
  /* this == yyval */
190
214
 
215
+ var isXlookuoColReference;
216
+ if (initialInput.toLowerCase().includes('xlookup')) {
217
+ var _initialInput$split, _initialInput$split$, _initialInput$split$$, _initialInput$split2, _initialInput$split2$, _initialInput$split2$2;
218
+ var t = initialInput.includes('XLOOKUP') ? initialInput === null || initialInput === void 0 ? void 0 : (_initialInput$split = initialInput.split('XLOOKUP(')) === null || _initialInput$split === void 0 ? void 0 : (_initialInput$split$ = _initialInput$split[1]) === null || _initialInput$split$ === void 0 ? void 0 : (_initialInput$split$$ = _initialInput$split$.split(',')) === null || _initialInput$split$$ === void 0 ? void 0 : _initialInput$split$$[1] : initialInput === null || initialInput === void 0 ? void 0 : (_initialInput$split2 = initialInput.split('xlookup(')) === null || _initialInput$split2 === void 0 ? void 0 : (_initialInput$split2$ = _initialInput$split2[1]) === null || _initialInput$split2$ === void 0 ? void 0 : (_initialInput$split2$2 = _initialInput$split2$.split(',')) === null || _initialInput$split2$2 === void 0 ? void 0 : _initialInput$split2$2[1];
219
+ isXlookuoColReference = checkIsCol(t);
220
+ }
191
221
  var $0 = $$.length - 1;
192
222
  switch (yystate) {
193
223
  case 1:
@@ -262,7 +292,7 @@ var parser = {
262
292
  this.$ = yy.callFunction($$[$0 - 2]);
263
293
  break;
264
294
  case 22:
265
- this.$ = yy.callFunction($$[$0 - 3], $$[$0 - 1]);
295
+ this.$ = yy.callFunction($$[$0 - 3], $$[$0 - 1], isXlookuoColReference);
266
296
  break;
267
297
  case 26:
268
298
  case 27:
@@ -1060,7 +1090,7 @@ var parser = {
1060
1090
  if (ranges) {
1061
1091
  yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
1062
1092
  }
1063
- r = _this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
1093
+ r = _this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack, input].concat(args));
1064
1094
  if (typeof r !== "undefined") {
1065
1095
  return {
1066
1096
  v: r
package/es/parser.js CHANGED
@@ -50,8 +50,8 @@ var Parser = /*#__PURE__*/function (_Emitter) {
50
50
  return _this._callVariable(variable);
51
51
  },
52
52
  evaluateByOperator: evaluateByOperator,
53
- callFunction: function callFunction(name, params) {
54
- return _this._callFunction(name, params);
53
+ callFunction: function callFunction(name, params, isXlookuoColReference) {
54
+ return _this._callFunction(name, params, isXlookuoColReference);
55
55
  },
56
56
  cellValue: function cellValue(value) {
57
57
  return _this._callCellValue(value);
@@ -194,6 +194,10 @@ var Parser = /*#__PURE__*/function (_Emitter) {
194
194
  key: "_callFunction",
195
195
  value: function _callFunction(name) {
196
196
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
197
+ var isXlookuoColReference = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
198
+ if (name.toLowerCase().includes('xlookup')) {
199
+ params.splice(3, 0, String(isXlookuoColReference));
200
+ }
197
201
  var fn = this.getFunction(name);
198
202
  var value;
199
203
  if (fn) {
package/lib/error.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
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
7
  exports["default"] = error;
8
8
  exports.isValidStrict = isValidStrict;
9
+ var _errors;
9
10
  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
11
  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
12
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
@@ -18,7 +19,7 @@ var ERROR_NULL = exports.ERROR_NULL = "NULL";
18
19
  var ERROR_NUM = exports.ERROR_NUM = "NUM";
19
20
  var ERROR_REF = exports.ERROR_REF = "REF";
20
21
  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
+ var errors = (_errors = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_errors, 'Error: lookup_range and result_range are required', "Lookup range and result range are required"), 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!"), 'search_key', "Error: search_key is required"), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_errors, 'lookup_range', "Error: lookup_range is required"), 'result_range', "Error: result_range is required"), 'lookup_range_single', "Error: lookup_range must be a singular row or column"), 'result_range_invalid', "Error: result_range is invalid"), 'lookup_range_and_result_range', "Error: lookup_range and result_range must have the same number of columns"), 'match_mode_must', "Error: match_mode must be 0, 1, -1, or 2"), 'search_mode_must', "Error: search_mode must be 1, -1, 2, or -2"), 'binary_search_and_wildcard', "'Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)"));
22
23
 
23
24
  /**
24
25
  * Return error type based on provided error id.
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Parser = Parser;
7
+ exports.checkIsCol = checkIsCol;
8
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
9
+ 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."); }
10
+ 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; } }
11
+ 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; }
12
+ 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; } }
13
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
7
14
  /* parser generated by jison 0.4.18 */
8
15
  /*
9
16
  Returns a Parser object of the following structure:
@@ -78,6 +85,24 @@ exports.Parser = Parser;
78
85
  }
79
86
  */
80
87
 
88
+ function checkIsCol(str) {
89
+ if (!str) return null;
90
+ // match pattern like A1:B10
91
+ var match = str.match(/^([A-Z]+)(\d+):([A-Z]+)(\d+)$/i);
92
+ if (!match) return null;
93
+ var _match = _slicedToArray(match, 5),
94
+ col1 = _match[1],
95
+ row1 = _match[2],
96
+ col2 = _match[3],
97
+ row2 = _match[4];
98
+ // same column, different rows → false
99
+ if (col1 === col2 && row1 !== row2) return false;
100
+ // same row, different columns → true
101
+ if (row1 === row2 && col1 !== col2) return true;
102
+ // otherwise not a straight row/col selection
103
+ return null;
104
+ }
105
+
81
106
  /* addresses */
82
107
  var simpleSheetName = "[A-Za-z0-9_\xC0-\u02AF]+";
83
108
  var quotedSheetName = "'(?:(?!').|'')*'";
@@ -191,9 +216,15 @@ var parser = {
191
216
  35: "ERROR"
192
217
  },
193
218
  productions_: [0, [3, 2], [4, 1], [4, 1], [4, 1], [4, 3], [4, 3], [4, 3], [4, 3], [4, 4], [4, 4], [4, 4], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 2], [4, 2], [4, 3], [4, 4], [4, 1], [4, 1], [4, 2], [23, 1], [23, 1], [23, 1], [23, 3], [23, 3], [23, 3], [23, 3], [23, 3], [23, 3], [23, 3], [23, 3], [23, 3], [22, 1], [22, 1], [22, 3], [22, 3], [6, 1], [6, 3], [7, 1], [7, 3], [7, 2], [2, 1]],
194
- performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
219
+ performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */, initialInput) {
195
220
  /* this == yyval */
196
221
 
222
+ var isXlookuoColReference;
223
+ if (initialInput.toLowerCase().includes('xlookup')) {
224
+ var _initialInput$split, _initialInput$split$, _initialInput$split$$, _initialInput$split2, _initialInput$split2$, _initialInput$split2$2;
225
+ var t = initialInput.includes('XLOOKUP') ? initialInput === null || initialInput === void 0 ? void 0 : (_initialInput$split = initialInput.split('XLOOKUP(')) === null || _initialInput$split === void 0 ? void 0 : (_initialInput$split$ = _initialInput$split[1]) === null || _initialInput$split$ === void 0 ? void 0 : (_initialInput$split$$ = _initialInput$split$.split(',')) === null || _initialInput$split$$ === void 0 ? void 0 : _initialInput$split$$[1] : initialInput === null || initialInput === void 0 ? void 0 : (_initialInput$split2 = initialInput.split('xlookup(')) === null || _initialInput$split2 === void 0 ? void 0 : (_initialInput$split2$ = _initialInput$split2[1]) === null || _initialInput$split2$ === void 0 ? void 0 : (_initialInput$split2$2 = _initialInput$split2$.split(',')) === null || _initialInput$split2$2 === void 0 ? void 0 : _initialInput$split2$2[1];
226
+ isXlookuoColReference = checkIsCol(t);
227
+ }
197
228
  var $0 = $$.length - 1;
198
229
  switch (yystate) {
199
230
  case 1:
@@ -268,7 +299,7 @@ var parser = {
268
299
  this.$ = yy.callFunction($$[$0 - 2]);
269
300
  break;
270
301
  case 22:
271
- this.$ = yy.callFunction($$[$0 - 3], $$[$0 - 1]);
302
+ this.$ = yy.callFunction($$[$0 - 3], $$[$0 - 1], isXlookuoColReference);
272
303
  break;
273
304
  case 26:
274
305
  case 27:
@@ -1066,7 +1097,7 @@ var parser = {
1066
1097
  if (ranges) {
1067
1098
  yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
1068
1099
  }
1069
- r = _this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
1100
+ r = _this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack, input].concat(args));
1070
1101
  if (typeof r !== "undefined") {
1071
1102
  return {
1072
1103
  v: r
package/lib/parser.js CHANGED
@@ -58,8 +58,8 @@ var Parser = /*#__PURE__*/function (_Emitter) {
58
58
  return _this._callVariable(variable);
59
59
  },
60
60
  evaluateByOperator: _evaluateByOperator["default"],
61
- callFunction: function callFunction(name, params) {
62
- return _this._callFunction(name, params);
61
+ callFunction: function callFunction(name, params, isXlookuoColReference) {
62
+ return _this._callFunction(name, params, isXlookuoColReference);
63
63
  },
64
64
  cellValue: function cellValue(value) {
65
65
  return _this._callCellValue(value);
@@ -202,6 +202,10 @@ var Parser = /*#__PURE__*/function (_Emitter) {
202
202
  key: "_callFunction",
203
203
  value: function _callFunction(name) {
204
204
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
205
+ var isXlookuoColReference = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
206
+ if (name.toLowerCase().includes('xlookup')) {
207
+ params.splice(3, 0, String(isXlookuoColReference));
208
+ }
205
209
  var fn = this.getFunction(name);
206
210
  var value;
207
211
  if (fn) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/formula-parser",
3
- "version": "0.2.70",
3
+ "version": "0.2.72",
4
4
  "description": "Formula parser",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -48,7 +48,7 @@
48
48
  "webpack-cli": "^4.2.0"
49
49
  },
50
50
  "dependencies": {
51
- "@fileverse-dev/formulajs": "4.4.20",
51
+ "@fileverse-dev/formulajs": "4.4.21",
52
52
  "tiny-emitter": "^2.1.0"
53
53
  },
54
54
  "jest": {