@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,628 @@
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, Internationalization } from '@syncfusion/ej2-base';
16
+ import { isValidCellReference } from '../common/cell-ref';
17
+ import { FormulaModuleBase } from './formula-module-base';
18
+ /**
19
+ * Core text manipulation: concatenation, case conversion, trimming, and substring extraction.
20
+ *
21
+ * Registers 10 functions including FIND, CONCATENATE, CONCAT, T, EXACT, and others.
22
+ *
23
+ * @hidden
24
+ */
25
+ var TextFormulas = /** @class */ (function (_super) {
26
+ __extends(TextFormulas, _super);
27
+ /**
28
+ * @hidden
29
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
30
+ */
31
+ function TextFormulas(owner) {
32
+ var _this = _super.call(this, owner) || this;
33
+ _this.isConcat = false;
34
+ /** Formula definitions registered with {@link BasicFormulas}. */
35
+ _this.formulas = [
36
+ { formulaName: 'FIND', category: 'Text', description: 'Returns the position of a string of text within another string.' },
37
+ { formulaName: 'CONCATENATE', category: 'Text', description: ' Used to join two or more strings together.' },
38
+ { formulaName: 'CONCAT', category: 'Text', description: 'Concatenates a list or range of text strings.' },
39
+ { formulaName: 'T', category: 'Text', description: 'Checks whether a value is text or not and returns the text.' },
40
+ { formulaName: 'EXACT', category: 'Text', description: 'Checks whether a two text strings are exactly same and returns TRUE or FALSE.' },
41
+ { formulaName: 'LEN', category: 'Text', description: 'Returns a number of characters in a given string.' },
42
+ { formulaName: 'CHAR', category: 'Text', description: 'Returns the character from the specified number.' },
43
+ { formulaName: 'CODE', category: 'Text', description: 'Returns the numeric code for the first character in a given string.' },
44
+ { formulaName: 'DOLLAR', category: 'Text', description: 'Converts the number to currency formatted text.' },
45
+ { formulaName: 'PROPER', category: 'Text', description: 'Converts a text to proper case; first letter to uppercase and other letters to lowercase.' }
46
+ ];
47
+ return _this;
48
+ }
49
+ /**
50
+ * Returns the position of a string of text within another string.
51
+ *
52
+ * Excel: `FIND(...)`.
53
+ *
54
+ * @hidden
55
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
56
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * engine.computeFormula('=FIND(1)');
61
+ * ```
62
+ */
63
+ TextFormulas.prototype.ComputeFIND = function () {
64
+ var _this = this;
65
+ var args = [];
66
+ for (var _i = 0; _i < arguments.length; _i++) {
67
+ args[_i] = arguments[_i];
68
+ }
69
+ var errCollection = this.parent.getErrorStrings();
70
+ if (isNullOrUndefined(args) || args.length === 1) {
71
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
72
+ }
73
+ else if (args.length > 3) {
74
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
75
+ }
76
+ var processArgs = function (actuaValue) {
77
+ var value = _this.parent.getValueFromArg(actuaValue);
78
+ if (isNullOrUndefined(value)) {
79
+ value = '';
80
+ }
81
+ else {
82
+ value = value.toString();
83
+ }
84
+ if (errCollection.indexOf(value) > -1) {
85
+ return value;
86
+ }
87
+ if (!_this.parent.isCellReference(actuaValue)) {
88
+ if (value.split('%').length === 2 && _this.parent.isNumber(value.split('%')[0])) {
89
+ value = (Number(value.split('%')[0]) * 0.01).toString();
90
+ }
91
+ else if (actuaValue.indexOf(_this.parent.tic) > -1) {
92
+ if (_this.parent.removeTics(actuaValue).match(/^(\d*\.\d+|\d+)\s*[-*/]\s*(\d*\.\d+|\d+)$/)) {
93
+ value = _this.parent.getValueFromArg(_this.parent.removeTics(actuaValue));
94
+ if (isNullOrUndefined(value)) {
95
+ value = '';
96
+ }
97
+ else {
98
+ value = value.toString();
99
+ }
100
+ }
101
+ else if (value.indexOf(_this.parent.tic + _this.parent.tic) > -1) {
102
+ value = value.replace(/""/g, _this.parent.tic);
103
+ }
104
+ }
105
+ }
106
+ return value;
107
+ };
108
+ var findText = '';
109
+ if (!isNullOrUndefined(args[0])) {
110
+ findText = processArgs(args[0]);
111
+ if (errCollection.indexOf(findText) > -1) {
112
+ return findText;
113
+ }
114
+ else if (!this.parent.isCellReference(args[0])) {
115
+ findText = this.parent.removeTics(findText);
116
+ }
117
+ }
118
+ var withinText = '';
119
+ if (!isNullOrUndefined(args[1])) {
120
+ withinText = processArgs(args[1]);
121
+ if (errCollection.indexOf(withinText) > -1) {
122
+ return withinText;
123
+ }
124
+ else if (!this.parent.isCellReference(args[1])) {
125
+ withinText = this.parent.removeTics(withinText);
126
+ }
127
+ }
128
+ var startNum = 1;
129
+ if (!isNullOrUndefined(args[2])) {
130
+ startNum = processArgs(args[2]);
131
+ if (errCollection.indexOf(startNum) > -1) {
132
+ return startNum;
133
+ }
134
+ else if (startNum.toUpperCase() === this.parent.trueValue) {
135
+ startNum = '1';
136
+ }
137
+ else if (startNum.toUpperCase() === this.parent.falseValue) {
138
+ startNum = '0';
139
+ }
140
+ if (!this.parent.isCellReference(args[2])) {
141
+ startNum = this.parent.removeTics(startNum);
142
+ }
143
+ startNum = this.parent.parseFloat(startNum);
144
+ if (isNaN(startNum) || startNum <= 0) {
145
+ return errCollection[CommonErrors.Value];
146
+ }
147
+ }
148
+ startNum = withinText.indexOf(findText, startNum - 1);
149
+ if (startNum < 0) {
150
+ return errCollection[CommonErrors.Value];
151
+ }
152
+ return (Number(startNum) + Number(1)).toString();
153
+ };
154
+ /**
155
+ * Used to join two or more strings together.
156
+ *
157
+ * Excel: `CONCATENATE(...)`.
158
+ *
159
+ * @hidden
160
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
161
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
162
+ */
163
+ TextFormulas.prototype.ComputeCONCATENATE = function () {
164
+ var args = [];
165
+ for (var _i = 0; _i < arguments.length; _i++) {
166
+ args[_i] = arguments[_i];
167
+ }
168
+ var errCollection = this.parent.getErrorStrings();
169
+ if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
170
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
171
+ }
172
+ var argsList = args;
173
+ var result = '';
174
+ var tempStr = '';
175
+ for (var i = 0; i < argsList.length; i++) {
176
+ var val = argsList[i];
177
+ if (this.parent.isCellReference(val)) {
178
+ if (val.indexOf(':') > -1) {
179
+ if (this.isConcat) {
180
+ var cells = this.parent.getCellCollection(val);
181
+ for (var i_1 = 0; i_1 < cells.length; i_1++) {
182
+ var tempString = this.parent.getValueFromArg(cells[i_1]);
183
+ result = result + tempString;
184
+ }
185
+ }
186
+ else {
187
+ return errCollection[CommonErrors.Value];
188
+ }
189
+ }
190
+ else {
191
+ if (argsList.length === 1 && argsList[0].indexOf(this.parent.tic) < 0 &&
192
+ !isValidCellReference(argsList[0])) {
193
+ return errCollection[CommonErrors.Name];
194
+ }
195
+ else {
196
+ tempStr = this.parent.getValueFromArg(val);
197
+ }
198
+ }
199
+ if (errCollection.indexOf(tempStr) > -1) {
200
+ return tempStr;
201
+ }
202
+ }
203
+ else {
204
+ if (val.startsWith(this.parent.tic) && val.endsWith(this.parent.tic) && val.indexOf('""') > -1) {
205
+ tempStr = val.substring(1, val.length - 1);
206
+ tempStr = tempStr.replace(/""/g, '"');
207
+ }
208
+ else {
209
+ tempStr = val.split(this.parent.tic).join('');
210
+ if (!(!(this.parent.isNumber(tempStr)) && !isNullOrUndefined(this.parent.isDate(tempStr))) || val.startsWith(' n')) {
211
+ tempStr = this.parent.getValueFromArg(val).split(this.parent.tic).join('');
212
+ }
213
+ }
214
+ if (errCollection.indexOf(tempStr) > -1) {
215
+ return tempStr;
216
+ }
217
+ }
218
+ result += tempStr;
219
+ }
220
+ this.isConcat = false;
221
+ return result;
222
+ };
223
+ /**
224
+ * Concatenates a list or range of text strings.
225
+ *
226
+ * Excel: `CONCAT(...)`.
227
+ *
228
+ * @hidden
229
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
230
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
231
+ */
232
+ TextFormulas.prototype.ComputeCONCAT = function () {
233
+ var args = [];
234
+ for (var _i = 0; _i < arguments.length; _i++) {
235
+ args[_i] = arguments[_i];
236
+ }
237
+ var _a;
238
+ this.isConcat = true;
239
+ return (_a = this.owner).ComputeCONCATENATE.apply(_a, args);
240
+ };
241
+ /**
242
+ * Checks whether a value is text or not and returns the text.
243
+ *
244
+ * Excel: `T(...)`.
245
+ *
246
+ * @hidden
247
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
248
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
249
+ */
250
+ TextFormulas.prototype.ComputeT = function () {
251
+ var args = [];
252
+ for (var _i = 0; _i < arguments.length; _i++) {
253
+ args[_i] = arguments[_i];
254
+ }
255
+ var value;
256
+ var nestedFormula;
257
+ var errCollection = this.parent.getErrorStrings();
258
+ if (args.length && args[args.length - 1] === 'nestedFormulaTrue') {
259
+ nestedFormula = true;
260
+ args.pop();
261
+ }
262
+ if (isNullOrUndefined(args) || (args.length === 1 && args[0].trim() === '')) {
263
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
264
+ }
265
+ else if (args.length > 1) {
266
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
267
+ }
268
+ value = this.parent.getValueFromArg(args[0]).trim();
269
+ if (errCollection.indexOf(value) > -1) {
270
+ return value;
271
+ }
272
+ if (args[0].indexOf(this.parent.tic) > -1) {
273
+ value = this.parent.removeTics(args[0].trim());
274
+ if (value.indexOf(this.parent.tic + this.parent.tic) > -1) {
275
+ value = value.replace(/""/g, this.parent.tic);
276
+ }
277
+ }
278
+ else {
279
+ if (value.split('%').length === 2 && this.parent.isNumber(value.split('%')[0])) {
280
+ value = (Number(value.split('%')[0]) / 100).toString();
281
+ }
282
+ if (this.parent.isNumber(value) ||
283
+ value.toUpperCase() === this.parent.trueValue || value.toUpperCase() === this.parent.falseValue) {
284
+ return '';
285
+ }
286
+ }
287
+ if (nestedFormula) {
288
+ value = this.parent.tic + value + this.parent.tic;
289
+ }
290
+ return value;
291
+ };
292
+ /**
293
+ * Checks whether a two text strings are exactly same and returns TRUE or FALSE.
294
+ *
295
+ * Excel: `EXACT(...)`.
296
+ *
297
+ * @hidden
298
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
299
+ * @returns {boolean} - Boolean result, nested-formula numeric string (`"0"`/`"1"`), or an Excel error token.
300
+ */
301
+ TextFormulas.prototype.ComputeEXACT = function () {
302
+ var args = [];
303
+ for (var _i = 0; _i < arguments.length; _i++) {
304
+ args[_i] = arguments[_i];
305
+ }
306
+ var result = false;
307
+ var nestedFormula = args.length && args[args.length - 1] === 'nestedFormulaTrue';
308
+ var errCollection = this.parent.getErrorStrings();
309
+ if (nestedFormula) {
310
+ args.pop();
311
+ }
312
+ if (!args || (!args[0] && args.length === 1)) {
313
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
314
+ }
315
+ else if (args.length !== 2) {
316
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
317
+ }
318
+ var value1;
319
+ var value2;
320
+ var isCellRef;
321
+ if (args[0]) {
322
+ value1 = this.parent.getValueFromArg(args[0]);
323
+ if (errCollection.indexOf(value1) > -1) {
324
+ return value1;
325
+ }
326
+ if (value1.indexOf(this.parent.tic) === -1 && value1.includes('%')) {
327
+ value1 = (Number(value1.split('%')[0]) / 100).toString();
328
+ }
329
+ if (this.parent.isCellReference(args[0])) {
330
+ isCellRef = true;
331
+ }
332
+ else {
333
+ value1 = value1.split(this.parent.tic).join('');
334
+ }
335
+ }
336
+ if (args[1]) {
337
+ value2 = this.parent.getValueFromArg(args[1]);
338
+ if (errCollection.indexOf(value2) > -1) {
339
+ return value2;
340
+ }
341
+ if (value2.indexOf(this.parent.tic) === -1 && value2.includes('%')) {
342
+ value2 = (Number(value2.split('%')[0]) / 100).toString();
343
+ }
344
+ if (this.parent.isCellReference(args[1])) {
345
+ if (!isCellRef && ((value1.trim().length === 0) && (value2.trim().length === 0))) {
346
+ result = false;
347
+ }
348
+ }
349
+ else {
350
+ value2 = value2.split(this.parent.tic).join('');
351
+ if (isCellRef && ((value1.trim().length === 0) && (value2.trim().length === 0))) {
352
+ result = false;
353
+ }
354
+ }
355
+ }
356
+ if (value1 === value2) {
357
+ result = true;
358
+ }
359
+ return nestedFormula ? (result ? '1' : '0') : result;
360
+ };
361
+ /**
362
+ * Returns a number of characters in a given string.
363
+ *
364
+ * Excel: `LEN(...)`.
365
+ *
366
+ * @hidden
367
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
368
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
369
+ */
370
+ TextFormulas.prototype.ComputeLEN = function () {
371
+ var args = [];
372
+ for (var _i = 0; _i < arguments.length; _i++) {
373
+ args[_i] = arguments[_i];
374
+ }
375
+ var value;
376
+ var errorStrings = this.parent.getErrorStrings();
377
+ if (isNullOrUndefined(args) || (args[0].trim() === '' && args.length === 1)) {
378
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
379
+ }
380
+ else if (args.length > 1) {
381
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
382
+ }
383
+ value = this.parent.getValueFromArg(args[0]);
384
+ if (errorStrings.indexOf(value) > -1) {
385
+ return value;
386
+ }
387
+ if (args[0].indexOf(this.parent.tic) > -1) {
388
+ if (args[0] !== value && args[0].startsWith('n')) {
389
+ value = this.parent.removeTics(value.trim());
390
+ }
391
+ else {
392
+ value = this.parent.removeTics(args[0].trim());
393
+ if (value.indexOf(this.parent.tic + this.parent.tic) > -1) {
394
+ value = value.replace(/""/g, this.parent.tic);
395
+ }
396
+ }
397
+ }
398
+ else if (!args[0].startsWith('n') && value.split('%').length === 2 && this.parent.isNumber(value.split('%')[0])) {
399
+ value = (Number(value.split('%')[0]) / 100).toString();
400
+ }
401
+ else if (this.parent.isNumber(value)) {
402
+ value = value.trim();
403
+ }
404
+ return value.length;
405
+ };
406
+ /**
407
+ * Returns the character from the specified number.
408
+ *
409
+ * Excel: `CHAR(...)`.
410
+ *
411
+ * @hidden
412
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
413
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
414
+ */
415
+ TextFormulas.prototype.ComputeCHAR = function () {
416
+ var args = [];
417
+ for (var _i = 0; _i < arguments.length; _i++) {
418
+ args[_i] = arguments[_i];
419
+ }
420
+ var value;
421
+ var errCollection = this.parent.getErrorStrings();
422
+ if (isNullOrUndefined(args) || args[0] === '') {
423
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
424
+ }
425
+ else if (args.length !== 1) {
426
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
427
+ }
428
+ var val = this.parent.getValueFromArg(args[0]).trim();
429
+ if (errCollection.indexOf(val) > -1) {
430
+ return val;
431
+ }
432
+ else if (val.indexOf('"TRUE"') > -1 || (this.parent.isCellReference(args[0]) &&
433
+ val.startsWith(this.parent.tic))) {
434
+ return errCollection[CommonErrors.Value];
435
+ }
436
+ val = val.split(this.parent.tic).join('');
437
+ if (this.parent.isNumber(val)) {
438
+ val = Math.floor(Number(val)).toString();
439
+ }
440
+ else if (val.indexOf('%') > -1) {
441
+ val = Math.floor(Number(val.split('%')[0]) / 100).toString();
442
+ }
443
+ else if (val === this.parent.trueValue) {
444
+ val = '1';
445
+ }
446
+ if (val.toUpperCase().match(/^[0-9]+$/)) {
447
+ var char = parseInt(val, 10);
448
+ if (char > 255 || char <= 0) {
449
+ return errCollection[CommonErrors.Value];
450
+ }
451
+ value = String.fromCharCode(char);
452
+ }
453
+ else {
454
+ return errCollection[CommonErrors.Value];
455
+ }
456
+ return value;
457
+ };
458
+ /**
459
+ * Returns the numeric code for the first character in a given string.
460
+ *
461
+ * Excel: `CODE(...)`.
462
+ *
463
+ * @hidden
464
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
465
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
466
+ */
467
+ TextFormulas.prototype.ComputeCODE = function () {
468
+ var args = [];
469
+ for (var _i = 0; _i < arguments.length; _i++) {
470
+ args[_i] = arguments[_i];
471
+ }
472
+ var value;
473
+ var errCollection = this.parent.getErrorStrings();
474
+ if (isNullOrUndefined(args) || (args.length === 1 && args[0].trim() === '')) {
475
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
476
+ }
477
+ else if (args.length > 1) {
478
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
479
+ }
480
+ value = this.parent.getValueFromArg(args[0]).trim();
481
+ if (errCollection.indexOf(value) > -1) {
482
+ return value;
483
+ }
484
+ if (args[0].indexOf(this.parent.tic) > -1) {
485
+ if (args[0] !== value && args[0].startsWith('n')) {
486
+ value = this.parent.removeTics(value.trim());
487
+ }
488
+ else {
489
+ value = this.parent.removeTics(args[0].trim());
490
+ }
491
+ }
492
+ else if (!args[0].startsWith('n') && value.split('%').length === 2 && this.parent.isNumber(value.split('%')[0])) {
493
+ value = (Number(value.split('%')[0]) / 100).toString();
494
+ }
495
+ if (value !== '') {
496
+ value = value.charCodeAt(0);
497
+ }
498
+ else {
499
+ return errCollection[CommonErrors.Value];
500
+ }
501
+ return value;
502
+ };
503
+ /**
504
+ * Converts the number to currency formatted text.
505
+ *
506
+ * Excel: `DOLLAR(...)`.
507
+ *
508
+ * @hidden
509
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
510
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
511
+ */
512
+ TextFormulas.prototype.ComputeDOLLAR = function () {
513
+ var args = [];
514
+ for (var _i = 0; _i < arguments.length; _i++) {
515
+ args[_i] = arguments[_i];
516
+ }
517
+ var value;
518
+ var isEmpty;
519
+ var nestedFormula;
520
+ if (args.length && args[args.length - 1] === 'nestedFormulaTrue') {
521
+ nestedFormula = true;
522
+ args.pop();
523
+ }
524
+ if (args.length === 1) {
525
+ if (args[0] === '') {
526
+ isEmpty = true;
527
+ }
528
+ args.push('2');
529
+ }
530
+ if (isNullOrUndefined(args) || args.length !== 2 || isEmpty) {
531
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
532
+ }
533
+ for (var i = 0; i < args.length; i++) {
534
+ if (args[i].indexOf(this.parent.tic) > -1) {
535
+ if (isNaN(this.parent.parseFloat(args[i]))) {
536
+ return this.parent.getErrorStrings()[CommonErrors.Value];
537
+ }
538
+ }
539
+ }
540
+ var val = this.parent.getValueFromArg(args[0]).split(this.parent.tic).join('');
541
+ var val2 = this.parent.getValueFromArg(args[1]).split(this.parent.tic).join('');
542
+ val = val === '' || val === this.parent.falseValue ? '0' : val === this.parent.trueValue ? '1' : val;
543
+ val2 = val2 === '' || val2 === this.parent.falseValue ? '0' : val2 === this.parent.trueValue ? '1' : val2;
544
+ if (val === '#NAME?' || val2 === '#NAME?') {
545
+ return this.parent.getErrorStrings()[CommonErrors.Name];
546
+ }
547
+ if (val.toUpperCase().match(/^[-]?[0-9.]+$/) && val2.toUpperCase().match(/^[-]?[0-9.]+$/)) {
548
+ var intl = new Internationalization();
549
+ var decimalCount = parseInt(val2, 10);
550
+ var divisor = Math.pow(10, -1 * decimalCount);
551
+ var decimalValue = '';
552
+ for (var decimalIdx = 1; decimalIdx <= decimalCount; decimalIdx++) {
553
+ decimalValue += '0';
554
+ }
555
+ var roundedNumber = Math.round(this.parent.parseFloat(val) / divisor) * divisor;
556
+ if (!isNaN(roundedNumber)) {
557
+ value = intl.formatNumber(roundedNumber, { format: '$#,##0.' + decimalValue + ';($#,##0.' + decimalValue + ');$0.' + decimalValue });
558
+ }
559
+ else {
560
+ value = this.parent.getErrorStrings()[CommonErrors.Value];
561
+ }
562
+ }
563
+ else {
564
+ return this.parent.getErrorStrings()[CommonErrors.Value];
565
+ }
566
+ if (nestedFormula) {
567
+ value = this.parent.tic + value + this.parent.tic;
568
+ }
569
+ return value;
570
+ };
571
+ /**
572
+ * Converts a text to proper case; first letter to uppercase and other letters to lowercase.
573
+ *
574
+ * Excel: `PROPER(...)`.
575
+ *
576
+ * @hidden
577
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
578
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
579
+ */
580
+ TextFormulas.prototype.ComputePROPER = function () {
581
+ var args = [];
582
+ for (var _i = 0; _i < arguments.length; _i++) {
583
+ args[_i] = arguments[_i];
584
+ }
585
+ var str;
586
+ var nestedFormula;
587
+ var errCollection = this.parent.getErrorStrings();
588
+ if (args.length && args[args.length - 1] === 'nestedFormulaTrue') {
589
+ nestedFormula = true;
590
+ args.pop();
591
+ }
592
+ if (isNullOrUndefined(args) || (args[0].trim() === '' && args.length === 1)) {
593
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
594
+ }
595
+ else if (args.length > 1) {
596
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
597
+ }
598
+ str = this.parent.getValueFromArg(args[0]).trim();
599
+ if (errCollection.indexOf(str) > -1) {
600
+ return str;
601
+ }
602
+ if (args[0].indexOf(this.parent.tic) > -1) {
603
+ if (args[0] !== str && args[0].startsWith('n')) {
604
+ str = this.parent.removeTics(str.trim());
605
+ }
606
+ else {
607
+ str = this.parent.removeTics(args[0].trim());
608
+ if (str.indexOf(this.parent.tic + this.parent.tic) > -1) {
609
+ str = str.replace(/""/g, this.parent.tic);
610
+ }
611
+ }
612
+ }
613
+ else if (!args[0].startsWith('n') && str.split('%').length === 2 && this.parent.isNumber(str.split('%')[0])) {
614
+ str = (Number(str.split('%')[0]) / 100).toString();
615
+ }
616
+ str = str.toLowerCase().replace(/\b\w/g, function (char) {
617
+ return char.toUpperCase();
618
+ }).replace(/(\d)([a-z])/g, function (match, number, char) {
619
+ return number + char.toUpperCase();
620
+ });
621
+ if (nestedFormula) {
622
+ str = this.parent.tic + str + this.parent.tic;
623
+ }
624
+ return str;
625
+ };
626
+ return TextFormulas;
627
+ }(FormulaModuleBase));
628
+ export { TextFormulas };
package/src/global.js ADDED
@@ -0,0 +1 @@
1
+ export * from './index';
package/src/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `@syncfusion/ej2-calculate` — Excel-compatible formula evaluation engine.
3
+ *
4
+ * ## Public surface
5
+ *
6
+ * - {@link Calculate} — primary engine for parsing and evaluating formulas
7
+ * - Formula category modules under `formulas/` — built-in Excel / ECMA-376 functions
8
+ * - Shared types and helpers under `common/` — errors, host contracts, cell addressing
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ export * from './base/index';
13
+ export * from './common/index';
14
+ export * from './formulas/index';
package/src/index.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `@syncfusion/ej2-calculate` — Excel-compatible formula evaluation engine.
3
+ *
4
+ * ## Public surface
5
+ *
6
+ * - {@link Calculate} — primary engine for parsing and evaluating formulas
7
+ * - Formula category modules under `formulas/` — built-in Excel / ECMA-376 functions
8
+ * - Shared types and helpers under `common/` — errors, host contracts, cell addressing
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ export * from './base/index';
13
+ export * from './common/index';
14
+ export * from './formulas/index';