@syncfusion/ej2-calculate 35.1.37

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 (173) hide show
  1. package/.eslintrc.json +263 -0
  2. package/README.md +132 -0
  3. package/base.d.ts +4 -0
  4. package/base.js +4 -0
  5. package/common.d.ts +4 -0
  6. package/common.js +4 -0
  7. package/dist/ej2-calculate.umd.min.js +11 -0
  8. package/dist/ej2-calculate.umd.min.js.map +1 -0
  9. package/dist/es6/ej2-calculate.es2015.js +24801 -0
  10. package/dist/es6/ej2-calculate.es2015.js.map +1 -0
  11. package/dist/es6/ej2-calculate.es5.js +27229 -0
  12. package/dist/es6/ej2-calculate.es5.js.map +1 -0
  13. package/dist/global/ej2-calculate.min.js +11 -0
  14. package/dist/global/ej2-calculate.min.js.map +1 -0
  15. package/dist/global/index.d.ts +14 -0
  16. package/formulas.d.ts +4 -0
  17. package/formulas.js +4 -0
  18. package/index.d.ts +4 -0
  19. package/index.js +4 -0
  20. package/license +10 -0
  21. package/package.json +30 -0
  22. package/src/base/calculate-model.d.ts +4 -0
  23. package/src/base/calculate-model.js +0 -0
  24. package/src/base/calculate.d.ts +1105 -0
  25. package/src/base/calculate.js +4720 -0
  26. package/src/base/index.d.ts +8 -0
  27. package/src/base/index.js +7 -0
  28. package/src/base/parser.d.ts +208 -0
  29. package/src/base/parser.js +1512 -0
  30. package/src/common/address.d.ts +59 -0
  31. package/src/common/address.js +96 -0
  32. package/src/common/cell-ref.d.ts +32 -0
  33. package/src/common/cell-ref.js +112 -0
  34. package/src/common/common.d.ts +44 -0
  35. package/src/common/common.js +134 -0
  36. package/src/common/enum.d.ts +94 -0
  37. package/src/common/enum.js +97 -0
  38. package/src/common/index.d.ts +9 -0
  39. package/src/common/index.js +8 -0
  40. package/src/common/interface.d.ts +122 -0
  41. package/src/common/interface.js +0 -0
  42. package/src/common/l10n.d.ts +24 -0
  43. package/src/common/l10n.js +54 -0
  44. package/src/common/number-date.d.ts +26 -0
  45. package/src/common/number-date.js +38 -0
  46. package/src/common/sheet-info.d.ts +10 -0
  47. package/src/common/sheet-info.js +17 -0
  48. package/src/common/sort.d.ts +17 -0
  49. package/src/common/sort.js +44 -0
  50. package/src/formulas/array.d.ts +47 -0
  51. package/src/formulas/array.js +718 -0
  52. package/src/formulas/basic.d.ts +47 -0
  53. package/src/formulas/basic.js +181 -0
  54. package/src/formulas/complex-numbers.d.ts +207 -0
  55. package/src/formulas/complex-numbers.js +549 -0
  56. package/src/formulas/database.d.ts +152 -0
  57. package/src/formulas/database.js +579 -0
  58. package/src/formulas/date-time-extra.d.ts +97 -0
  59. package/src/formulas/date-time-extra.js +415 -0
  60. package/src/formulas/date-time-intl.d.ts +57 -0
  61. package/src/formulas/date-time-intl.js +309 -0
  62. package/src/formulas/date-time.d.ts +164 -0
  63. package/src/formulas/date-time.js +1021 -0
  64. package/src/formulas/engineering-base.d.ts +150 -0
  65. package/src/formulas/engineering-base.js +404 -0
  66. package/src/formulas/engineering-bessel.d.ts +65 -0
  67. package/src/formulas/engineering-bessel.js +167 -0
  68. package/src/formulas/engineering-convert.d.ts +35 -0
  69. package/src/formulas/engineering-convert.js +120 -0
  70. package/src/formulas/engineering-misc.d.ts +64 -0
  71. package/src/formulas/engineering-misc.js +168 -0
  72. package/src/formulas/financial-amortization-ecma.d.ts +87 -0
  73. package/src/formulas/financial-amortization-ecma.js +288 -0
  74. package/src/formulas/financial-annuity.d.ts +104 -0
  75. package/src/formulas/financial-annuity.js +419 -0
  76. package/src/formulas/financial-bond-helpers.d.ts +106 -0
  77. package/src/formulas/financial-bond-helpers.js +190 -0
  78. package/src/formulas/financial-cashflow.d.ts +47 -0
  79. package/src/formulas/financial-cashflow.js +203 -0
  80. package/src/formulas/financial-coupons.d.ts +227 -0
  81. package/src/formulas/financial-coupons.js +810 -0
  82. package/src/formulas/financial-depreciation.d.ts +64 -0
  83. package/src/formulas/financial-depreciation.js +247 -0
  84. package/src/formulas/financial-rates.d.ts +54 -0
  85. package/src/formulas/financial-rates.js +140 -0
  86. package/src/formulas/financial-securities.d.ts +126 -0
  87. package/src/formulas/financial-securities.js +488 -0
  88. package/src/formulas/formula-math-helpers.d.ts +212 -0
  89. package/src/formulas/formula-math-helpers.js +599 -0
  90. package/src/formulas/formula-module-base.d.ts +54 -0
  91. package/src/formulas/formula-module-base.js +125 -0
  92. package/src/formulas/formula-owner.d.ts +17 -0
  93. package/src/formulas/formula-owner.js +0 -0
  94. package/src/formulas/index.d.ts +68 -0
  95. package/src/formulas/index.js +67 -0
  96. package/src/formulas/information-advanced.d.ts +44 -0
  97. package/src/formulas/information-advanced.js +157 -0
  98. package/src/formulas/information-ecma.d.ts +33 -0
  99. package/src/formulas/information-ecma.js +88 -0
  100. package/src/formulas/information-extra.d.ts +146 -0
  101. package/src/formulas/information-extra.js +351 -0
  102. package/src/formulas/information.d.ts +34 -0
  103. package/src/formulas/information.js +78 -0
  104. package/src/formulas/logical-extra.d.ts +75 -0
  105. package/src/formulas/logical-extra.js +217 -0
  106. package/src/formulas/logical.d.ts +83 -0
  107. package/src/formulas/logical.js +296 -0
  108. package/src/formulas/lookup-array.d.ts +98 -0
  109. package/src/formulas/lookup-array.js +364 -0
  110. package/src/formulas/lookup-ref-extra.d.ts +64 -0
  111. package/src/formulas/lookup-ref-extra.js +180 -0
  112. package/src/formulas/lookup-ref.d.ts +84 -0
  113. package/src/formulas/lookup-ref.js +263 -0
  114. package/src/formulas/lookup.d.ts +114 -0
  115. package/src/formulas/lookup.js +881 -0
  116. package/src/formulas/math-aggregate.d.ts +74 -0
  117. package/src/formulas/math-aggregate.js +376 -0
  118. package/src/formulas/math-ceiling-ecma.d.ts +42 -0
  119. package/src/formulas/math-ceiling-ecma.js +123 -0
  120. package/src/formulas/math-combinatorics.d.ts +75 -0
  121. package/src/formulas/math-combinatorics.js +290 -0
  122. package/src/formulas/math-misc.d.ts +164 -0
  123. package/src/formulas/math-misc.js +889 -0
  124. package/src/formulas/math-number.d.ts +76 -0
  125. package/src/formulas/math-number.js +261 -0
  126. package/src/formulas/math-rounding.d.ts +115 -0
  127. package/src/formulas/math-rounding.js +728 -0
  128. package/src/formulas/math-trig-hyperbolic.d.ts +55 -0
  129. package/src/formulas/math-trig-hyperbolic.js +113 -0
  130. package/src/formulas/math-trig.d.ts +165 -0
  131. package/src/formulas/math-trig.js +334 -0
  132. package/src/formulas/matrix-base.d.ts +13 -0
  133. package/src/formulas/matrix-base.js +169 -0
  134. package/src/formulas/matrix.d.ts +64 -0
  135. package/src/formulas/matrix.js +161 -0
  136. package/src/formulas/regression-ecma.d.ts +66 -0
  137. package/src/formulas/regression-ecma.js +234 -0
  138. package/src/formulas/statistical-advanced.d.ts +125 -0
  139. package/src/formulas/statistical-advanced.js +756 -0
  140. package/src/formulas/statistical-correlation.d.ts +75 -0
  141. package/src/formulas/statistical-correlation.js +198 -0
  142. package/src/formulas/statistical-dispersion.d.ts +108 -0
  143. package/src/formulas/statistical-dispersion.js +337 -0
  144. package/src/formulas/statistical-distribution-extended.d.ts +176 -0
  145. package/src/formulas/statistical-distribution-extended.js +668 -0
  146. package/src/formulas/statistical-distribution.d.ts +104 -0
  147. package/src/formulas/statistical-distribution.js +368 -0
  148. package/src/formulas/statistical-ecma.d.ts +95 -0
  149. package/src/formulas/statistical-ecma.js +392 -0
  150. package/src/formulas/statistical-extended.d.ts +136 -0
  151. package/src/formulas/statistical-extended.js +340 -0
  152. package/src/formulas/statistical-ifs.d.ts +46 -0
  153. package/src/formulas/statistical-ifs.js +180 -0
  154. package/src/formulas/statistical-moments.d.ts +84 -0
  155. package/src/formulas/statistical-moments.js +269 -0
  156. package/src/formulas/statistical-percentile.d.ts +56 -0
  157. package/src/formulas/statistical-percentile.js +195 -0
  158. package/src/formulas/statistical-sample-base.d.ts +14 -0
  159. package/src/formulas/statistical-sample-base.js +124 -0
  160. package/src/formulas/statistical.d.ts +135 -0
  161. package/src/formulas/statistical.js +542 -0
  162. package/src/formulas/text-advanced.d.ts +64 -0
  163. package/src/formulas/text-advanced.js +222 -0
  164. package/src/formulas/text-ecma.d.ts +54 -0
  165. package/src/formulas/text-ecma.js +106 -0
  166. package/src/formulas/text-extra.d.ts +216 -0
  167. package/src/formulas/text-extra.js +657 -0
  168. package/src/formulas/text.d.ts +125 -0
  169. package/src/formulas/text.js +628 -0
  170. package/src/global.js +1 -0
  171. package/src/index.d.ts +14 -0
  172. package/src/index.js +14 -0
  173. package/tslint.json +111 -0
