@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,657 @@
|
|
|
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 text functions for search, replace, formatting, and character-code conversion.
|
|
19
|
+
*
|
|
20
|
+
* Registers 19 functions including LEFT, RIGHT, MID, UPPER, LOWER, and others.
|
|
21
|
+
*
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
var TextExtraFormulas = /** @class */ (function (_super) {
|
|
25
|
+
__extends(TextExtraFormulas, _super);
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
29
|
+
*/
|
|
30
|
+
function TextExtraFormulas(owner) {
|
|
31
|
+
var _this = _super.call(this, owner) || this;
|
|
32
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
33
|
+
_this.formulas = [
|
|
34
|
+
{ formulaName: 'LEFT', category: 'Text', description: 'Returns the leftmost characters from a text value.' },
|
|
35
|
+
{ formulaName: 'RIGHT', category: 'Text', description: 'Returns the rightmost characters from a text value.' },
|
|
36
|
+
{ formulaName: 'MID', category: 'Text', description: 'Returns a specific number of characters from a text string starting at the position you specify.' },
|
|
37
|
+
{ formulaName: 'UPPER', category: 'Text', description: 'Converts text to uppercase.' },
|
|
38
|
+
{ formulaName: 'LOWER', category: 'Text', description: 'Converts text to lowercase.' },
|
|
39
|
+
{ formulaName: 'TRIM', category: 'Text', description: 'Removes spaces from text except for single spaces between words.' },
|
|
40
|
+
{ formulaName: 'REPLACE', category: 'Text', description: 'Replaces characters within text.' },
|
|
41
|
+
{ formulaName: 'SUBSTITUTE', category: 'Text', description: 'Substitutes new text for old text in a text string.' },
|
|
42
|
+
{ formulaName: 'REPT', category: 'Text', description: 'Repeats text a given number of times.' },
|
|
43
|
+
{ formulaName: 'SEARCH', category: 'Text', description: 'Finds one text value within another (not case-sensitive).' },
|
|
44
|
+
{ formulaName: 'VALUE', category: 'Text', description: 'Converts a text argument to a number.' },
|
|
45
|
+
{ formulaName: 'CLEAN', category: 'Text', description: 'Removes all nonprintable characters from text.' },
|
|
46
|
+
{ formulaName: 'FIXED', category: 'Text', description: 'Formats a number as text with a fixed number of decimals.' },
|
|
47
|
+
{ formulaName: 'TEXTJOIN', category: 'Text', description: 'Combines text from multiple ranges/strings with a delimiter.' },
|
|
48
|
+
{ formulaName: 'LEFTB', category: 'Text', description: 'Returns the leftmost characters from a text value (byte count alias).' },
|
|
49
|
+
{ formulaName: 'RIGHTB', category: 'Text', description: 'Returns the rightmost characters from a text value (byte count alias).' },
|
|
50
|
+
{ formulaName: 'MIDB', category: 'Text', description: 'Returns characters from a text string (byte count alias).' },
|
|
51
|
+
{ formulaName: 'REPLACEB', category: 'Text', description: 'Replaces characters within text (byte count alias).' },
|
|
52
|
+
{ formulaName: 'SEARCHB', category: 'Text', description: 'Finds one text value within another (byte count alias).' }
|
|
53
|
+
];
|
|
54
|
+
return _this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns the leftmost characters from a text value.
|
|
58
|
+
*
|
|
59
|
+
* Excel: `LEFT(...)`.
|
|
60
|
+
*
|
|
61
|
+
* @hidden
|
|
62
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
63
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* engine.computeFormula('=LEFT("Calculate",4)');
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
TextExtraFormulas.prototype.ComputeLEFT = function () {
|
|
71
|
+
var args = [];
|
|
72
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
73
|
+
args[_i] = arguments[_i];
|
|
74
|
+
}
|
|
75
|
+
return this.substringSide(args, true);
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Returns the rightmost characters from a text value.
|
|
79
|
+
*
|
|
80
|
+
* Excel: `RIGHT(...)`.
|
|
81
|
+
*
|
|
82
|
+
* @hidden
|
|
83
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
84
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
85
|
+
*/
|
|
86
|
+
TextExtraFormulas.prototype.ComputeRIGHT = function () {
|
|
87
|
+
var args = [];
|
|
88
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
89
|
+
args[_i] = arguments[_i];
|
|
90
|
+
}
|
|
91
|
+
return this.substringSide(args, false);
|
|
92
|
+
};
|
|
93
|
+
TextExtraFormulas.prototype.substringSide = function (args, fromLeft) {
|
|
94
|
+
var errCollection = this.parent.getErrorStrings();
|
|
95
|
+
if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
|
|
96
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
97
|
+
}
|
|
98
|
+
if (args.length > 2) {
|
|
99
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
100
|
+
}
|
|
101
|
+
var text = this.resolveTextArg(args[0]);
|
|
102
|
+
if (errCollection.indexOf(text) > -1) {
|
|
103
|
+
return text;
|
|
104
|
+
}
|
|
105
|
+
var count = 1;
|
|
106
|
+
if (args.length === 2) {
|
|
107
|
+
var num = this.resolveNumberArg(args[1]);
|
|
108
|
+
if (typeof num === 'string') {
|
|
109
|
+
return num;
|
|
110
|
+
}
|
|
111
|
+
count = Math.floor(num);
|
|
112
|
+
if (count < 0) {
|
|
113
|
+
return errCollection[CommonErrors.Value];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (fromLeft) {
|
|
117
|
+
return text.substring(0, count);
|
|
118
|
+
}
|
|
119
|
+
return count >= text.length ? text : text.substring(text.length - count);
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Returns a specific number of characters from a text string starting at the position you specify.
|
|
123
|
+
*
|
|
124
|
+
* Excel: `MID(...)`.
|
|
125
|
+
*
|
|
126
|
+
* @hidden
|
|
127
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
128
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
129
|
+
*/
|
|
130
|
+
TextExtraFormulas.prototype.ComputeMID = function () {
|
|
131
|
+
var args = [];
|
|
132
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
133
|
+
args[_i] = arguments[_i];
|
|
134
|
+
}
|
|
135
|
+
var errCollection = this.parent.getErrorStrings();
|
|
136
|
+
if (isNullOrUndefined(args) || args.length !== 3) {
|
|
137
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
138
|
+
}
|
|
139
|
+
var text = this.resolveTextArg(args[0]);
|
|
140
|
+
if (errCollection.indexOf(text) > -1) {
|
|
141
|
+
return text;
|
|
142
|
+
}
|
|
143
|
+
var start = this.resolveNumberArg(args[1]);
|
|
144
|
+
var numChars = this.resolveNumberArg(args[2]);
|
|
145
|
+
if (typeof start === 'string') {
|
|
146
|
+
return start;
|
|
147
|
+
}
|
|
148
|
+
if (typeof numChars === 'string') {
|
|
149
|
+
return numChars;
|
|
150
|
+
}
|
|
151
|
+
var startIdx = Math.floor(start);
|
|
152
|
+
var length = Math.floor(numChars);
|
|
153
|
+
if (startIdx < 1 || length < 0) {
|
|
154
|
+
return errCollection[CommonErrors.Value];
|
|
155
|
+
}
|
|
156
|
+
return text.substring(startIdx - 1, startIdx - 1 + length);
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Converts text to uppercase.
|
|
160
|
+
*
|
|
161
|
+
* Excel: `UPPER(...)`.
|
|
162
|
+
*
|
|
163
|
+
* @hidden
|
|
164
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
165
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
166
|
+
*/
|
|
167
|
+
TextExtraFormulas.prototype.ComputeUPPER = function () {
|
|
168
|
+
var args = [];
|
|
169
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
170
|
+
args[_i] = arguments[_i];
|
|
171
|
+
}
|
|
172
|
+
return this.caseTransform(args, true);
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Converts text to lowercase.
|
|
176
|
+
*
|
|
177
|
+
* Excel: `LOWER(...)`.
|
|
178
|
+
*
|
|
179
|
+
* @hidden
|
|
180
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
181
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
182
|
+
*/
|
|
183
|
+
TextExtraFormulas.prototype.ComputeLOWER = function () {
|
|
184
|
+
var args = [];
|
|
185
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
186
|
+
args[_i] = arguments[_i];
|
|
187
|
+
}
|
|
188
|
+
return this.caseTransform(args, false);
|
|
189
|
+
};
|
|
190
|
+
TextExtraFormulas.prototype.caseTransform = function (args, upper) {
|
|
191
|
+
var errCollection = this.parent.getErrorStrings();
|
|
192
|
+
if (isNullOrUndefined(args) || args.length !== 1) {
|
|
193
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
194
|
+
}
|
|
195
|
+
var text = this.resolveTextArg(args[0]);
|
|
196
|
+
if (errCollection.indexOf(text) > -1) {
|
|
197
|
+
return text;
|
|
198
|
+
}
|
|
199
|
+
return upper ? text.toUpperCase() : text.toLowerCase();
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Removes spaces from text except for single spaces between words.
|
|
203
|
+
*
|
|
204
|
+
* Excel: `TRIM(...)`.
|
|
205
|
+
*
|
|
206
|
+
* @hidden
|
|
207
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
208
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
209
|
+
*/
|
|
210
|
+
TextExtraFormulas.prototype.ComputeTRIM = function () {
|
|
211
|
+
var args = [];
|
|
212
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
213
|
+
args[_i] = arguments[_i];
|
|
214
|
+
}
|
|
215
|
+
var errCollection = this.parent.getErrorStrings();
|
|
216
|
+
if (isNullOrUndefined(args) || args.length !== 1) {
|
|
217
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
218
|
+
}
|
|
219
|
+
var text = this.resolveTextArg(args[0]);
|
|
220
|
+
if (errCollection.indexOf(text) > -1) {
|
|
221
|
+
return text;
|
|
222
|
+
}
|
|
223
|
+
return text.trim().replace(/\s+/g, ' ');
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Replaces characters within text.
|
|
227
|
+
*
|
|
228
|
+
* Excel: `REPLACE(...)`.
|
|
229
|
+
*
|
|
230
|
+
* @hidden
|
|
231
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
232
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
233
|
+
*/
|
|
234
|
+
TextExtraFormulas.prototype.ComputeREPLACE = function () {
|
|
235
|
+
var args = [];
|
|
236
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
237
|
+
args[_i] = arguments[_i];
|
|
238
|
+
}
|
|
239
|
+
var errCollection = this.parent.getErrorStrings();
|
|
240
|
+
if (isNullOrUndefined(args) || args.length !== 4) {
|
|
241
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
242
|
+
}
|
|
243
|
+
var text = this.resolveTextArg(args[0]);
|
|
244
|
+
if (errCollection.indexOf(text) > -1) {
|
|
245
|
+
return text;
|
|
246
|
+
}
|
|
247
|
+
var start = this.resolveNumberArg(args[1]);
|
|
248
|
+
var numChars = this.resolveNumberArg(args[2]);
|
|
249
|
+
var newText = this.resolveTextArg(args[3]);
|
|
250
|
+
if (typeof start === 'string') {
|
|
251
|
+
return start;
|
|
252
|
+
}
|
|
253
|
+
if (typeof numChars === 'string') {
|
|
254
|
+
return numChars;
|
|
255
|
+
}
|
|
256
|
+
if (errCollection.indexOf(newText) > -1) {
|
|
257
|
+
return newText;
|
|
258
|
+
}
|
|
259
|
+
var startIdx = Math.floor(start);
|
|
260
|
+
var length = Math.floor(numChars);
|
|
261
|
+
if (startIdx < 1 || length < 0) {
|
|
262
|
+
return errCollection[CommonErrors.Value];
|
|
263
|
+
}
|
|
264
|
+
return text.substring(0, startIdx - 1) + newText + text.substring(startIdx - 1 + length);
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Substitutes new text for old text in a text string.
|
|
268
|
+
*
|
|
269
|
+
* Excel: `SUBSTITUTE(...)`.
|
|
270
|
+
*
|
|
271
|
+
* @hidden
|
|
272
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
273
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
274
|
+
*/
|
|
275
|
+
TextExtraFormulas.prototype.ComputeSUBSTITUTE = function () {
|
|
276
|
+
var args = [];
|
|
277
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
278
|
+
args[_i] = arguments[_i];
|
|
279
|
+
}
|
|
280
|
+
var errCollection = this.parent.getErrorStrings();
|
|
281
|
+
if (isNullOrUndefined(args) || args.length < 3 || args.length > 4) {
|
|
282
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
283
|
+
}
|
|
284
|
+
var text = this.resolveTextArg(args[0]);
|
|
285
|
+
var oldText = this.resolveTextArg(args[1]);
|
|
286
|
+
var newText = this.resolveTextArg(args[2]);
|
|
287
|
+
if (errCollection.indexOf(text) > -1) {
|
|
288
|
+
return text;
|
|
289
|
+
}
|
|
290
|
+
if (errCollection.indexOf(oldText) > -1) {
|
|
291
|
+
return oldText;
|
|
292
|
+
}
|
|
293
|
+
if (errCollection.indexOf(newText) > -1) {
|
|
294
|
+
return newText;
|
|
295
|
+
}
|
|
296
|
+
if (oldText === '') {
|
|
297
|
+
return text;
|
|
298
|
+
}
|
|
299
|
+
if (args.length === 3) {
|
|
300
|
+
return text.split(oldText).join(newText);
|
|
301
|
+
}
|
|
302
|
+
var instance = this.resolveNumberArg(args[3]);
|
|
303
|
+
if (typeof instance === 'string') {
|
|
304
|
+
return instance;
|
|
305
|
+
}
|
|
306
|
+
var nth = Math.floor(instance);
|
|
307
|
+
if (nth < 1) {
|
|
308
|
+
return errCollection[CommonErrors.Value];
|
|
309
|
+
}
|
|
310
|
+
var found = 0;
|
|
311
|
+
var index = text.indexOf(oldText);
|
|
312
|
+
while (index > -1) {
|
|
313
|
+
found++;
|
|
314
|
+
if (found === nth) {
|
|
315
|
+
return text.substring(0, index) + newText + text.substring(index + oldText.length);
|
|
316
|
+
}
|
|
317
|
+
index = text.indexOf(oldText, index + oldText.length);
|
|
318
|
+
}
|
|
319
|
+
return text;
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* Repeats text a given number of times.
|
|
323
|
+
*
|
|
324
|
+
* Excel: `REPT(...)`.
|
|
325
|
+
*
|
|
326
|
+
* @hidden
|
|
327
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
328
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
329
|
+
*/
|
|
330
|
+
TextExtraFormulas.prototype.ComputeREPT = function () {
|
|
331
|
+
var args = [];
|
|
332
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
333
|
+
args[_i] = arguments[_i];
|
|
334
|
+
}
|
|
335
|
+
var errCollection = this.parent.getErrorStrings();
|
|
336
|
+
if (isNullOrUndefined(args) || args.length !== 2) {
|
|
337
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
338
|
+
}
|
|
339
|
+
var text = this.resolveTextArg(args[0]);
|
|
340
|
+
if (errCollection.indexOf(text) > -1) {
|
|
341
|
+
return text;
|
|
342
|
+
}
|
|
343
|
+
var times = this.resolveNumberArg(args[1]);
|
|
344
|
+
if (typeof times === 'string') {
|
|
345
|
+
return times;
|
|
346
|
+
}
|
|
347
|
+
var count = Math.floor(times);
|
|
348
|
+
if (count < 0) {
|
|
349
|
+
return errCollection[CommonErrors.Value];
|
|
350
|
+
}
|
|
351
|
+
if (count === 0 || text === '') {
|
|
352
|
+
return '';
|
|
353
|
+
}
|
|
354
|
+
return new Array(count + 1).join(text);
|
|
355
|
+
};
|
|
356
|
+
/**
|
|
357
|
+
* Finds one text value within another (not case-sensitive).
|
|
358
|
+
*
|
|
359
|
+
* Excel: `SEARCH(...)`.
|
|
360
|
+
*
|
|
361
|
+
* @hidden
|
|
362
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
363
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
364
|
+
*/
|
|
365
|
+
TextExtraFormulas.prototype.ComputeSEARCH = function () {
|
|
366
|
+
var args = [];
|
|
367
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
368
|
+
args[_i] = arguments[_i];
|
|
369
|
+
}
|
|
370
|
+
var errCollection = this.parent.getErrorStrings();
|
|
371
|
+
if (isNullOrUndefined(args) || args.length < 2 || args.length > 3) {
|
|
372
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
373
|
+
}
|
|
374
|
+
var findText = this.resolveTextArg(args[0]).toLowerCase();
|
|
375
|
+
var withinText = this.resolveTextArg(args[1]).toLowerCase();
|
|
376
|
+
if (errCollection.indexOf(findText) > -1) {
|
|
377
|
+
return findText;
|
|
378
|
+
}
|
|
379
|
+
if (errCollection.indexOf(withinText) > -1) {
|
|
380
|
+
return withinText;
|
|
381
|
+
}
|
|
382
|
+
var startNum = 1;
|
|
383
|
+
if (args.length === 3) {
|
|
384
|
+
var start = this.resolveNumberArg(args[2]);
|
|
385
|
+
if (typeof start === 'string') {
|
|
386
|
+
return start;
|
|
387
|
+
}
|
|
388
|
+
startNum = Math.floor(start);
|
|
389
|
+
if (startNum < 1) {
|
|
390
|
+
return errCollection[CommonErrors.Value];
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
var idx = withinText.indexOf(findText, startNum - 1);
|
|
394
|
+
if (idx < 0) {
|
|
395
|
+
return errCollection[CommonErrors.Value];
|
|
396
|
+
}
|
|
397
|
+
return (idx + 1).toString();
|
|
398
|
+
};
|
|
399
|
+
/**
|
|
400
|
+
* Converts a text argument to a number.
|
|
401
|
+
*
|
|
402
|
+
* Excel: `VALUE(...)`.
|
|
403
|
+
*
|
|
404
|
+
* @hidden
|
|
405
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
406
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
407
|
+
*/
|
|
408
|
+
TextExtraFormulas.prototype.ComputeVALUE = function () {
|
|
409
|
+
var args = [];
|
|
410
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
411
|
+
args[_i] = arguments[_i];
|
|
412
|
+
}
|
|
413
|
+
var errCollection = this.parent.getErrorStrings();
|
|
414
|
+
if (isNullOrUndefined(args) || args.length !== 1) {
|
|
415
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
416
|
+
}
|
|
417
|
+
var text = this.resolveTextArg(args[0]);
|
|
418
|
+
if (errCollection.indexOf(text) > -1) {
|
|
419
|
+
return text;
|
|
420
|
+
}
|
|
421
|
+
if (text === '') {
|
|
422
|
+
return '0';
|
|
423
|
+
}
|
|
424
|
+
var cleaned = text.replace(/,/g, '').replace(/\$/g, '').trim();
|
|
425
|
+
var num = this.parent.parseFloat(cleaned);
|
|
426
|
+
if (isNaN(num)) {
|
|
427
|
+
return errCollection[CommonErrors.Value];
|
|
428
|
+
}
|
|
429
|
+
return num.toString();
|
|
430
|
+
};
|
|
431
|
+
/**
|
|
432
|
+
* Removes all nonprintable characters from text.
|
|
433
|
+
*
|
|
434
|
+
* Excel: `CLEAN(...)`.
|
|
435
|
+
*
|
|
436
|
+
* @hidden
|
|
437
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
438
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
439
|
+
*/
|
|
440
|
+
TextExtraFormulas.prototype.ComputeCLEAN = function () {
|
|
441
|
+
var args = [];
|
|
442
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
443
|
+
args[_i] = arguments[_i];
|
|
444
|
+
}
|
|
445
|
+
var errCollection = this.parent.getErrorStrings();
|
|
446
|
+
if (isNullOrUndefined(args) || args.length !== 1) {
|
|
447
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
448
|
+
}
|
|
449
|
+
var text = this.resolveTextArg(args[0]);
|
|
450
|
+
if (errCollection.indexOf(text) > -1) {
|
|
451
|
+
return text;
|
|
452
|
+
}
|
|
453
|
+
var result = '';
|
|
454
|
+
for (var i = 0; i < text.length; i++) {
|
|
455
|
+
var code = text.charCodeAt(i);
|
|
456
|
+
if (code >= 32) {
|
|
457
|
+
result += text.charAt(i);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return result;
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* Formats a number as text with a fixed number of decimals.
|
|
464
|
+
*
|
|
465
|
+
* Excel: `FIXED(...)`.
|
|
466
|
+
*
|
|
467
|
+
* @hidden
|
|
468
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
469
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
470
|
+
*/
|
|
471
|
+
TextExtraFormulas.prototype.ComputeFIXED = function () {
|
|
472
|
+
var args = [];
|
|
473
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
474
|
+
args[_i] = arguments[_i];
|
|
475
|
+
}
|
|
476
|
+
if (isNullOrUndefined(args) || args.length < 1 || args.length > 3) {
|
|
477
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
478
|
+
}
|
|
479
|
+
var number = this.resolveNumberArg(args[0]);
|
|
480
|
+
if (typeof number === 'string') {
|
|
481
|
+
return number;
|
|
482
|
+
}
|
|
483
|
+
var decimals = 2;
|
|
484
|
+
if (args.length >= 2 && args[1] !== '') {
|
|
485
|
+
var d = this.resolveNumberArg(args[1]);
|
|
486
|
+
if (typeof d === 'string') {
|
|
487
|
+
return d;
|
|
488
|
+
}
|
|
489
|
+
decimals = Math.floor(d);
|
|
490
|
+
}
|
|
491
|
+
var noCommas = false;
|
|
492
|
+
if (args.length === 3 && args[2] !== '') {
|
|
493
|
+
var flag = this.parent.getValueFromArg(args[2]).toUpperCase();
|
|
494
|
+
noCommas = flag === this.parent.trueValue || this.parent.parseFloat(flag) !== 0;
|
|
495
|
+
}
|
|
496
|
+
if (decimals < 0) {
|
|
497
|
+
var factor = Math.pow(10, -decimals);
|
|
498
|
+
var rounded = Math.round(number / factor) * factor;
|
|
499
|
+
return noCommas ? rounded.toString() : rounded.toLocaleString('en-US');
|
|
500
|
+
}
|
|
501
|
+
var fixed = number.toFixed(decimals);
|
|
502
|
+
if (noCommas) {
|
|
503
|
+
return fixed;
|
|
504
|
+
}
|
|
505
|
+
var parts = fixed.split('.');
|
|
506
|
+
var intPart = parts[0];
|
|
507
|
+
var sign = intPart.charAt(0) === '-' ? '-' : '';
|
|
508
|
+
if (sign) {
|
|
509
|
+
intPart = intPart.substring(1);
|
|
510
|
+
}
|
|
511
|
+
var grouped = '';
|
|
512
|
+
for (var i = 0; i < intPart.length; i++) {
|
|
513
|
+
var fromEnd = intPart.length - i;
|
|
514
|
+
if (i > 0 && fromEnd % 3 === 0) {
|
|
515
|
+
grouped += ',';
|
|
516
|
+
}
|
|
517
|
+
grouped += intPart.charAt(i);
|
|
518
|
+
}
|
|
519
|
+
parts[0] = sign + grouped;
|
|
520
|
+
return parts.join('.');
|
|
521
|
+
};
|
|
522
|
+
/**
|
|
523
|
+
* Combines text from multiple ranges/strings with a delimiter.
|
|
524
|
+
*
|
|
525
|
+
* Excel: `TEXTJOIN(...)`.
|
|
526
|
+
*
|
|
527
|
+
* @hidden
|
|
528
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
529
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
530
|
+
*/
|
|
531
|
+
TextExtraFormulas.prototype.ComputeTEXTJOIN = function () {
|
|
532
|
+
var args = [];
|
|
533
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
534
|
+
args[_i] = arguments[_i];
|
|
535
|
+
}
|
|
536
|
+
var errCollection = this.parent.getErrorStrings();
|
|
537
|
+
if (isNullOrUndefined(args) || args.length < 3) {
|
|
538
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
539
|
+
}
|
|
540
|
+
var delimiter = this.resolveTextArg(args[0]);
|
|
541
|
+
if (errCollection.indexOf(delimiter) > -1) {
|
|
542
|
+
return delimiter;
|
|
543
|
+
}
|
|
544
|
+
var ignoreEmptyFlag = this.parent.getValueFromArg(args[1]).toUpperCase();
|
|
545
|
+
var ignoreEmpty = ignoreEmptyFlag === this.parent.trueValue ||
|
|
546
|
+
(!isNaN(this.parent.parseFloat(ignoreEmptyFlag)) && this.parent.parseFloat(ignoreEmptyFlag) !== 0);
|
|
547
|
+
var parts = [];
|
|
548
|
+
for (var i = 2; i < args.length; i++) {
|
|
549
|
+
var arg = args[i];
|
|
550
|
+
if (this.parent.isCellReference(arg) && arg.indexOf(':') > -1) {
|
|
551
|
+
var cells = this.parent.getCellCollection(arg);
|
|
552
|
+
var list = Array.isArray(cells) ? cells : [cells];
|
|
553
|
+
for (var c = 0; c < list.length; c++) {
|
|
554
|
+
var val = this.parent.getValueFromArg(list[c]);
|
|
555
|
+
if (errCollection.indexOf(val) > -1) {
|
|
556
|
+
return val;
|
|
557
|
+
}
|
|
558
|
+
if (!(ignoreEmpty && val === '')) {
|
|
559
|
+
parts.push(val);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
var val = this.resolveTextArg(arg);
|
|
565
|
+
if (errCollection.indexOf(val) > -1) {
|
|
566
|
+
return val;
|
|
567
|
+
}
|
|
568
|
+
if (!(ignoreEmpty && val === '')) {
|
|
569
|
+
parts.push(val);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return parts.join(delimiter);
|
|
574
|
+
};
|
|
575
|
+
/**
|
|
576
|
+
* Returns the leftmost characters from a text value (byte count alias).
|
|
577
|
+
*
|
|
578
|
+
* Excel: `LEFTB(...)`.
|
|
579
|
+
*
|
|
580
|
+
* @hidden
|
|
581
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
582
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
583
|
+
*/
|
|
584
|
+
TextExtraFormulas.prototype.ComputeLEFTB = function () {
|
|
585
|
+
var args = [];
|
|
586
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
587
|
+
args[_i] = arguments[_i];
|
|
588
|
+
}
|
|
589
|
+
return this.ComputeLEFT.apply(this, args);
|
|
590
|
+
};
|
|
591
|
+
/**
|
|
592
|
+
* Returns the rightmost characters from a text value (byte count alias).
|
|
593
|
+
*
|
|
594
|
+
* Excel: `RIGHTB(...)`.
|
|
595
|
+
*
|
|
596
|
+
* @hidden
|
|
597
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
598
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
599
|
+
*/
|
|
600
|
+
TextExtraFormulas.prototype.ComputeRIGHTB = function () {
|
|
601
|
+
var args = [];
|
|
602
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
603
|
+
args[_i] = arguments[_i];
|
|
604
|
+
}
|
|
605
|
+
return this.ComputeRIGHT.apply(this, args);
|
|
606
|
+
};
|
|
607
|
+
/**
|
|
608
|
+
* Returns characters from a text string (byte count alias).
|
|
609
|
+
*
|
|
610
|
+
* Excel: `MIDB(...)`.
|
|
611
|
+
*
|
|
612
|
+
* @hidden
|
|
613
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
614
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
615
|
+
*/
|
|
616
|
+
TextExtraFormulas.prototype.ComputeMIDB = function () {
|
|
617
|
+
var args = [];
|
|
618
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
619
|
+
args[_i] = arguments[_i];
|
|
620
|
+
}
|
|
621
|
+
return this.ComputeMID.apply(this, args);
|
|
622
|
+
};
|
|
623
|
+
/**
|
|
624
|
+
* Replaces characters within text (byte count alias).
|
|
625
|
+
*
|
|
626
|
+
* Excel: `REPLACEB(...)`.
|
|
627
|
+
*
|
|
628
|
+
* @hidden
|
|
629
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
630
|
+
* @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
|
|
631
|
+
*/
|
|
632
|
+
TextExtraFormulas.prototype.ComputeREPLACEB = function () {
|
|
633
|
+
var args = [];
|
|
634
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
635
|
+
args[_i] = arguments[_i];
|
|
636
|
+
}
|
|
637
|
+
return this.ComputeREPLACE.apply(this, args);
|
|
638
|
+
};
|
|
639
|
+
/**
|
|
640
|
+
* Finds one text value within another (byte count alias).
|
|
641
|
+
*
|
|
642
|
+
* Excel: `SEARCHB(...)`.
|
|
643
|
+
*
|
|
644
|
+
* @hidden
|
|
645
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
646
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
647
|
+
*/
|
|
648
|
+
TextExtraFormulas.prototype.ComputeSEARCHB = function () {
|
|
649
|
+
var args = [];
|
|
650
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
651
|
+
args[_i] = arguments[_i];
|
|
652
|
+
}
|
|
653
|
+
return this.ComputeSEARCH.apply(this, args);
|
|
654
|
+
};
|
|
655
|
+
return TextExtraFormulas;
|
|
656
|
+
}(FormulaModuleBase));
|
|
657
|
+
export { TextExtraFormulas };
|