@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,135 @@
1
+ import { IBasicFormula } from '../common/index';
2
+ import { FormulaOwner } from './formula-owner';
3
+ import { FormulaModuleBase } from './formula-module-base';
4
+ /**
5
+ * Core descriptive statistics: averages, counts, min/max, and basic range summaries.
6
+ *
7
+ * Registers 11 functions including AVERAGE, AVERAGEIF, AVERAGEA, AVERAGEIFS, COUNT, and others.
8
+ *
9
+ * @hidden
10
+ */
11
+ export declare class StatisticalFormulas 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
+ * The sum of the numbers divided by how many numbers are being averaged.
21
+ *
22
+ * Excel: `AVERAGE(...)`.
23
+ *
24
+ * @hidden
25
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
26
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * engine.computeFormula('=AVERAGE(1,2,3)');
31
+ * ```
32
+ */
33
+ ComputeAVERAGE(...args: string[]): string;
34
+ /**
35
+ * Computes the average of the numbers in a range that meet the supplied criteria.
36
+ *
37
+ * Excel: `AVERAGEIF(...)`.
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
+ ComputeAVERAGEIF(...args: string[]): string | number;
44
+ /**
45
+ * Calculates the average of values in the list of arguments.Arguments can be numbers, names, arrays or references.
46
+ *
47
+ * Excel: `AVERAGEA(...)`.
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
+ ComputeAVERAGEA(...args: string[]): number | string;
54
+ private processLogicalCellValue;
55
+ /**
56
+ * Conditionally returns the average of the contents of cells for the set of ranges.
57
+ *
58
+ * Excel: `AVERAGEIFS(...)`.
59
+ *
60
+ * @hidden
61
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
62
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
63
+ */
64
+ ComputeAVERAGEIFS(...args: string[]): number | string;
65
+ /**
66
+ * Counts the numbers in the list of arguments, exclude text entries.
67
+ *
68
+ * Excel: `COUNT(...)`.
69
+ *
70
+ * @hidden
71
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
72
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
73
+ */
74
+ ComputeCOUNT(...args: string[]): number | string;
75
+ /**
76
+ * Counts the non-empty values in the list of arguments.
77
+ *
78
+ * Excel: `COUNTA(...)`.
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
+ ComputeCOUNTA(...args: string[]): number | string;
85
+ /**
86
+ * Counts the number of cells in a range that meet a specified condition.
87
+ *
88
+ * Excel: `COUNTIF(...)`.
89
+ *
90
+ * @hidden
91
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
92
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
93
+ */
94
+ ComputeCOUNTIF(...args: string[]): number | string;
95
+ /**
96
+ * Counts the number of times each cells in all the ranges that meet the specific conditions.
97
+ *
98
+ * Excel: `COUNTIFS(...)`.
99
+ *
100
+ * @hidden
101
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
102
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
103
+ */
104
+ ComputeCOUNTIFS(...args: string[]): number | string;
105
+ /**
106
+ * Returns the number of empty cells in a specified range of cells.
107
+ *
108
+ * Excel: `COUNTBLANK(...)`.
109
+ *
110
+ * @hidden
111
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
112
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
113
+ */
114
+ ComputeCOUNTBLANK(...args: string[]): string | number;
115
+ /**
116
+ * Returns the smaller number in set of arguments.
117
+ *
118
+ * Excel: `MIN(...)`.
119
+ *
120
+ * @hidden
121
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
122
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
123
+ */
124
+ ComputeMIN(...args: string[]): string;
125
+ /**
126
+ * Returns the largest number in set of arguments.
127
+ *
128
+ * Excel: `MAX(...)`.
129
+ *
130
+ * @hidden
131
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
132
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
133
+ */
134
+ ComputeMAX(...args: string[]): string;
135
+ }
@@ -0,0 +1,542 @@
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 { FormulaModuleBase } from './formula-module-base';
17
+ /**
18
+ * Core descriptive statistics: averages, counts, min/max, and basic range summaries.
19
+ *
20
+ * Registers 11 functions including AVERAGE, AVERAGEIF, AVERAGEA, AVERAGEIFS, COUNT, and others.
21
+ *
22
+ * @hidden
23
+ */
24
+ var StatisticalFormulas = /** @class */ (function (_super) {
25
+ __extends(StatisticalFormulas, _super);
26
+ /**
27
+ * @hidden
28
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
29
+ */
30
+ function StatisticalFormulas(owner) {
31
+ var _this = _super.call(this, owner) || this;
32
+ /** Formula definitions registered with {@link BasicFormulas}. */
33
+ _this.formulas = [
34
+ { formulaName: 'AVERAGE', category: 'Statistical', description: 'The sum of the numbers divided by how many numbers are being averaged.' },
35
+ { formulaName: 'AVERAGEIF', category: 'Statistical', description: 'Computes the average of the numbers in a range that meet the supplied criteria.' },
36
+ { formulaName: 'AVERAGEA', category: 'Statistical', description: 'Calculates the average of values in the list of arguments.Arguments can be numbers, names, arrays or references.' },
37
+ { formulaName: 'AVERAGEIFS', category: 'Statistical', description: 'Conditionally returns the average of the contents of cells for the set of ranges.' },
38
+ { formulaName: 'COUNT', category: 'Statistical', description: 'Counts the numbers in the list of arguments, exclude text entries.' },
39
+ { formulaName: 'COUNTA', category: 'Statistical', description: 'Counts the non-empty values in the list of arguments.' },
40
+ { formulaName: 'COUNTIF', category: 'Statistical', description: 'Counts the number of cells in a range that meet a specified condition.' },
41
+ { formulaName: 'COUNTIFS', category: 'Statistical', description: 'Counts the number of times each cells in all the ranges that meet the specific conditions.' },
42
+ { formulaName: 'COUNTBLANK', category: 'Statistical', description: 'Returns the number of empty cells in a specified range of cells.' },
43
+ { formulaName: 'MIN', category: 'Statistical', description: 'Returns the smaller number in set of arguments.' },
44
+ { formulaName: 'MAX', category: 'Statistical', description: 'Returns the largest number in set of arguments.' }
45
+ ];
46
+ return _this;
47
+ }
48
+ /**
49
+ * The sum of the numbers divided by how many numbers are being averaged.
50
+ *
51
+ * Excel: `AVERAGE(...)`.
52
+ *
53
+ * @hidden
54
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
55
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * engine.computeFormula('=AVERAGE(1,2,3)');
60
+ * ```
61
+ */
62
+ StatisticalFormulas.prototype.ComputeAVERAGE = function () {
63
+ var args = [];
64
+ for (var _i = 0; _i < arguments.length; _i++) {
65
+ args[_i] = arguments[_i];
66
+ }
67
+ var isSubtotalFormula = false;
68
+ if (args.length) {
69
+ var lastArgument = args[args.length - 1];
70
+ if (lastArgument === 'isSubtotal') {
71
+ isSubtotalFormula = true;
72
+ args.pop();
73
+ }
74
+ }
75
+ if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
76
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
77
+ }
78
+ var argArr = args;
79
+ for (var i = 0; i < argArr.length; i++) {
80
+ if (argArr[i].indexOf(':') > -1) {
81
+ if (argArr[i].indexOf(this.parent.tic) > -1) {
82
+ return this.parent.getErrorStrings()[CommonErrors.Value];
83
+ }
84
+ }
85
+ }
86
+ return this.parent.calculateAvg(argArr, isSubtotalFormula);
87
+ };
88
+ /**
89
+ * Computes the average of the numbers in a range that meet the supplied criteria.
90
+ *
91
+ * Excel: `AVERAGEIF(...)`.
92
+ *
93
+ * @hidden
94
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
95
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
96
+ */
97
+ StatisticalFormulas.prototype.ComputeAVERAGEIF = function () {
98
+ var args = [];
99
+ for (var _i = 0; _i < arguments.length; _i++) {
100
+ args[_i] = arguments[_i];
101
+ }
102
+ var argList = args;
103
+ if (argList[0].indexOf(':') < 0 && !this.parent.isCellReference(argList[0])) {
104
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.ImproperFormula];
105
+ }
106
+ var resultVal = this.parent.computeSumIfAndAvgIf(args, true);
107
+ if (resultVal[1] === 0 || resultVal[0].toString() === 'NaN') {
108
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.Div];
109
+ }
110
+ if (typeof resultVal === 'string' && (this.parent.formulaErrorStrings.indexOf(resultVal)
111
+ || this.parent.getErrorStrings().indexOf(resultVal))) {
112
+ return resultVal;
113
+ }
114
+ return this.parent.parseFloat(resultVal[0]) / this.parent.parseFloat(resultVal[1]);
115
+ };
116
+ /**
117
+ * Calculates the average of values in the list of arguments.Arguments can be numbers, names, arrays or references.
118
+ *
119
+ * Excel: `AVERAGEA(...)`.
120
+ *
121
+ * @hidden
122
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
123
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
124
+ */
125
+ StatisticalFormulas.prototype.ComputeAVERAGEA = function () {
126
+ var args = [];
127
+ for (var _i = 0; _i < arguments.length; _i++) {
128
+ args[_i] = arguments[_i];
129
+ }
130
+ if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
131
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
132
+ }
133
+ var argArrs = args;
134
+ var cellCol;
135
+ var result = 0;
136
+ var cellValue;
137
+ var value;
138
+ var length = 0;
139
+ var parseValue;
140
+ for (var k = 0; k < argArrs.length; k++) {
141
+ if (this.parent.isCellReference(argArrs[k])) {
142
+ if (argArrs[k].indexOf(':') > -1) {
143
+ cellCol = this.parent.getCellCollection(argArrs[k].split(this.parent.tic).join(''));
144
+ for (var j = 0; j < cellCol.length; j++) {
145
+ cellValue = this.parent.getValueFromArg(cellCol[j]);
146
+ cellValue = this.processLogicalCellValue(cellValue);
147
+ if (this.parent.getErrorStrings().indexOf(cellValue) > -1) {
148
+ return cellValue;
149
+ }
150
+ else if (isNullOrUndefined(cellValue) || cellValue === '') {
151
+ continue;
152
+ }
153
+ parseValue = this.parent.parseFloat(cellValue);
154
+ cellValue = !isNaN(parseValue) ? parseValue : 0;
155
+ result += cellValue;
156
+ length = length + 1;
157
+ }
158
+ }
159
+ else {
160
+ cellValue = this.parent.getValueFromArg(argArrs[k]);
161
+ cellValue = this.processLogicalCellValue(cellValue);
162
+ if (this.parent.getErrorStrings().indexOf(cellValue) > -1) {
163
+ return cellValue;
164
+ }
165
+ else if (isNullOrUndefined(cellValue) || cellValue === '') {
166
+ continue;
167
+ }
168
+ parseValue = this.parent.parseFloat(cellValue);
169
+ cellValue = !isNaN(parseValue) ? parseValue : 0;
170
+ result += cellValue;
171
+ length = length + 1;
172
+ }
173
+ }
174
+ else {
175
+ if (argArrs[k].indexOf(this.parent.tic) > -1) {
176
+ if (isNaN(this.parent.parseFloat(argArrs[k].split(this.parent.tic).join(''))) ||
177
+ argArrs[k].split(this.parent.tic).join('').trim() === '') {
178
+ return this.parent.getErrorStrings()[CommonErrors.Value];
179
+ }
180
+ }
181
+ argArrs[k] = this.processLogicalCellValue(argArrs[k]);
182
+ value = this.parent.getValueFromArg(argArrs[k].split(this.parent.tic).join(''));
183
+ if (this.parent.getErrorStrings().indexOf(value) > -1) {
184
+ return value;
185
+ }
186
+ result += this.parent.parseFloat(value);
187
+ length = length + 1;
188
+ }
189
+ }
190
+ if (length === 0) {
191
+ return this.parent.getErrorStrings()[CommonErrors.DivZero];
192
+ }
193
+ return result / length;
194
+ };
195
+ StatisticalFormulas.prototype.processLogicalCellValue = function (cellValue) {
196
+ var value = cellValue;
197
+ if (value.toUpperCase() === this.parent.trueValue) {
198
+ value = '1';
199
+ }
200
+ else if (value.toUpperCase() === this.parent.falseValue) {
201
+ value = '0';
202
+ }
203
+ return value;
204
+ };
205
+ /**
206
+ * Conditionally returns the average of the contents of cells for the set of ranges.
207
+ *
208
+ * Excel: `AVERAGEIFS(...)`.
209
+ *
210
+ * @hidden
211
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
212
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
213
+ */
214
+ StatisticalFormulas.prototype.ComputeAVERAGEIFS = function () {
215
+ var args = [];
216
+ for (var _i = 0; _i < arguments.length; _i++) {
217
+ args[_i] = arguments[_i];
218
+ }
219
+ var sum = this.calculateIFS(args, this.parent.trueValue);
220
+ return sum;
221
+ };
222
+ /**
223
+ * Counts the numbers in the list of arguments, exclude text entries.
224
+ *
225
+ * Excel: `COUNT(...)`.
226
+ *
227
+ * @hidden
228
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
229
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
230
+ */
231
+ StatisticalFormulas.prototype.ComputeCOUNT = function () {
232
+ var args = [];
233
+ for (var _i = 0; _i < arguments.length; _i++) {
234
+ args[_i] = arguments[_i];
235
+ }
236
+ var isSubtotalFormula = false;
237
+ if (args.length && args[args.length - 1] === 'isSubtotal') {
238
+ isSubtotalFormula = true;
239
+ args.pop();
240
+ }
241
+ if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
242
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
243
+ }
244
+ var argArr = args;
245
+ var argVal;
246
+ var cellColl;
247
+ var result = 0;
248
+ var cellValue;
249
+ var value;
250
+ for (var i = 0; i < argArr.length; i++) {
251
+ argVal = argArr[i];
252
+ if (this.parent.isCellReference(argVal)) {
253
+ if (argVal.indexOf(':') > -1) {
254
+ cellColl = this.parent.getCellCollection(argVal.split(this.parent.tic).join(''));
255
+ for (var j = 0; j < cellColl.length; j++) {
256
+ cellValue = !isSubtotalFormula ? this.parent.getValueFromArg(cellColl[j]) :
257
+ this.parent.getValueFromArg(cellColl[j], null, null, true);
258
+ if (isSubtotalFormula && cellValue.includes('SUBTOTAL(')) {
259
+ continue;
260
+ }
261
+ if (!isNaN(this.parent.parseFloat(cellValue))) {
262
+ if (argVal.length > 0 && cellValue.trim() !== '') {
263
+ result++;
264
+ }
265
+ }
266
+ }
267
+ }
268
+ else {
269
+ cellValue = !isSubtotalFormula ? this.parent.getValueFromArg(argVal) :
270
+ this.parent.getValueFromArg(argVal, null, null, true);
271
+ if (isSubtotalFormula && cellValue.includes('SUBTOTAL(')) {
272
+ continue;
273
+ }
274
+ if (!isNaN(this.parent.parseFloat(cellValue))) {
275
+ if (argVal.length > 0 && cellValue.trim() !== '') {
276
+ result++;
277
+ }
278
+ }
279
+ }
280
+ }
281
+ else {
282
+ value = this.parent.getValueFromArg(argVal).split(this.parent.tic).join('');
283
+ if (argVal.length === 0 && value.trim() === '') {
284
+ result++;
285
+ }
286
+ else if (!isNaN(this.parent.parseFloat(value)) || argVal === this.parent.trueValue || argVal === this.parent.falseValue) {
287
+ if (argVal.length > 0 && argVal.trim() !== '' && value.trim() !== '') {
288
+ result++;
289
+ }
290
+ }
291
+ }
292
+ }
293
+ return result;
294
+ };
295
+ /**
296
+ * Counts the non-empty values in the list of arguments.
297
+ *
298
+ * Excel: `COUNTA(...)`.
299
+ *
300
+ * @hidden
301
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
302
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
303
+ */
304
+ StatisticalFormulas.prototype.ComputeCOUNTA = function () {
305
+ var args = [];
306
+ for (var _i = 0; _i < arguments.length; _i++) {
307
+ args[_i] = arguments[_i];
308
+ }
309
+ var isSubtotalFormula = false;
310
+ if (args.length) {
311
+ var lastArgument = args[args.length - 1];
312
+ if (lastArgument === 'isSubtotal') {
313
+ isSubtotalFormula = true;
314
+ args.pop();
315
+ }
316
+ }
317
+ if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
318
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
319
+ }
320
+ var argArr = args;
321
+ var cellColl;
322
+ var result = 0;
323
+ var cellValue;
324
+ var value;
325
+ for (var i = 0; i < argArr.length; i++) {
326
+ if (this.parent.isCellReference(argArr[i])) {
327
+ if (argArr[i].indexOf(':') > -1) {
328
+ cellColl = this.parent.getCellCollection(argArr[i].split(this.parent.tic).join(''));
329
+ for (var j = 0; j < cellColl.length; j++) {
330
+ cellValue = !isSubtotalFormula ? this.parent.getValueFromArg(cellColl[j]) :
331
+ this.parent.getValueFromArg(cellColl[j], null, null, true);
332
+ if (isSubtotalFormula && cellValue.includes('SUBTOTAL(')) {
333
+ continue;
334
+ }
335
+ if (cellValue.length > 0) {
336
+ result++;
337
+ }
338
+ }
339
+ }
340
+ else {
341
+ cellValue = !isSubtotalFormula ? this.parent.getValueFromArg(argArr[i]) :
342
+ this.parent.getValueFromArg(argArr[i], null, null, true);
343
+ if (isSubtotalFormula && cellValue.includes('SUBTOTAL(')) {
344
+ continue;
345
+ }
346
+ if (cellValue.length > 0) {
347
+ result++;
348
+ }
349
+ }
350
+ }
351
+ else {
352
+ value = this.parent.getValueFromArg(argArr[i]).split(this.parent.tic).join('');
353
+ if (value.length > 0) {
354
+ result++;
355
+ }
356
+ else if (value.length === 0 && value.trim() === '') {
357
+ result++;
358
+ }
359
+ }
360
+ }
361
+ return result;
362
+ };
363
+ /**
364
+ * Counts the number of cells in a range that meet a specified condition.
365
+ *
366
+ * Excel: `COUNTIF(...)`.
367
+ *
368
+ * @hidden
369
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
370
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
371
+ */
372
+ StatisticalFormulas.prototype.ComputeCOUNTIF = function () {
373
+ var args = [];
374
+ for (var _i = 0; _i < arguments.length; _i++) {
375
+ args[_i] = arguments[_i];
376
+ }
377
+ var argArr = args;
378
+ if (isNullOrUndefined(args) || args[0] === '' || argArr.length !== 2) {
379
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
380
+ }
381
+ if (argArr[0].indexOf(':') < 0 && !this.parent.isCellReference(argArr[0])) {
382
+ return this.parent.getErrorStrings()[CommonErrors.Name];
383
+ }
384
+ var cellColl;
385
+ var result = 0;
386
+ var cellValue;
387
+ var stack = [];
388
+ var op = 'equal';
389
+ if (argArr[1] === '') {
390
+ return 0;
391
+ }
392
+ var isStringVal = argArr[1].startsWith(this.parent.tic) && argArr[1].endsWith(this.parent.tic);
393
+ var condition = this.parent.getANDComputedValue(argArr[1]);
394
+ var isAsterisk = condition.includes('*');
395
+ var isAsteriskOnly = condition === '*' || condition === '<>*';
396
+ var criteriaValue = isAsterisk && !isAsteriskOnly ? condition.replace(/\*/g, '').trim() : condition;
397
+ var isCellReferenceValue = false;
398
+ if (!isStringVal && this.parent.isCellReference(criteriaValue)) {
399
+ criteriaValue = this.parent.getValueFromArg(criteriaValue);
400
+ isCellReferenceValue = true;
401
+ }
402
+ if (isAsterisk && !isAsteriskOnly) {
403
+ var asteriskIndex = condition.indexOf('*');
404
+ if (condition[0] === '*') {
405
+ criteriaValue = '*' + criteriaValue;
406
+ }
407
+ if (condition[condition.length - 1] === '*') {
408
+ criteriaValue += '*';
409
+ }
410
+ if (asteriskIndex > 0 && asteriskIndex < condition.length - 1) {
411
+ criteriaValue = condition.substring(0, asteriskIndex) + '*' + condition.substring(asteriskIndex + 1);
412
+ }
413
+ }
414
+ condition = criteriaValue;
415
+ if (condition.startsWith('<=')) {
416
+ op = 'lessEq';
417
+ condition = condition.substring(2);
418
+ }
419
+ else if (condition.startsWith('>=')) {
420
+ op = 'greaterEq';
421
+ condition = condition.substring(2);
422
+ }
423
+ else if (condition.startsWith('<>')) {
424
+ op = 'notEq';
425
+ condition = condition.substring(2);
426
+ }
427
+ else if (condition.startsWith('<')) {
428
+ op = 'less';
429
+ condition = condition.substring(1);
430
+ }
431
+ else if (condition.startsWith('>')) {
432
+ op = 'greater';
433
+ condition = condition.substring(1);
434
+ }
435
+ else if (condition.startsWith('=')) {
436
+ op = 'equal';
437
+ condition = condition.substring(1);
438
+ }
439
+ var isWildCardCondition = condition.indexOf('*') > -1 || condition.indexOf('?') > -1;
440
+ if ((!isStringVal && this.parent.isCellReference(condition) && !isCellReferenceValue) || condition.includes(this.parent.arithMarker)
441
+ || (condition.includes(this.parent.getParseDecimalSeparator()) && !isWildCardCondition)) {
442
+ condition = this.parent.getValueFromArg(condition);
443
+ }
444
+ if (this.parent.isCellReference(argArr[0])) {
445
+ cellColl = this.parent.getCellCollection(argArr[0].split(this.parent.tic).join(''));
446
+ for (var j = 0; j < cellColl.length; j++) {
447
+ cellValue = this.parent.getValueFromArg(cellColl[j]);
448
+ if (isWildCardCondition) {
449
+ cellValue = this.parent.findWildCardValue(condition.toLowerCase(), cellValue.toLowerCase());
450
+ }
451
+ stack.push(cellValue);
452
+ stack.push(condition);
453
+ if (this.parent.processLogical(stack, op) === this.parent.trueValue) {
454
+ result++;
455
+ }
456
+ }
457
+ }
458
+ return result;
459
+ };
460
+ /**
461
+ * Counts the number of times each cells in all the ranges that meet the specific conditions.
462
+ *
463
+ * Excel: `COUNTIFS(...)`.
464
+ *
465
+ * @hidden
466
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
467
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
468
+ */
469
+ StatisticalFormulas.prototype.ComputeCOUNTIFS = function () {
470
+ var args = [];
471
+ for (var _i = 0; _i < arguments.length; _i++) {
472
+ args[_i] = arguments[_i];
473
+ }
474
+ var sum = this.parent.computeCountIfsFormulas(args);
475
+ return sum;
476
+ };
477
+ /**
478
+ * Returns the number of empty cells in a specified range of cells.
479
+ *
480
+ * Excel: `COUNTBLANK(...)`.
481
+ *
482
+ * @hidden
483
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
484
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
485
+ */
486
+ StatisticalFormulas.prototype.ComputeCOUNTBLANK = function () {
487
+ var args = [];
488
+ for (var _i = 0; _i < arguments.length; _i++) {
489
+ args[_i] = arguments[_i];
490
+ }
491
+ var result = 0;
492
+ if (args.length !== 1 || isNullOrUndefined(args) || !this.parent.isCellReference(args[0])) {
493
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
494
+ }
495
+ else if (args[0] === '') {
496
+ return this.parent.getErrorStrings()[CommonErrors.Value];
497
+ }
498
+ else {
499
+ var cellRange = this.parent.getCellCollection(args[0]);
500
+ for (var i = 0; i < cellRange.length; i++) {
501
+ if (this.parent.getValueFromArg(cellRange[i]) === '') {
502
+ result++;
503
+ }
504
+ }
505
+ }
506
+ return result;
507
+ };
508
+ /**
509
+ * Returns the smaller number in set of arguments.
510
+ *
511
+ * Excel: `MIN(...)`.
512
+ *
513
+ * @hidden
514
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
515
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
516
+ */
517
+ StatisticalFormulas.prototype.ComputeMIN = function () {
518
+ var args = [];
519
+ for (var _i = 0; _i < arguments.length; _i++) {
520
+ args[_i] = arguments[_i];
521
+ }
522
+ return this.parent.computeMinMax(args, 'min');
523
+ };
524
+ /**
525
+ * Returns the largest number in set of arguments.
526
+ *
527
+ * Excel: `MAX(...)`.
528
+ *
529
+ * @hidden
530
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
531
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
532
+ */
533
+ StatisticalFormulas.prototype.ComputeMAX = function () {
534
+ var args = [];
535
+ for (var _i = 0; _i < arguments.length; _i++) {
536
+ args[_i] = arguments[_i];
537
+ }
538
+ return this.parent.computeMinMax(args, 'max');
539
+ };
540
+ return StatisticalFormulas;
541
+ }(FormulaModuleBase));
542
+ export { StatisticalFormulas };