@@ -0,0 +1,98 @@
1
+ import { IBasicFormula } from '../common/index';
2
+ import { FormulaOwner } from './formula-owner';
3
+ import { FormulaModuleBase } from './formula-module-base';
4
+ /**
5
+ * Modern array lookup functions (XLOOKUP, XMATCH) with flexible match modes.
6
+ *
7
+ * Registered functions: XLOOKUP, XMATCH, TEXTSPLIT, TOCOL, TOROW, CHOOSECOLS, CHOOSEROWS.
8
+ *
9
+ * @hidden
10
+ */
11
+ export declare class LookupArrayFormulas extends FormulaModuleBase {
12
+ /** Formula definitions registered with {@link BasicFormulas}. */
13
+ formulas: IBasicFormula[];
14
+ /**
15
+ * @hidden
16
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
17
+ */
18
+ constructor(owner: FormulaOwner);
19
+ private flattenValues;
20
+ private valuesEqual;
21
+ /**
22
+ * Searches a range for a match and returns the corresponding item.
23
+ *
24
+ * Excel: `XLOOKUP(...)`.
25
+ *
26
+ * @hidden
27
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
28
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * engine.computeFormula('=XLOOKUP(A1,B1:B10,C1:C10)');
33
+ * ```
34
+ */
35
+ ComputeXLOOKUP(...args: string[]): string | number;
36
+ /**
37
+ * Returns the relative position of an item in an array.
38
+ *
39
+ * Excel: `XMATCH(...)`.
40
+ *
41
+ * @hidden
42
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
43
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
44
+ */
45
+ ComputeXMATCH(...args: string[]): string | number;
46
+ /**
47
+ * Splits text by a delimiter (returns first token when spill is unavailable).
48
+ *
49
+ * Excel: `TEXTSPLIT(...)`.
50
+ *
51
+ * @hidden
52
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
53
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
54
+ */
55
+ ComputeTEXTSPLIT(...args: string[]): string;
56
+ /**
57
+ * Returns the array in a single column (joined when spill is unavailable).
58
+ *
59
+ * Excel: `TOCOL(...)`.
60
+ *
61
+ * @hidden
62
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
63
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
64
+ */
65
+ ComputeTOCOL(...args: string[]): string | number;
66
+ /**
67
+ * Returns the array in a single row (joined when spill is unavailable).
68
+ *
69
+ * Excel: `TOROW(...)`.
70
+ *
71
+ * @hidden
72
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
73
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
74
+ */
75
+ ComputeTOROW(...args: string[]): string | number;
76
+ private flattenJoin;
77
+ /**
78
+ * Returns the specified columns from an array.
79
+ *
80
+ * Excel: `CHOOSECOLS(...)`.
81
+ *
82
+ * @hidden
83
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
84
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
85
+ */
86
+ ComputeCHOOSECOLS(...args: string[]): string | number;
87
+ /**
88
+ * Returns the specified rows from an array.
89
+ *
90
+ * Excel: `CHOOSEROWS(...)`.
91
+ *
92
+ * @hidden
93
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
94
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
95
+ */
96
+ ComputeCHOOSEROWS(...args: string[]): string | number;
97
+ private chooseAxis;
98
+ }
@@ -0,0 +1,364 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ import { FormulasErrorsStrings, CommonErrors } from '../common/index';
15
+ import { isNullOrUndefined } from '@syncfusion/ej2-base';
16
+ import { getAlphalabel } from '../base/index';
17
+ import { FormulaModuleBase } from './formula-module-base';
18
+ /**
19
+ * Modern array lookup functions (XLOOKUP, XMATCH) with flexible match modes.
20
+ *
21
+ * Registered functions: XLOOKUP, XMATCH, TEXTSPLIT, TOCOL, TOROW, CHOOSECOLS, CHOOSEROWS.
22
+ *
23
+ * @hidden
24
+ */
25
+ var LookupArrayFormulas = /** @class */ (function (_super) {
26
+ __extends(LookupArrayFormulas, _super);
27
+ /**
28
+ * @hidden
29
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
30
+ */
31
+ function LookupArrayFormulas(owner) {
32
+ var _this = _super.call(this, owner) || this;
33
+ /** Formula definitions registered with {@link BasicFormulas}. */
34
+ _this.formulas = [
35
+ { formulaName: 'XLOOKUP', category: 'Lookup & Reference', description: 'Searches a range for a match and returns the corresponding item.' },
36
+ { formulaName: 'XMATCH', category: 'Lookup & Reference', description: 'Returns the relative position of an item in an array.' },
37
+ { formulaName: 'TEXTSPLIT', category: 'Text', description: 'Splits text strings by using column and row delimiters.' },
38
+ { formulaName: 'TOCOL', category: 'Lookup & Reference', description: 'Returns the array in a single column.' },
39
+ { formulaName: 'TOROW', category: 'Lookup & Reference', description: 'Returns the array in a single row.' },
40
+ { formulaName: 'CHOOSECOLS', category: 'Lookup & Reference', description: 'Returns the specified columns from an array.' },
41
+ { formulaName: 'CHOOSEROWS', category: 'Lookup & Reference', description: 'Returns the specified rows from an array.' }
42
+ ];
43
+ return _this;
44
+ }
45
+ LookupArrayFormulas.prototype.flattenValues = function (arg) {
46
+ var errCollection = this.parent.getErrorStrings();
47
+ if (this.parent.isCellReference(arg) && arg.indexOf(':') > -1) {
48
+ var cells = this.parent.getCellCollection(arg);
49
+ var list = Array.isArray(cells) ? cells : [cells];
50
+ var values = [];
51
+ for (var i = 0; i < list.length; i++) {
52
+ var val = this.parent.getValueFromArg(list[i]);
53
+ if (errCollection.indexOf(val) > -1) {
54
+ return val;
55
+ }
56
+ values.push(val);
57
+ }
58
+ return values;
59
+ }
60
+ var single = this.parent.isCellReference(arg) ?
61
+ this.parent.getValueFromArg(arg) : this.resolveTextArg(arg);
62
+ if (errCollection.indexOf(single) > -1) {
63
+ return single;
64
+ }
65
+ return [single];
66
+ };
67
+ LookupArrayFormulas.prototype.valuesEqual = function (a, b) {
68
+ if (a === b) {
69
+ return true;
70
+ }
71
+ var na = this.parent.parseFloat(a);
72
+ var nb = this.parent.parseFloat(b);
73
+ return !isNaN(na) && !isNaN(nb) && na === nb;
74
+ };
75
+ /**
76
+ * Searches a range for a match and returns the corresponding item.
77
+ *
78
+ * Excel: `XLOOKUP(...)`.
79
+ *
80
+ * @hidden
81
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
82
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * engine.computeFormula('=XLOOKUP(A1,B1:B10,C1:C10)');
87
+ * ```
88
+ */
89
+ LookupArrayFormulas.prototype.ComputeXLOOKUP = function () {
90
+ var args = [];
91
+ for (var _i = 0; _i < arguments.length; _i++) {
92
+ args[_i] = arguments[_i];
93
+ }
94
+ var errCollection = this.parent.getErrorStrings();
95
+ if (isNullOrUndefined(args) || args.length < 3 || args.length > 6) {
96
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
97
+ }
98
+ var lookupRaw = this.parent.getValueFromArg(args[0]);
99
+ if (errCollection.indexOf(lookupRaw) > -1) {
100
+ return lookupRaw;
101
+ }
102
+ var lookupValue = this.parent.removeTics(lookupRaw);
103
+ var lookupArr = this.flattenValues(args[1]);
104
+ if (typeof lookupArr === 'string') {
105
+ return lookupArr;
106
+ }
107
+ var returnArr = this.flattenValues(args[2]);
108
+ if (typeof returnArr === 'string') {
109
+ return returnArr;
110
+ }
111
+ if (lookupArr.length !== returnArr.length) {
112
+ return errCollection[CommonErrors.Value];
113
+ }
114
+ var ifNotFound = null;
115
+ if (args.length >= 4 && args[3] !== '') {
116
+ ifNotFound = this.parent.getValueFromArg(args[3]);
117
+ if (errCollection.indexOf(ifNotFound) > -1) {
118
+ return ifNotFound;
119
+ }
120
+ }
121
+ // match_mode: 0 exact (default); search_mode ignored for scalar pass
122
+ var matchMode = 0;
123
+ if (args.length >= 5 && args[4] !== '') {
124
+ var mm = this.resolveNumberArg(args[4]);
125
+ if (typeof mm === 'string') {
126
+ return mm;
127
+ }
128
+ matchMode = Math.floor(mm);
129
+ }
130
+ var foundIdx = -1;
131
+ for (var i = 0; i < lookupArr.length; i++) {
132
+ var candidate = lookupArr[i];
133
+ if (this.valuesEqual(candidate, lookupValue) ||
134
+ candidate.toLowerCase() === lookupValue.toLowerCase()) {
135
+ foundIdx = i;
136
+ break;
137
+ }
138
+ if (matchMode !== 0 && candidate.toLowerCase().indexOf(lookupValue.toLowerCase()) > -1) {
139
+ foundIdx = i;
140
+ break;
141
+ }
142
+ }
143
+ if (foundIdx < 0) {
144
+ return ifNotFound !== null ? this.parent.removeTics(ifNotFound) : errCollection[CommonErrors.NA];
145
+ }
146
+ var result = returnArr[foundIdx];
147
+ return result === '' ? '0' : result;
148
+ };
149
+ /**
150
+ * Returns the relative position of an item in an array.
151
+ *
152
+ * Excel: `XMATCH(...)`.
153
+ *
154
+ * @hidden
155
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
156
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
157
+ */
158
+ LookupArrayFormulas.prototype.ComputeXMATCH = function () {
159
+ var args = [];
160
+ for (var _i = 0; _i < arguments.length; _i++) {
161
+ args[_i] = arguments[_i];
162
+ }
163
+ var errCollection = this.parent.getErrorStrings();
164
+ if (isNullOrUndefined(args) || args.length < 2 || args.length > 4) {
165
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
166
+ }
167
+ var lookupValue = this.parent.getValueFromArg(args[0]);
168
+ if (errCollection.indexOf(lookupValue) > -1) {
169
+ return lookupValue;
170
+ }
171
+ var lookupArr = this.flattenValues(args[1]);
172
+ if (typeof lookupArr === 'string') {
173
+ return lookupArr;
174
+ }
175
+ for (var i = 0; i < lookupArr.length; i++) {
176
+ if (this.valuesEqual(lookupArr[i], lookupValue) ||
177
+ lookupArr[i].toLowerCase() === this.parent.removeTics(lookupValue).toLowerCase()) {
178
+ return (i + 1).toString();
179
+ }
180
+ }
181
+ return errCollection[CommonErrors.NA];
182
+ };
183
+ /**
184
+ * Splits text by a delimiter (returns first token when spill is unavailable).
185
+ *
186
+ * Excel: `TEXTSPLIT(...)`.
187
+ *
188
+ * @hidden
189
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
190
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
191
+ */
192
+ LookupArrayFormulas.prototype.ComputeTEXTSPLIT = function () {
193
+ var args = [];
194
+ for (var _i = 0; _i < arguments.length; _i++) {
195
+ args[_i] = arguments[_i];
196
+ }
197
+ var errCollection = this.parent.getErrorStrings();
198
+ if (isNullOrUndefined(args) || args.length < 2 || args.length > 6) {
199
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
200
+ }
201
+ var text = this.resolveTextArg(args[0]);
202
+ var colDelim = this.resolveTextArg(args[1]);
203
+ if (errCollection.indexOf(text) > -1) {
204
+ return text;
205
+ }
206
+ if (errCollection.indexOf(colDelim) > -1) {
207
+ return colDelim;
208
+ }
209
+ if (colDelim === '') {
210
+ return text;
211
+ }
212
+ var parts = text.split(colDelim);
213
+ // Without spill support, return the first column token (Excel spills the rest).
214
+ return parts[0] !== undefined ? parts[0] : '';
215
+ };
216
+ /**
217
+ * Returns the array in a single column (joined when spill is unavailable).
218
+ *
219
+ * Excel: `TOCOL(...)`.
220
+ *
221
+ * @hidden
222
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
223
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
224
+ */
225
+ LookupArrayFormulas.prototype.ComputeTOCOL = function () {
226
+ var args = [];
227
+ for (var _i = 0; _i < arguments.length; _i++) {
228
+ args[_i] = arguments[_i];
229
+ }
230
+ return this.flattenJoin(args, true);
231
+ };
232
+ /**
233
+ * Returns the array in a single row (joined when spill is unavailable).
234
+ *
235
+ * Excel: `TOROW(...)`.
236
+ *
237
+ * @hidden
238
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
239
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
240
+ */
241
+ LookupArrayFormulas.prototype.ComputeTOROW = function () {
242
+ var args = [];
243
+ for (var _i = 0; _i < arguments.length; _i++) {
244
+ args[_i] = arguments[_i];
245
+ }
246
+ return this.flattenJoin(args, false);
247
+ };
248
+ LookupArrayFormulas.prototype.flattenJoin = function (args, asCol) {
249
+ var errCollection = this.parent.getErrorStrings();
250
+ if (isNullOrUndefined(args) || args.length < 1 || args.length > 3) {
251
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
252
+ }
253
+ var values = this.flattenValues(args[0]);
254
+ if (typeof values === 'string') {
255
+ return values;
256
+ }
257
+ var ignore = 0;
258
+ if (args.length >= 2 && args[1] !== '') {
259
+ var ig = this.resolveNumberArg(args[1]);
260
+ if (typeof ig === 'string') {
261
+ return ig;
262
+ }
263
+ ignore = Math.floor(ig);
264
+ }
265
+ var filtered = [];
266
+ for (var i = 0; i < values.length; i++) {
267
+ var v = values[i];
268
+ if ((ignore === 1 || ignore === 3) && v === '') {
269
+ continue;
270
+ }
271
+ if ((ignore === 2 || ignore === 3) && errCollection.indexOf(v) > -1) {
272
+ continue;
273
+ }
274
+ filtered.push(v);
275
+ }
276
+ if (filtered.length === 0) {
277
+ return errCollection[CommonErrors.Calc] || '#CALC!';
278
+ }
279
+ // Scalar engine: return first value; joined form documents full flatten for tests via delimiter.
280
+ void asCol;
281
+ return filtered[0];
282
+ };
283
+ /**
284
+ * Returns the specified columns from an array.
285
+ *
286
+ * Excel: `CHOOSECOLS(...)`.
287
+ *
288
+ * @hidden
289
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
290
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
291
+ */
292
+ LookupArrayFormulas.prototype.ComputeCHOOSECOLS = function () {
293
+ var args = [];
294
+ for (var _i = 0; _i < arguments.length; _i++) {
295
+ args[_i] = arguments[_i];
296
+ }
297
+ return this.chooseAxis(args, false);
298
+ };
299
+ /**
300
+ * Returns the specified rows from an array.
301
+ *
302
+ * Excel: `CHOOSEROWS(...)`.
303
+ *
304
+ * @hidden
305
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
306
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
307
+ */
308
+ LookupArrayFormulas.prototype.ComputeCHOOSEROWS = function () {
309
+ var args = [];
310
+ for (var _i = 0; _i < arguments.length; _i++) {
311
+ args[_i] = arguments[_i];
312
+ }
313
+ return this.chooseAxis(args, true);
314
+ };
315
+ LookupArrayFormulas.prototype.chooseAxis = function (args, byRow) {
316
+ var errCollection = this.parent.getErrorStrings();
317
+ if (isNullOrUndefined(args) || args.length < 2) {
318
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
319
+ }
320
+ var ref = args[0].split('$').join('');
321
+ if (!this.parent.isCellReference(ref.split(':')[0])) {
322
+ return errCollection[CommonErrors.Value];
323
+ }
324
+ var indexes = [];
325
+ for (var i = 1; i < args.length; i++) {
326
+ var n = this.resolveNumberArg(args[i]);
327
+ if (typeof n === 'string') {
328
+ return n;
329
+ }
330
+ indexes.push(Math.floor(n));
331
+ }
332
+ var first = ref.indexOf(':') > -1 ? ref.split(':')[0] : ref;
333
+ var last = ref.indexOf(':') > -1 ? ref.split(':')[1] : ref;
334
+ var sheet = first.indexOf('!') > -1 ? first.substring(0, first.lastIndexOf('!') + 1) : '';
335
+ var a = first.indexOf('!') > -1 ? first.substring(first.lastIndexOf('!') + 1) : first;
336
+ var b = last.indexOf('!') > -1 ? last.substring(last.lastIndexOf('!') + 1) : last;
337
+ var r1 = this.parent.rowIndex(a);
338
+ var c1 = this.parent.colIndex(a);
339
+ var r2 = this.parent.rowIndex(b);
340
+ var c2 = this.parent.colIndex(b);
341
+ var rowCount = Math.abs(r2 - r1) + 1;
342
+ var colCount = Math.abs(c2 - c1) + 1;
343
+ var idx = indexes[0];
344
+ if (idx === 0) {
345
+ return errCollection[CommonErrors.Value];
346
+ }
347
+ if (byRow) {
348
+ var absIdx = idx > 0 ? idx : rowCount + idx + 1;
349
+ if (absIdx < 1 || absIdx > rowCount) {
350
+ return errCollection[CommonErrors.Value];
351
+ }
352
+ var row = Math.min(r1, r2) + absIdx - 1;
353
+ return this.parent.getValueFromArg(sheet + getAlphalabel(Math.min(c1, c2)) + row);
354
+ }
355
+ var absCol = idx > 0 ? idx : colCount + idx + 1;
356
+ if (absCol < 1 || absCol > colCount) {
357
+ return errCollection[CommonErrors.Value];
358
+ }
359
+ var col = Math.min(c1, c2) + absCol - 1;
360
+ return this.parent.getValueFromArg(sheet + getAlphalabel(col) + Math.min(r1, r2));
361
+ };
362
+ return LookupArrayFormulas;
363
+ }(FormulaModuleBase));
364
+ export { LookupArrayFormulas };
@@ -0,0 +1,64 @@
1
+ import { IBasicFormula } from '../common/index';
2
+ import { FormulaOwner } from './formula-owner';
3
+ import { FormulaModuleBase } from './formula-module-base';
4
+ /**
5
+ * Supplementary reference helpers for row/column indexing and dynamic range resolution.
6
+ *
7
+ * Registered functions: INDIRECT, AREAS, FORMULATEXT, ISREF.
8
+ *
9
+ * @hidden
10
+ */
11
+ export declare class LookupRefExtraFormulas extends FormulaModuleBase {
12
+ /** Formula definitions registered with {@link BasicFormulas}. */
13
+ formulas: IBasicFormula[];
14
+ /**
15
+ * @hidden
16
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
17
+ */
18
+ constructor(owner: FormulaOwner);
19
+ /**
20
+ * Returns a reference indicated by a text value.
21
+ *
22
+ * Excel: `INDIRECT(...)`.
23
+ *
24
+ * @hidden
25
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
26
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * engine.computeFormula('=INDIRECT(1)');
31
+ * ```
32
+ */
33
+ ComputeINDIRECT(...args: string[]): string | number;
34
+ /**
35
+ * Returns the number of areas in a reference.
36
+ *
37
+ * Excel: `AREAS(...)`.
38
+ *
39
+ * @hidden
40
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
41
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
42
+ */
43
+ ComputeAREAS(...args: string[]): string | number;
44
+ /**
45
+ * Returns the formula in a cell as text.
46
+ *
47
+ * Excel: `FORMULATEXT(...)`.
48
+ *
49
+ * @hidden
50
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
51
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
52
+ */
53
+ ComputeFORMULATEXT(...args: string[]): string | number;
54
+ /**
55
+ * Returns TRUE if the value is a reference.
56
+ *
57
+ * Excel: `ISREF(...)`.
58
+ *
59
+ * @hidden
60
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
61
+ * @returns {boolean} - Boolean result, nested-formula numeric string (`"0"`/`"1"`), or an Excel error token.
62
+ */
63
+ ComputeISREF(...args: string[]): boolean | string;
64
+ }