@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.
- package/.eslintrc.json +263 -0
- package/README.md +132 -0
- package/base.d.ts +4 -0
- package/base.js +4 -0
- package/common.d.ts +4 -0
- package/common.js +4 -0
- package/dist/ej2-calculate.umd.min.js +11 -0
- package/dist/ej2-calculate.umd.min.js.map +1 -0
- package/dist/es6/ej2-calculate.es2015.js +24801 -0
- package/dist/es6/ej2-calculate.es2015.js.map +1 -0
- package/dist/es6/ej2-calculate.es5.js +27229 -0
- package/dist/es6/ej2-calculate.es5.js.map +1 -0
- package/dist/global/ej2-calculate.min.js +11 -0
- package/dist/global/ej2-calculate.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/formulas.d.ts +4 -0
- package/formulas.js +4 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +30 -0
- package/src/base/calculate-model.d.ts +4 -0
- package/src/base/calculate-model.js +0 -0
- package/src/base/calculate.d.ts +1105 -0
- package/src/base/calculate.js +4720 -0
- package/src/base/index.d.ts +8 -0
- package/src/base/index.js +7 -0
- package/src/base/parser.d.ts +208 -0
- package/src/base/parser.js +1512 -0
- package/src/common/address.d.ts +59 -0
- package/src/common/address.js +96 -0
- package/src/common/cell-ref.d.ts +32 -0
- package/src/common/cell-ref.js +112 -0
- package/src/common/common.d.ts +44 -0
- package/src/common/common.js +134 -0
- package/src/common/enum.d.ts +94 -0
- package/src/common/enum.js +97 -0
- package/src/common/index.d.ts +9 -0
- package/src/common/index.js +8 -0
- package/src/common/interface.d.ts +122 -0
- package/src/common/interface.js +0 -0
- package/src/common/l10n.d.ts +24 -0
- package/src/common/l10n.js +54 -0
- package/src/common/number-date.d.ts +26 -0
- package/src/common/number-date.js +38 -0
- package/src/common/sheet-info.d.ts +10 -0
- package/src/common/sheet-info.js +17 -0
- package/src/common/sort.d.ts +17 -0
- package/src/common/sort.js +44 -0
- package/src/formulas/array.d.ts +47 -0
- package/src/formulas/array.js +718 -0
- package/src/formulas/basic.d.ts +47 -0
- package/src/formulas/basic.js +181 -0
- package/src/formulas/complex-numbers.d.ts +207 -0
- package/src/formulas/complex-numbers.js +549 -0
- package/src/formulas/database.d.ts +152 -0
- package/src/formulas/database.js +579 -0
- package/src/formulas/date-time-extra.d.ts +97 -0
- package/src/formulas/date-time-extra.js +415 -0
- package/src/formulas/date-time-intl.d.ts +57 -0
- package/src/formulas/date-time-intl.js +309 -0
- package/src/formulas/date-time.d.ts +164 -0
- package/src/formulas/date-time.js +1021 -0
- package/src/formulas/engineering-base.d.ts +150 -0
- package/src/formulas/engineering-base.js +404 -0
- package/src/formulas/engineering-bessel.d.ts +65 -0
- package/src/formulas/engineering-bessel.js +167 -0
- package/src/formulas/engineering-convert.d.ts +35 -0
- package/src/formulas/engineering-convert.js +120 -0
- package/src/formulas/engineering-misc.d.ts +64 -0
- package/src/formulas/engineering-misc.js +168 -0
- package/src/formulas/financial-amortization-ecma.d.ts +87 -0
- package/src/formulas/financial-amortization-ecma.js +288 -0
- package/src/formulas/financial-annuity.d.ts +104 -0
- package/src/formulas/financial-annuity.js +419 -0
- package/src/formulas/financial-bond-helpers.d.ts +106 -0
- package/src/formulas/financial-bond-helpers.js +190 -0
- package/src/formulas/financial-cashflow.d.ts +47 -0
- package/src/formulas/financial-cashflow.js +203 -0
- package/src/formulas/financial-coupons.d.ts +227 -0
- package/src/formulas/financial-coupons.js +810 -0
- package/src/formulas/financial-depreciation.d.ts +64 -0
- package/src/formulas/financial-depreciation.js +247 -0
- package/src/formulas/financial-rates.d.ts +54 -0
- package/src/formulas/financial-rates.js +140 -0
- package/src/formulas/financial-securities.d.ts +126 -0
- package/src/formulas/financial-securities.js +488 -0
- package/src/formulas/formula-math-helpers.d.ts +212 -0
- package/src/formulas/formula-math-helpers.js +599 -0
- package/src/formulas/formula-module-base.d.ts +54 -0
- package/src/formulas/formula-module-base.js +125 -0
- package/src/formulas/formula-owner.d.ts +17 -0
- package/src/formulas/formula-owner.js +0 -0
- package/src/formulas/index.d.ts +68 -0
- package/src/formulas/index.js +67 -0
- package/src/formulas/information-advanced.d.ts +44 -0
- package/src/formulas/information-advanced.js +157 -0
- package/src/formulas/information-ecma.d.ts +33 -0
- package/src/formulas/information-ecma.js +88 -0
- package/src/formulas/information-extra.d.ts +146 -0
- package/src/formulas/information-extra.js +351 -0
- package/src/formulas/information.d.ts +34 -0
- package/src/formulas/information.js +78 -0
- package/src/formulas/logical-extra.d.ts +75 -0
- package/src/formulas/logical-extra.js +217 -0
- package/src/formulas/logical.d.ts +83 -0
- package/src/formulas/logical.js +296 -0
- package/src/formulas/lookup-array.d.ts +98 -0
- package/src/formulas/lookup-array.js +364 -0
- package/src/formulas/lookup-ref-extra.d.ts +64 -0
- package/src/formulas/lookup-ref-extra.js +180 -0
- package/src/formulas/lookup-ref.d.ts +84 -0
- package/src/formulas/lookup-ref.js +263 -0
- package/src/formulas/lookup.d.ts +114 -0
- package/src/formulas/lookup.js +881 -0
- package/src/formulas/math-aggregate.d.ts +74 -0
- package/src/formulas/math-aggregate.js +376 -0
- package/src/formulas/math-ceiling-ecma.d.ts +42 -0
- package/src/formulas/math-ceiling-ecma.js +123 -0
- package/src/formulas/math-combinatorics.d.ts +75 -0
- package/src/formulas/math-combinatorics.js +290 -0
- package/src/formulas/math-misc.d.ts +164 -0
- package/src/formulas/math-misc.js +889 -0
- package/src/formulas/math-number.d.ts +76 -0
- package/src/formulas/math-number.js +261 -0
- package/src/formulas/math-rounding.d.ts +115 -0
- package/src/formulas/math-rounding.js +728 -0
- package/src/formulas/math-trig-hyperbolic.d.ts +55 -0
- package/src/formulas/math-trig-hyperbolic.js +113 -0
- package/src/formulas/math-trig.d.ts +165 -0
- package/src/formulas/math-trig.js +334 -0
- package/src/formulas/matrix-base.d.ts +13 -0
- package/src/formulas/matrix-base.js +169 -0
- package/src/formulas/matrix.d.ts +64 -0
- package/src/formulas/matrix.js +161 -0
- package/src/formulas/regression-ecma.d.ts +66 -0
- package/src/formulas/regression-ecma.js +234 -0
- package/src/formulas/statistical-advanced.d.ts +125 -0
- package/src/formulas/statistical-advanced.js +756 -0
- package/src/formulas/statistical-correlation.d.ts +75 -0
- package/src/formulas/statistical-correlation.js +198 -0
- package/src/formulas/statistical-dispersion.d.ts +108 -0
- package/src/formulas/statistical-dispersion.js +337 -0
- package/src/formulas/statistical-distribution-extended.d.ts +176 -0
- package/src/formulas/statistical-distribution-extended.js +668 -0
- package/src/formulas/statistical-distribution.d.ts +104 -0
- package/src/formulas/statistical-distribution.js +368 -0
- package/src/formulas/statistical-ecma.d.ts +95 -0
- package/src/formulas/statistical-ecma.js +392 -0
- package/src/formulas/statistical-extended.d.ts +136 -0
- package/src/formulas/statistical-extended.js +340 -0
- package/src/formulas/statistical-ifs.d.ts +46 -0
- package/src/formulas/statistical-ifs.js +180 -0
- package/src/formulas/statistical-moments.d.ts +84 -0
- package/src/formulas/statistical-moments.js +269 -0
- package/src/formulas/statistical-percentile.d.ts +56 -0
- package/src/formulas/statistical-percentile.js +195 -0
- package/src/formulas/statistical-sample-base.d.ts +14 -0
- package/src/formulas/statistical-sample-base.js +124 -0
- package/src/formulas/statistical.d.ts +135 -0
- package/src/formulas/statistical.js +542 -0
- package/src/formulas/text-advanced.d.ts +64 -0
- package/src/formulas/text-advanced.js +222 -0
- package/src/formulas/text-ecma.d.ts +54 -0
- package/src/formulas/text-ecma.js +106 -0
- package/src/formulas/text-extra.d.ts +216 -0
- package/src/formulas/text-extra.js +657 -0
- package/src/formulas/text.d.ts +125 -0
- package/src/formulas/text.js +628 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +14 -0
- package/tslint.json +111 -0
|
@@ -0,0 +1,217 @@
|
|
|
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
|
+
* Extended logical helpers including IFS, SWITCH, XOR, and multi-condition boolean tests.
|
|
19
|
+
*
|
|
20
|
+
* Registered functions: TRUE, FALSE, XOR, IFNA, SWITCH.
|
|
21
|
+
*
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
var LogicalExtraFormulas = /** @class */ (function (_super) {
|
|
25
|
+
__extends(LogicalExtraFormulas, _super);
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
29
|
+
*/
|
|
30
|
+
function LogicalExtraFormulas(owner) {
|
|
31
|
+
var _this = _super.call(this, owner) || this;
|
|
32
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
33
|
+
_this.formulas = [
|
|
34
|
+
{ formulaName: 'TRUE', category: 'Logical', description: 'Returns the logical value TRUE.' },
|
|
35
|
+
{ formulaName: 'FALSE', category: 'Logical', description: 'Returns the logical value FALSE.' },
|
|
36
|
+
{ formulaName: 'XOR', category: 'Logical', description: 'Returns a logical exclusive OR of all arguments.' },
|
|
37
|
+
{ formulaName: 'IFNA', category: 'Logical', description: 'Returns the value you specify if the expression resolves to #N/A; otherwise returns the result of the expression.' },
|
|
38
|
+
{ formulaName: 'SWITCH', category: 'Logical', description: 'Evaluates an expression against a list of values and returns the result corresponding to the first matching value.' }
|
|
39
|
+
];
|
|
40
|
+
return _this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the logical value TRUE.
|
|
44
|
+
*
|
|
45
|
+
* Excel: `TRUE(...)`.
|
|
46
|
+
*
|
|
47
|
+
* @hidden
|
|
48
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
49
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* engine.computeFormula('=TRUE(1)');
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
LogicalExtraFormulas.prototype.ComputeTRUE = function () {
|
|
57
|
+
var args = [];
|
|
58
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
59
|
+
args[_i] = arguments[_i];
|
|
60
|
+
}
|
|
61
|
+
if (args && args.length === 1 && args[0] === '') {
|
|
62
|
+
return this.parent.trueValue;
|
|
63
|
+
}
|
|
64
|
+
if (args && args.length > 0 && !(args.length === 1 && args[0] === '')) {
|
|
65
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
66
|
+
}
|
|
67
|
+
return this.parent.trueValue;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Returns the logical value FALSE.
|
|
71
|
+
*
|
|
72
|
+
* Excel: `FALSE(...)`.
|
|
73
|
+
*
|
|
74
|
+
* @hidden
|
|
75
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
76
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
77
|
+
*/
|
|
78
|
+
LogicalExtraFormulas.prototype.ComputeFALSE = function () {
|
|
79
|
+
var args = [];
|
|
80
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
81
|
+
args[_i] = arguments[_i];
|
|
82
|
+
}
|
|
83
|
+
if (args && args.length === 1 && args[0] === '') {
|
|
84
|
+
return this.parent.falseValue;
|
|
85
|
+
}
|
|
86
|
+
if (args && args.length > 0 && !(args.length === 1 && args[0] === '')) {
|
|
87
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
88
|
+
}
|
|
89
|
+
return this.parent.falseValue;
|
|
90
|
+
};
|
|
91
|
+
LogicalExtraFormulas.prototype.isTruthy = function (value) {
|
|
92
|
+
var upper = value.toUpperCase();
|
|
93
|
+
if (upper === this.parent.trueValue) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (upper === this.parent.falseValue || value === '') {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
var num = this.parent.parseFloat(value);
|
|
100
|
+
return !isNaN(num) && num !== 0;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Returns a logical exclusive OR of all arguments.
|
|
104
|
+
*
|
|
105
|
+
* Excel: `XOR(...)`.
|
|
106
|
+
*
|
|
107
|
+
* @hidden
|
|
108
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
109
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
110
|
+
*/
|
|
111
|
+
LogicalExtraFormulas.prototype.ComputeXOR = function () {
|
|
112
|
+
var args = [];
|
|
113
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
114
|
+
args[_i] = arguments[_i];
|
|
115
|
+
}
|
|
116
|
+
var errCollection = this.parent.getErrorStrings();
|
|
117
|
+
if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
|
|
118
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
119
|
+
}
|
|
120
|
+
var trueCount = 0;
|
|
121
|
+
for (var i = 0; i < args.length; i++) {
|
|
122
|
+
var arg = args[i];
|
|
123
|
+
if (this.parent.isCellReference(arg) && arg.indexOf(':') > -1) {
|
|
124
|
+
var cells = this.parent.getCellCollection(arg);
|
|
125
|
+
var list = Array.isArray(cells) ? cells : [cells];
|
|
126
|
+
for (var c = 0; c < list.length; c++) {
|
|
127
|
+
var val = this.parent.getValueFromArg(list[c]);
|
|
128
|
+
if (errCollection.indexOf(val) > -1) {
|
|
129
|
+
return val;
|
|
130
|
+
}
|
|
131
|
+
if (this.isTruthy(val)) {
|
|
132
|
+
trueCount++;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
var val = this.parent.getValueFromArg(arg);
|
|
138
|
+
if (errCollection.indexOf(val) > -1) {
|
|
139
|
+
return val;
|
|
140
|
+
}
|
|
141
|
+
if (this.isTruthy(val)) {
|
|
142
|
+
trueCount++;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return (trueCount % 2 === 1) ? this.parent.trueValue : this.parent.falseValue;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Returns the value you specify if the expression resolves to #N/A; otherwise returns the result of the expression.
|
|
150
|
+
*
|
|
151
|
+
* Excel: `IFNA(...)`.
|
|
152
|
+
*
|
|
153
|
+
* @hidden
|
|
154
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
155
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
156
|
+
*/
|
|
157
|
+
LogicalExtraFormulas.prototype.ComputeIFNA = function () {
|
|
158
|
+
var args = [];
|
|
159
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
160
|
+
args[_i] = arguments[_i];
|
|
161
|
+
}
|
|
162
|
+
if (isNullOrUndefined(args) || args.length !== 2) {
|
|
163
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
164
|
+
}
|
|
165
|
+
var value = this.parent.getValueFromArg(args[0]);
|
|
166
|
+
if (value === this.parent.getErrorStrings()[CommonErrors.NA] || value === '#N/A') {
|
|
167
|
+
return this.parent.getValueFromArg(args[1]);
|
|
168
|
+
}
|
|
169
|
+
return value === '' ? '0' : value;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Evaluates an expression against a list of values and returns the result corresponding to the first matching value.
|
|
173
|
+
*
|
|
174
|
+
* Excel: `SWITCH(...)`.
|
|
175
|
+
*
|
|
176
|
+
* @hidden
|
|
177
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
178
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
179
|
+
*/
|
|
180
|
+
LogicalExtraFormulas.prototype.ComputeSWITCH = function () {
|
|
181
|
+
var args = [];
|
|
182
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
183
|
+
args[_i] = arguments[_i];
|
|
184
|
+
}
|
|
185
|
+
var errCollection = this.parent.getErrorStrings();
|
|
186
|
+
if (isNullOrUndefined(args) || args.length < 3) {
|
|
187
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
188
|
+
}
|
|
189
|
+
var expression = this.parent.getValueFromArg(args[0]);
|
|
190
|
+
if (errCollection.indexOf(expression) > -1) {
|
|
191
|
+
return expression;
|
|
192
|
+
}
|
|
193
|
+
var pairs = Math.floor((args.length - 1) / 2);
|
|
194
|
+
var defaultValue = errCollection[CommonErrors.NA];
|
|
195
|
+
var hasDefault = (args.length - 1) % 2 === 1;
|
|
196
|
+
if (hasDefault) {
|
|
197
|
+
defaultValue = this.parent.getValueFromArg(args[args.length - 1]);
|
|
198
|
+
}
|
|
199
|
+
for (var i = 0; i < pairs; i++) {
|
|
200
|
+
var valueIdx = 1 + i * 2;
|
|
201
|
+
var resultIdx = valueIdx + 1;
|
|
202
|
+
var matchVal = this.parent.getValueFromArg(args[valueIdx]);
|
|
203
|
+
if (errCollection.indexOf(matchVal) > -1) {
|
|
204
|
+
return matchVal;
|
|
205
|
+
}
|
|
206
|
+
if (matchVal === expression ||
|
|
207
|
+
(!isNaN(this.parent.parseFloat(matchVal)) &&
|
|
208
|
+
this.parent.parseFloat(matchVal) === this.parent.parseFloat(expression))) {
|
|
209
|
+
var result = this.parent.getValueFromArg(args[resultIdx]);
|
|
210
|
+
return result === '' ? '0' : this.parent.removeTics(result);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return defaultValue === '' ? '0' : this.parent.removeTics(defaultValue);
|
|
214
|
+
};
|
|
215
|
+
return LogicalExtraFormulas;
|
|
216
|
+
}(FormulaModuleBase));
|
|
217
|
+
export { LogicalExtraFormulas };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { IBasicFormula } from '../common/index';
|
|
2
|
+
import { FormulaOwner } from './formula-owner';
|
|
3
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
4
|
+
/**
|
|
5
|
+
* Boolean logic, conditional branching (IF), and error-coalescing (IFERROR) functions.
|
|
6
|
+
*
|
|
7
|
+
* Registered functions: IF, AND, OR, NOT, IFS, IFERROR.
|
|
8
|
+
*
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export declare class LogicalFormulas 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 one value if a logical expression is TRUE and another if it is FALSE.
|
|
21
|
+
*
|
|
22
|
+
* Excel: `IF(...)`.
|
|
23
|
+
*
|
|
24
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
25
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* engine.computeFormula('=IF(A1>0,"Yes","No")');
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
ComputeIF(...args: string[]): string | number;
|
|
33
|
+
/**
|
|
34
|
+
* Returns TRUE if all the arguments are considered TRUE, and FALSE otherwise.
|
|
35
|
+
*
|
|
36
|
+
* Excel: `AND(...)`.
|
|
37
|
+
*
|
|
38
|
+
* @hidden
|
|
39
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
40
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
41
|
+
*/
|
|
42
|
+
ComputeAND(...args: string[]): string;
|
|
43
|
+
/**
|
|
44
|
+
* Returns TRUE if any arguments considered TRUE, and all the arguments are FALSE it will return FALSE.
|
|
45
|
+
*
|
|
46
|
+
* Excel: `OR(...)`.
|
|
47
|
+
*
|
|
48
|
+
* @hidden
|
|
49
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
50
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
51
|
+
*/
|
|
52
|
+
ComputeOR(...args: string[]): string;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the inverse of a given logical expression.
|
|
55
|
+
*
|
|
56
|
+
* Excel: `NOT(...)`.
|
|
57
|
+
*
|
|
58
|
+
* @hidden
|
|
59
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
60
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
61
|
+
*/
|
|
62
|
+
ComputeNOT(...args: string[]): string;
|
|
63
|
+
/**
|
|
64
|
+
* Checks multiple conditions and returns a value corresponding to the first TRUE result.
|
|
65
|
+
*
|
|
66
|
+
* Excel: `IFS(...)`.
|
|
67
|
+
*
|
|
68
|
+
* @hidden
|
|
69
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
70
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
71
|
+
*/
|
|
72
|
+
ComputeIFS(...args: string[]): string | number;
|
|
73
|
+
/**
|
|
74
|
+
* Returns a value you specify if a formula evaluates to an error; otherwise, it returns the result of the formula.
|
|
75
|
+
*
|
|
76
|
+
* Excel: `IFERROR(...)`.
|
|
77
|
+
*
|
|
78
|
+
* @hidden
|
|
79
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
80
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
81
|
+
*/
|
|
82
|
+
ComputeIFERROR(...args: string[]): number | string;
|
|
83
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
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 { isNumber } from '../common/number-date';
|
|
17
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
18
|
+
/**
|
|
19
|
+
* Boolean logic, conditional branching (IF), and error-coalescing (IFERROR) functions.
|
|
20
|
+
*
|
|
21
|
+
* Registered functions: IF, AND, OR, NOT, IFS, IFERROR.
|
|
22
|
+
*
|
|
23
|
+
* @hidden
|
|
24
|
+
*/
|
|
25
|
+
var LogicalFormulas = /** @class */ (function (_super) {
|
|
26
|
+
__extends(LogicalFormulas, _super);
|
|
27
|
+
/**
|
|
28
|
+
* @hidden
|
|
29
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
30
|
+
*/
|
|
31
|
+
function LogicalFormulas(owner) {
|
|
32
|
+
var _this = _super.call(this, owner) || this;
|
|
33
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
34
|
+
_this.formulas = [
|
|
35
|
+
{ formulaName: 'IF', category: 'Logical', description: 'Returns one value if a logical expression is TRUE and another if it is FALSE' },
|
|
36
|
+
{ formulaName: 'AND', category: 'Logical', description: 'Returns TRUE if all the arguments are considered TRUE, and FALSE otherwise.' },
|
|
37
|
+
{ formulaName: 'OR', category: 'Logical', description: 'Returns TRUE if any arguments considered TRUE, and all the arguments are FALSE it will return FALSE.' },
|
|
38
|
+
{ formulaName: 'NOT', category: 'Logical', description: 'Returns the inverse of a given logical expression.' },
|
|
39
|
+
{ formulaName: 'IFS', category: 'Logical', description: 'Checks multiple conditions and returns a value corresponding to the first TRUE result.' },
|
|
40
|
+
{ formulaName: 'IFERROR', category: 'Logical', description: 'Returns a value you specify if a formula evaluates to an error; otherwise, it returns the result of the formula.' }
|
|
41
|
+
];
|
|
42
|
+
return _this;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns one value if a logical expression is TRUE and another if it is FALSE.
|
|
46
|
+
*
|
|
47
|
+
* Excel: `IF(...)`.
|
|
48
|
+
*
|
|
49
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
50
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* engine.computeFormula('=IF(A1>0,"Yes","No")');
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
LogicalFormulas.prototype.ComputeIF = function () {
|
|
58
|
+
var args = [];
|
|
59
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
60
|
+
args[_i] = arguments[_i];
|
|
61
|
+
}
|
|
62
|
+
var nestedFormula;
|
|
63
|
+
if (args.length && args[args.length - 1] === 'nestedFormulaTrue') {
|
|
64
|
+
nestedFormula = true;
|
|
65
|
+
args.pop();
|
|
66
|
+
}
|
|
67
|
+
if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
|
|
68
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
69
|
+
}
|
|
70
|
+
if (this.parent.getErrorStrings().indexOf(args[0]) > -1) {
|
|
71
|
+
return args[0];
|
|
72
|
+
}
|
|
73
|
+
var argArr = args;
|
|
74
|
+
var skipTick;
|
|
75
|
+
if (argArr.length === 4 && argArr[3] === 'nestedFormulaTrue') {
|
|
76
|
+
skipTick = true;
|
|
77
|
+
argArr.pop();
|
|
78
|
+
}
|
|
79
|
+
var condition;
|
|
80
|
+
var result;
|
|
81
|
+
if (argArr.length > 3 || argArr.length === 1) {
|
|
82
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
83
|
+
}
|
|
84
|
+
else if (argArr.length <= 3) {
|
|
85
|
+
var cellValues = void 0;
|
|
86
|
+
var cellVal = void 0;
|
|
87
|
+
var val = '';
|
|
88
|
+
condition = this.parent.getValueFromArg(argArr[0]);
|
|
89
|
+
if (this.parent.getErrorStrings().indexOf(condition) > -1) {
|
|
90
|
+
return condition;
|
|
91
|
+
}
|
|
92
|
+
var condUpper = condition.toUpperCase();
|
|
93
|
+
var parsedVal = this.parent.parseFloat(condition);
|
|
94
|
+
if (condUpper === this.parent.trueValue || (parsedVal < 0 || parsedVal > 0)) {
|
|
95
|
+
if (nestedFormula && argArr[1].includes(':')) {
|
|
96
|
+
cellValues = this.parent.getCellCollection(argArr[1]);
|
|
97
|
+
for (var i = 0; i < cellValues.length; i++) {
|
|
98
|
+
cellVal = this.parent.getValueFromArg(cellValues[i]);
|
|
99
|
+
if (!isNaN(this.parent.parseFloat(cellVal))) {
|
|
100
|
+
val += cellVal + ',';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return val.slice(0, val.length - 1);
|
|
104
|
+
}
|
|
105
|
+
result = argArr[1] === '' ? '0' : this.parent.getValueFromArg(argArr[1], undefined, undefined, undefined, true);
|
|
106
|
+
}
|
|
107
|
+
else if (condUpper === this.parent.falseValue || parsedVal === 0) {
|
|
108
|
+
if (isNullOrUndefined(argArr[2])) {
|
|
109
|
+
return this.parent.falseValue;
|
|
110
|
+
}
|
|
111
|
+
if (nestedFormula && argArr[2].includes(':')) {
|
|
112
|
+
cellValues = this.parent.getCellCollection(argArr[2]);
|
|
113
|
+
for (var i = 0; i < cellValues.length; i++) {
|
|
114
|
+
cellVal = this.parent.getValueFromArg(cellValues[i]);
|
|
115
|
+
if (!isNaN(this.parent.parseFloat(cellVal))) {
|
|
116
|
+
val += cellVal + ',';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return val.slice(0, val.length - 1);
|
|
120
|
+
}
|
|
121
|
+
result = argArr[2] === '' ? '0' : this.parent.getValueFromArg(argArr[2], undefined, undefined, undefined, true);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.Requires3Args];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
var indexOfTic = result.indexOf(this.parent.tic);
|
|
128
|
+
if (!skipTick && indexOfTic > -1) {
|
|
129
|
+
return result.split(this.parent.tic).join('');
|
|
130
|
+
}
|
|
131
|
+
else if (skipTick && !isNumber(result) && indexOfTic === -1 && result !== this.parent.trueValue &&
|
|
132
|
+
result !== this.parent.falseValue && !this.parent.isCellReference(result)) {
|
|
133
|
+
return '"' + result + '"';
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return result === '' ? '0' : result;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Returns TRUE if all the arguments are considered TRUE, and FALSE otherwise.
|
|
141
|
+
*
|
|
142
|
+
* Excel: `AND(...)`.
|
|
143
|
+
*
|
|
144
|
+
* @hidden
|
|
145
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
146
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
147
|
+
*/
|
|
148
|
+
LogicalFormulas.prototype.ComputeAND = function () {
|
|
149
|
+
var args = [];
|
|
150
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
151
|
+
args[_i] = arguments[_i];
|
|
152
|
+
}
|
|
153
|
+
var argArr = args;
|
|
154
|
+
if (isNullOrUndefined(args) || (argArr.length === 1 && argArr[0] === '')) {
|
|
155
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
156
|
+
}
|
|
157
|
+
return this.parent.computeAndOrNot(argArr, 'and');
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Returns TRUE if any arguments considered TRUE, and all the arguments are FALSE it will return FALSE.
|
|
161
|
+
*
|
|
162
|
+
* Excel: `OR(...)`.
|
|
163
|
+
*
|
|
164
|
+
* @hidden
|
|
165
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
166
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
167
|
+
*/
|
|
168
|
+
LogicalFormulas.prototype.ComputeOR = function () {
|
|
169
|
+
var args = [];
|
|
170
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
171
|
+
args[_i] = arguments[_i];
|
|
172
|
+
}
|
|
173
|
+
var argArr = args;
|
|
174
|
+
if (isNullOrUndefined(args) || (argArr.length === 1 && argArr[0] === '')) {
|
|
175
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
176
|
+
}
|
|
177
|
+
return this.parent.computeAndOrNot(argArr, 'or');
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Returns the inverse of a given logical expression.
|
|
181
|
+
*
|
|
182
|
+
* Excel: `NOT(...)`.
|
|
183
|
+
*
|
|
184
|
+
* @hidden
|
|
185
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
186
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
187
|
+
*/
|
|
188
|
+
LogicalFormulas.prototype.ComputeNOT = function () {
|
|
189
|
+
var args = [];
|
|
190
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
191
|
+
args[_i] = arguments[_i];
|
|
192
|
+
}
|
|
193
|
+
var argArr = args;
|
|
194
|
+
if (isNullOrUndefined(args) || (args.length > 1 || args[0] === '')) {
|
|
195
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
196
|
+
}
|
|
197
|
+
return this.parent.computeAndOrNot(argArr, 'not');
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Checks multiple conditions and returns a value corresponding to the first TRUE result.
|
|
201
|
+
*
|
|
202
|
+
* Excel: `IFS(...)`.
|
|
203
|
+
*
|
|
204
|
+
* @hidden
|
|
205
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
206
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
207
|
+
*/
|
|
208
|
+
LogicalFormulas.prototype.ComputeIFS = function () {
|
|
209
|
+
var args = [];
|
|
210
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
211
|
+
args[_i] = arguments[_i];
|
|
212
|
+
}
|
|
213
|
+
var argArr = args;
|
|
214
|
+
if (isNullOrUndefined(args) || (argArr.length === 1 && argArr[0] === '') || argArr.length % 2 !== 0) {
|
|
215
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
216
|
+
}
|
|
217
|
+
var condition = '';
|
|
218
|
+
var result = '';
|
|
219
|
+
for (var i = 0; i < argArr.length; i++) {
|
|
220
|
+
condition = this.parent.getValueFromArg(argArr[i]);
|
|
221
|
+
if (argArr[i] === '') {
|
|
222
|
+
return this.parent.getErrorStrings()[CommonErrors.NA];
|
|
223
|
+
}
|
|
224
|
+
if (this.parent.getErrorStrings().indexOf(condition) > -1) {
|
|
225
|
+
return condition;
|
|
226
|
+
}
|
|
227
|
+
if (condition !== this.parent.trueValue && condition !== this.parent.falseValue) {
|
|
228
|
+
return this.parent.getErrorStrings()[CommonErrors.Value];
|
|
229
|
+
}
|
|
230
|
+
if (condition === this.parent.trueValue) {
|
|
231
|
+
if (this.parent.isCellReference(argArr[i + 1].split(this.parent.tic).join('')) || argArr[i + 1].includes(this.parent.arithMarker)) {
|
|
232
|
+
result = this.parent.getValueFromArg(argArr[i + 1]);
|
|
233
|
+
result = result === '' ? '0' : result;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
result = argArr[i + 1] === '' ? '0' : this.parent.getValueFromArg(argArr[i + 1]);
|
|
237
|
+
if (result.indexOf(this.parent.tic) > -1) {
|
|
238
|
+
result = result.split(this.parent.tic).join('');
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
i = i + 1;
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
else if (condition === this.parent.falseValue) {
|
|
245
|
+
i = i + 1;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return this.parent.getErrorStrings()[CommonErrors.NA];
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Returns a value you specify if a formula evaluates to an error; otherwise, it returns the result of the formula.
|
|
252
|
+
*
|
|
253
|
+
* Excel: `IFERROR(...)`.
|
|
254
|
+
*
|
|
255
|
+
* @hidden
|
|
256
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
257
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
258
|
+
*/
|
|
259
|
+
LogicalFormulas.prototype.ComputeIFERROR = function () {
|
|
260
|
+
var args = [];
|
|
261
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
262
|
+
args[_i] = arguments[_i];
|
|
263
|
+
}
|
|
264
|
+
if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
|
|
265
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
266
|
+
}
|
|
267
|
+
var argArr = args;
|
|
268
|
+
var condition;
|
|
269
|
+
if (argArr.length !== 2) {
|
|
270
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
271
|
+
}
|
|
272
|
+
if (this.parent.isCellReference(argArr[0])) {
|
|
273
|
+
condition = this.parent.getValueFromArg(argArr[0]) || '0';
|
|
274
|
+
if (this.parent.getErrorStrings().indexOf(condition) === -1 && condition !== 'NaN') {
|
|
275
|
+
return condition;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
condition = this.parent.getValueFromArg(argArr[0], null, true) || '0';
|
|
280
|
+
if (this.parent.getErrorStrings().indexOf(condition) === -1 && condition !== 'NaN') {
|
|
281
|
+
condition = condition.split(this.parent.tic).join('').trim();
|
|
282
|
+
return condition;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (this.parent.isCellReference(argArr[1])) {
|
|
286
|
+
condition = this.parent.getValueFromArg(argArr[1]) || '0';
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
condition = this.parent.getValueFromArg(argArr[1]) || '0';
|
|
290
|
+
condition = condition.split(this.parent.tic).join('').trim();
|
|
291
|
+
}
|
|
292
|
+
return condition;
|
|
293
|
+
};
|
|
294
|
+
return LogicalFormulas;
|
|
295
|
+
}(FormulaModuleBase));
|
|
296
|
+
export { LogicalFormulas };
|