@univerjs/engine-formula 1.5.2 → 1.6.1
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/lib/cjs/facade.js +2 -2
- package/lib/cjs/index.js +4 -2
- package/lib/cjs/{plugin-DFoqrWnC.js → plugin-2MkLwT8w.js} +601 -141
- package/lib/cjs/worker.js +1 -1
- package/lib/es/facade.js +2 -2
- package/lib/es/index.js +2 -2
- package/lib/es/{plugin-D8WjYqcc.js → plugin-CIMLSmdW.js} +591 -143
- package/lib/es/worker.js +1 -1
- package/lib/facade.js +2 -2
- package/lib/index.js +2 -2
- package/lib/{plugin-D8WjYqcc.js → plugin-CIMLSmdW.js} +591 -143
- package/lib/types/engine/utils/char-kit.d.ts +28 -3
- package/lib/types/engine/utils/compare.d.ts +24 -0
- package/lib/types/engine/utils/math-kit.d.ts +7 -0
- package/lib/types/engine/utils/numfmt-kit.d.ts +1 -2
- package/lib/types/engine/value-object/array-value-object.d.ts +5 -1
- package/lib/types/functions/financial/amordegrc/index.d.ts +10 -2
- package/lib/types/functions/lookup/xmatch/index.d.ts +1 -0
- package/lib/types/functions/math/iso-ceiling/index.d.ts +6 -4
- package/lib/types/functions/text/euroconvert/index.d.ts +10 -2
- package/lib/types/index.d.ts +2 -0
- package/lib/umd/index.js +4 -4
- package/lib/worker.js +1 -1
- package/package.json +6 -6
|
@@ -957,7 +957,7 @@ function splitTableStructuredRef(ref) {
|
|
|
957
957
|
};
|
|
958
958
|
}
|
|
959
959
|
|
|
960
|
-
// \0@oxc-project+runtime@0.
|
|
960
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
961
961
|
function _typeof(o) {
|
|
962
962
|
"@babel/helpers - typeof";
|
|
963
963
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -967,7 +967,7 @@ function _typeof(o) {
|
|
|
967
967
|
}, _typeof(o);
|
|
968
968
|
}
|
|
969
969
|
|
|
970
|
-
// \0@oxc-project+runtime@0.
|
|
970
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
971
971
|
function toPrimitive(t, e) {
|
|
972
972
|
if ("object" != _typeof(t) || !t) return t;
|
|
973
973
|
var r;
|
|
@@ -979,13 +979,13 @@ function toPrimitive(t, e) {
|
|
|
979
979
|
return ("string" === e ? String : Number)(t);
|
|
980
980
|
}
|
|
981
981
|
|
|
982
|
-
// \0@oxc-project+runtime@0.
|
|
982
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
983
983
|
function toPropertyKey(t) {
|
|
984
984
|
var i = toPrimitive(t, "string");
|
|
985
985
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
986
986
|
}
|
|
987
987
|
|
|
988
|
-
// \0@oxc-project+runtime@0.
|
|
988
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
989
989
|
function _defineProperty(e, r, t) {
|
|
990
990
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
991
991
|
value: t,
|
|
@@ -995,14 +995,14 @@ function _defineProperty(e, r, t) {
|
|
|
995
995
|
}) : e[r] = t, e;
|
|
996
996
|
}
|
|
997
997
|
|
|
998
|
-
// \0@oxc-project+runtime@0.
|
|
998
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
999
999
|
function __decorateParam(paramIndex, decorator) {
|
|
1000
1000
|
return function(target, key) {
|
|
1001
1001
|
decorator(target, key, paramIndex);
|
|
1002
1002
|
};
|
|
1003
1003
|
}
|
|
1004
1004
|
|
|
1005
|
-
// \0@oxc-project+runtime@0.
|
|
1005
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
1006
1006
|
function __decorate(decorators, target, key, desc) {
|
|
1007
1007
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1008
1008
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5329,6 +5329,100 @@ function getFirstBaseTable(tables, tableOrder) {
|
|
|
5329
5329
|
}
|
|
5330
5330
|
const IFormulaCurrentConfigService = (0, _univerjs_core.createIdentifier)("univer.formula.current-data.service");
|
|
5331
5331
|
|
|
5332
|
+
// src/engine/utils/char-kit.ts
|
|
5333
|
+
/**
|
|
5334
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
5335
|
+
*
|
|
5336
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5337
|
+
* you may not use this file except in compliance with the License.
|
|
5338
|
+
* You may obtain a copy of the License at
|
|
5339
|
+
*
|
|
5340
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5341
|
+
*
|
|
5342
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5343
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5344
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5345
|
+
* See the License for the specific language governing permissions and
|
|
5346
|
+
* limitations under the License.
|
|
5347
|
+
*/
|
|
5348
|
+
/**
|
|
5349
|
+
* A code point in the surrogate block is half of a UTF-16 pair, not a character.
|
|
5350
|
+
*/
|
|
5351
|
+
function isSurrogateCodePoint(codePoint) {
|
|
5352
|
+
return codePoint >= 55296 && codePoint <= 57343;
|
|
5353
|
+
}
|
|
5354
|
+
/**
|
|
5355
|
+
* U+FDD0-U+FDEF and the last two code points of every plane (xFFFE, xFFFF).
|
|
5356
|
+
*/
|
|
5357
|
+
function isNonCharacterCodePoint(codePoint) {
|
|
5358
|
+
return codePoint >= 64976 && codePoint <= 65007 || (codePoint & 65535) >= 65534;
|
|
5359
|
+
}
|
|
5360
|
+
/**
|
|
5361
|
+
* Excel logic is confusing, so we use google sheet logic
|
|
5362
|
+
*
|
|
5363
|
+
* Each UTF-16 code unit above U+00FF counts as two bytes here, so a character outside
|
|
5364
|
+
* the BMP counts as four. That length feeds LENB, LEFTB, RIGHTB, MIDB, REPLACEB,
|
|
5365
|
+
* SEARCHB and FINDB. Excel 2021 (16.0, zh-CN, DBCS default language, checked 2026-11-18)
|
|
5366
|
+
* contradicts itself on the same text: LENB("😊") is 2, but LEFTB("😊ab", 2) is "😊a",
|
|
5367
|
+
* as if 😊 were one byte, and LEFTB("😊ab", 1) returns the whole pair; MIDB("😊ab", 1, 1)
|
|
5368
|
+
* returns half a surrogate pair, while MIDB("中ab", 2, 1) returns a space standing for
|
|
5369
|
+
* the second byte of a double-byte character.
|
|
5370
|
+
*/
|
|
5371
|
+
function charLenByte(text) {
|
|
5372
|
+
let byteCount = 0;
|
|
5373
|
+
for (let i = 0; i < text.length; i++) byteCount += getCharLenByteInText(text, i);
|
|
5374
|
+
return byteCount;
|
|
5375
|
+
}
|
|
5376
|
+
function getCharLenByteInText(text, charIndex, direction = "ltr") {
|
|
5377
|
+
return getCodePoint(text, charIndex, direction) > 255 ? 2 : 1;
|
|
5378
|
+
}
|
|
5379
|
+
/**
|
|
5380
|
+
* Whether the code unit at `index` and the one after it form a surrogate pair, which
|
|
5381
|
+
* together make up one character.
|
|
5382
|
+
*/
|
|
5383
|
+
function isSurrogatePairAt(text, index) {
|
|
5384
|
+
const high = text.charCodeAt(index);
|
|
5385
|
+
const low = text.charCodeAt(index + 1);
|
|
5386
|
+
return high >= 55296 && high <= 56319 && low >= 56320 && low <= 57343;
|
|
5387
|
+
}
|
|
5388
|
+
/**
|
|
5389
|
+
* Upper-cases text for a case-insensitive search without changing its length, so an
|
|
5390
|
+
* index in the result is also the index in the original text. A character whose upper
|
|
5391
|
+
* case is longer, such as ß becoming SS, is left as it is. The host locale is ignored,
|
|
5392
|
+
* as it is for the wildcard comparisons in `compare.ts`.
|
|
5393
|
+
*/
|
|
5394
|
+
function upperCaseKeepingPositions(text) {
|
|
5395
|
+
const upperCase = text.toUpperCase();
|
|
5396
|
+
if (upperCase.length === text.length) return upperCase;
|
|
5397
|
+
let result = "";
|
|
5398
|
+
for (const char of text) {
|
|
5399
|
+
const upperChar = char.toUpperCase();
|
|
5400
|
+
result += upperChar.length === char.length ? upperChar : char;
|
|
5401
|
+
}
|
|
5402
|
+
return result;
|
|
5403
|
+
}
|
|
5404
|
+
function highSurrogate(charCode) {
|
|
5405
|
+
return charCode >= 55296 && charCode <= 56319;
|
|
5406
|
+
}
|
|
5407
|
+
function lowSurrogate(charCode) {
|
|
5408
|
+
return charCode >= 56320 && charCode <= 57343;
|
|
5409
|
+
}
|
|
5410
|
+
function surrogatePair(highSurrogate, lowSurrogate) {
|
|
5411
|
+
return ((highSurrogate & 1023) << 10) + (lowSurrogate & 1023) + 65536;
|
|
5412
|
+
}
|
|
5413
|
+
function getCodePoint(str, index, direction = "ltr") {
|
|
5414
|
+
const charCode = str.charCodeAt(index);
|
|
5415
|
+
if (direction === "ltr" && highSurrogate(charCode) && index + 1 < str.length) {
|
|
5416
|
+
const nextCharCode = str.charCodeAt(index + 1);
|
|
5417
|
+
if (lowSurrogate(nextCharCode)) return surrogatePair(charCode, nextCharCode);
|
|
5418
|
+
}
|
|
5419
|
+
if (direction === "rtl" && lowSurrogate(charCode) && index - 1 >= 0) {
|
|
5420
|
+
const prevCharCode = str.charCodeAt(index - 1);
|
|
5421
|
+
if (highSurrogate(prevCharCode)) return surrogatePair(prevCharCode, charCode);
|
|
5422
|
+
}
|
|
5423
|
+
return charCode;
|
|
5424
|
+
}
|
|
5425
|
+
|
|
5332
5426
|
// src/engine/utils/compare.ts
|
|
5333
5427
|
function getCompare() {
|
|
5334
5428
|
if (Intl && Intl.Collator) return new Intl.Collator(void 0, { numeric: false }).compare;
|
|
@@ -5355,6 +5449,13 @@ function normalizeTextForComparison(value) {
|
|
|
5355
5449
|
const lower = value.toLowerCase();
|
|
5356
5450
|
return /[\u0080-\uFFFF]/.test(lower) ? lower.normalize("NFC").replace(/[ßæœff-st]/g, (character) => TEXT_LIGATURES[character]) : lower;
|
|
5357
5451
|
}
|
|
5452
|
+
/**
|
|
5453
|
+
* Text equality for an exact lookup, where ? and * are ordinary characters (XLOOKUP and XMATCH
|
|
5454
|
+
* match mode 0). It ignores case, as the `=` comparison does.
|
|
5455
|
+
*/
|
|
5456
|
+
function isLiteralTextMatch(currentValue, value) {
|
|
5457
|
+
return normalizeTextForComparison(currentValue) === normalizeTextForComparison(value);
|
|
5458
|
+
}
|
|
5358
5459
|
function isMatchWildcard(currentValue, value) {
|
|
5359
5460
|
const pattern = escapeRegExpForWildcard(value).replace(/~?[*?]/g, (match) => {
|
|
5360
5461
|
if (match.startsWith("~")) return `\\${match.substring(1)}`;
|
|
@@ -5370,6 +5471,67 @@ function replaceWildcard(value) {
|
|
|
5370
5471
|
return " ";
|
|
5371
5472
|
});
|
|
5372
5473
|
}
|
|
5474
|
+
function parseWildcardPattern(pattern) {
|
|
5475
|
+
const segments = [[]];
|
|
5476
|
+
let hasWildcard = false;
|
|
5477
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
5478
|
+
const char = pattern[i];
|
|
5479
|
+
if (char === "~") {
|
|
5480
|
+
if (i + 1 < pattern.length) {
|
|
5481
|
+
segments[segments.length - 1].push(pattern[i + 1]);
|
|
5482
|
+
i++;
|
|
5483
|
+
}
|
|
5484
|
+
} else if (char === "*") {
|
|
5485
|
+
hasWildcard = true;
|
|
5486
|
+
segments.push([]);
|
|
5487
|
+
} else if (char === "?") {
|
|
5488
|
+
hasWildcard = true;
|
|
5489
|
+
segments[segments.length - 1].push(null);
|
|
5490
|
+
} else segments[segments.length - 1].push(char);
|
|
5491
|
+
}
|
|
5492
|
+
return {
|
|
5493
|
+
literal: hasWildcard ? null : segments[0].join(""),
|
|
5494
|
+
segments
|
|
5495
|
+
};
|
|
5496
|
+
}
|
|
5497
|
+
/**
|
|
5498
|
+
* Index of the earliest match of `pattern` in `text` at or after `fromIndex`, or -1.
|
|
5499
|
+
*
|
|
5500
|
+
* The parts of a wildcard pattern are placed at their leftmost position, so the cost
|
|
5501
|
+
* is text length times pattern length and no input can make the search backtrack.
|
|
5502
|
+
*/
|
|
5503
|
+
function searchWildcard(text, pattern, fromIndex) {
|
|
5504
|
+
if (pattern.literal !== null) return text.indexOf(pattern.literal, fromIndex);
|
|
5505
|
+
const { segments } = pattern;
|
|
5506
|
+
const start = findSegment(text, segments[0], fromIndex);
|
|
5507
|
+
if (start === -1) return -1;
|
|
5508
|
+
let position = matchSegmentAt(text, segments[0], start);
|
|
5509
|
+
for (let i = 1; i < segments.length; i++) {
|
|
5510
|
+
const found = findSegment(text, segments[i], position);
|
|
5511
|
+
if (found === -1) return -1;
|
|
5512
|
+
position = matchSegmentAt(text, segments[i], found);
|
|
5513
|
+
}
|
|
5514
|
+
return start;
|
|
5515
|
+
}
|
|
5516
|
+
/** Leftmost start at or after `fromIndex` where `segment` matches, or -1. */
|
|
5517
|
+
function findSegment(text, segment, fromIndex) {
|
|
5518
|
+
for (let start = fromIndex; start + segment.length <= text.length; start++) if (matchSegmentAt(text, segment, start) !== -1) return start;
|
|
5519
|
+
return -1;
|
|
5520
|
+
}
|
|
5521
|
+
/**
|
|
5522
|
+
* End of `segment` matched at `start`, or -1. A `?` covers one character, so a surrogate
|
|
5523
|
+
* pair such as an emoji is a single `?`; positions stay in UTF-16 units, as LEN counts them.
|
|
5524
|
+
*/
|
|
5525
|
+
function matchSegmentAt(text, segment, start) {
|
|
5526
|
+
let position = start;
|
|
5527
|
+
for (const token of segment) {
|
|
5528
|
+
if (position >= text.length) return -1;
|
|
5529
|
+
if (token === null) position += isSurrogatePairAt(text, position) ? 2 : 1;
|
|
5530
|
+
else if (token === text[position]) position++;
|
|
5531
|
+
else return -1;
|
|
5532
|
+
}
|
|
5533
|
+
return position;
|
|
5534
|
+
}
|
|
5373
5535
|
function compareWithWildcard(currentValue, value, operator, isCaseSensitive = true) {
|
|
5374
5536
|
let currentText = currentValue;
|
|
5375
5537
|
let pattern = value;
|
|
@@ -5890,39 +6052,12 @@ const numberFormatTypeCache = new FormulaAstLRU(1e5);
|
|
|
5890
6052
|
function clearNumberFormatTypeCache() {
|
|
5891
6053
|
numberFormatTypeCache.clear();
|
|
5892
6054
|
}
|
|
5893
|
-
/**
|
|
5894
|
-
* Get the currency symbol based on the locale
|
|
5895
|
-
*/
|
|
5896
|
-
const localeCurrencySymbolMap = /* @__PURE__ */ new Map([
|
|
5897
|
-
[_univerjs_core.LocaleType.EN_US, "$"],
|
|
5898
|
-
[_univerjs_core.LocaleType.RU_RU, "₽"],
|
|
5899
|
-
[_univerjs_core.LocaleType.VI_VN, "₫"],
|
|
5900
|
-
[_univerjs_core.LocaleType.ZH_CN, "¥"],
|
|
5901
|
-
[_univerjs_core.LocaleType.ZH_TW, "NT$"],
|
|
5902
|
-
[_univerjs_core.LocaleType.ZH_HK, "HK$"],
|
|
5903
|
-
[_univerjs_core.LocaleType.FR_FR, "€"],
|
|
5904
|
-
[_univerjs_core.LocaleType.FA_IR, "﷼"],
|
|
5905
|
-
[_univerjs_core.LocaleType.KO_KR, "₩"],
|
|
5906
|
-
[_univerjs_core.LocaleType.ES_ES, "€"],
|
|
5907
|
-
[_univerjs_core.LocaleType.CA_ES, "€"],
|
|
5908
|
-
[_univerjs_core.LocaleType.SK_SK, "€"],
|
|
5909
|
-
[_univerjs_core.LocaleType.JA_JP, "¥"],
|
|
5910
|
-
[_univerjs_core.LocaleType.PT_BR, "R$"],
|
|
5911
|
-
[_univerjs_core.LocaleType.DE_DE, "€"],
|
|
5912
|
-
[_univerjs_core.LocaleType.IT_IT, "€"],
|
|
5913
|
-
[_univerjs_core.LocaleType.ID_ID, "Rp"],
|
|
5914
|
-
[_univerjs_core.LocaleType.PL_PL, "zł"],
|
|
5915
|
-
[_univerjs_core.LocaleType.AR_SA, "﷼"]
|
|
5916
|
-
]);
|
|
5917
|
-
function getCurrencySymbol(locale) {
|
|
5918
|
-
return localeCurrencySymbolMap.get(locale) || "$";
|
|
5919
|
-
}
|
|
5920
6055
|
function getCurrencyFormat(locale, numberDigits = 2) {
|
|
5921
6056
|
let _numberDigits = numberDigits;
|
|
5922
6057
|
if (numberDigits > 127) _numberDigits = 127;
|
|
5923
6058
|
let decimal = "";
|
|
5924
6059
|
if (_numberDigits > 0) decimal = `.${"0".repeat(_numberDigits)}`;
|
|
5925
|
-
return `"${
|
|
6060
|
+
return `"${(0, _univerjs_core.getCurrencySymbolByLocale)(locale)}"#,##0${decimal}_);[Red]("${(0, _univerjs_core.getCurrencySymbolByLocale)(locale)}"#,##0${decimal})`;
|
|
5926
6061
|
}
|
|
5927
6062
|
function applyCurrencyFormat(locale, number, numberDigits = 2) {
|
|
5928
6063
|
return _univerjs_core.numfmt.format(getCurrencyFormat(locale, numberDigits), number);
|
|
@@ -6538,6 +6673,20 @@ function round(base, precision) {
|
|
|
6538
6673
|
return Math.round(multiply(base, factor) + epsilon) / factor;
|
|
6539
6674
|
}
|
|
6540
6675
|
/**
|
|
6676
|
+
* Rounds a number to a specified number of decimal places, halves to even ('banker's rounding').
|
|
6677
|
+
* @param base The number to round.
|
|
6678
|
+
* @param precision The number of decimal places to round to.
|
|
6679
|
+
* @returns The rounded number.
|
|
6680
|
+
*/
|
|
6681
|
+
function roundHalfEven(base, precision) {
|
|
6682
|
+
const factor = 10 ** Math.trunc(precision);
|
|
6683
|
+
const scaled = +multiply(base, factor).toFixed(8);
|
|
6684
|
+
const lower = Math.floor(scaled);
|
|
6685
|
+
const decimalPart = scaled - lower;
|
|
6686
|
+
if (Math.abs(decimalPart - .5) > 1e-8) return Math.round(scaled) / factor;
|
|
6687
|
+
return (lower % 2 === 0 ? lower : lower + 1) / factor;
|
|
6688
|
+
}
|
|
6689
|
+
/**
|
|
6541
6690
|
* Rounds down a number to a specified number of decimal places.
|
|
6542
6691
|
* @param base The number to round down.
|
|
6543
6692
|
* @param precision The number of decimal places to round down to.
|
|
@@ -7586,7 +7735,7 @@ var StringValueObject = class StringValueObject extends BaseValueObject {
|
|
|
7586
7735
|
const rawValue = this.getValue();
|
|
7587
7736
|
if (rawValue.trim() === "") return ErrorValueObject.create("#VALUE!");
|
|
7588
7737
|
const parseData = (0, _univerjs_core.getNumfmtParseValueFilter)(rawValue, { dateSystem: this.getDateSystem() });
|
|
7589
|
-
if (parseData
|
|
7738
|
+
if (parseData) return createNumberValueObjectByRawValue(parseData.v, parseData.z).withDateSystem(this.getDateSystem());
|
|
7590
7739
|
const compactMonthYear = parseCompactEnglishMonthYear(rawValue, this.getDateSystem());
|
|
7591
7740
|
if (compactMonthYear !== null) return createNumberValueObjectByRawValue(compactMonthYear).withDateSystem(this.getDateSystem());
|
|
7592
7741
|
return createNumberValueObjectByRawValue(rawValue).withDateSystem(this.getDateSystem());
|
|
@@ -7631,6 +7780,25 @@ function createNumberValueObjectByRawValue(rawValue, pattern = "") {
|
|
|
7631
7780
|
}
|
|
7632
7781
|
|
|
7633
7782
|
// src/engine/value-object/array-value-object.ts
|
|
7783
|
+
/** Literal text order: case-insensitive, and ? and * are ordinary characters rather than wildcards. */
|
|
7784
|
+
function compareTextOrder(left, right) {
|
|
7785
|
+
const leftText = normalizeTextForComparison(left);
|
|
7786
|
+
const rightText = normalizeTextForComparison(right);
|
|
7787
|
+
if (leftText === rightText) return 0;
|
|
7788
|
+
return leftText.localeCompare(rightText) < 0 ? -1 : 1;
|
|
7789
|
+
}
|
|
7790
|
+
/**
|
|
7791
|
+
* Order two values for the next smaller or larger item that XLOOKUP and XMATCH match modes -1
|
|
7792
|
+
* and 1 fall back to. Text compares as text, so ? and * inside an array item are ordinary
|
|
7793
|
+
* characters, and the other types keep the order of the value objects.
|
|
7794
|
+
*/
|
|
7795
|
+
function compareOrderValues(left, right) {
|
|
7796
|
+
if (left.isString() && right.isString()) return compareTextOrder(String(left.getValue()), String(right.getValue()));
|
|
7797
|
+
if (left.isEqual(right).getValue() === true) return 0;
|
|
7798
|
+
if (left.isLessThan(right).getValue() === true) return -1;
|
|
7799
|
+
if (left.isGreaterThan(right).getValue() === true) return 1;
|
|
7800
|
+
return 0;
|
|
7801
|
+
}
|
|
7634
7802
|
function transformToValueObject(array = [], isIgnoreNumberPattern = false, dateSystem) {
|
|
7635
7803
|
const arrayValueList = [];
|
|
7636
7804
|
for (let r = 0; r < array.length; r++) {
|
|
@@ -8019,21 +8187,43 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8019
8187
|
* Due to the inability to effectively utilize the cache,
|
|
8020
8188
|
* the sequential matching approach is only used for special matches in XLOOKUP and XMATCH.
|
|
8021
8189
|
* For example, when match_mode is set to 1 and -1 for an exact match. If not found, it returns the next smaller item.
|
|
8190
|
+
*
|
|
8191
|
+
* With literalText, the exact match and the next smaller or larger fallback read ? and * in a text value as
|
|
8192
|
+
* ordinary characters, as XLOOKUP and XMATCH do outside match mode 2. MATCH leaves it off, because its exact
|
|
8193
|
+
* match accepts wildcards.
|
|
8022
8194
|
*/
|
|
8023
|
-
orderSearch(valueObject, searchType = 1, isDesc = false, isFuzzyMatching = false, keepFirstNearest = false) {
|
|
8195
|
+
orderSearch(valueObject, searchType = 1, isDesc = false, isFuzzyMatching = false, keepFirstNearest = false, literalText = false) {
|
|
8196
|
+
const literalPattern = literalText && valueObject.isString() && isWildcard(String(valueObject.getValue())) ? String(valueObject.getValue()) : null;
|
|
8024
8197
|
let result;
|
|
8025
8198
|
let maxOrMin;
|
|
8026
8199
|
let resultPosition;
|
|
8027
8200
|
let maxOrMinPosition;
|
|
8028
8201
|
const _isNearer = (itemValue, currentValue) => {
|
|
8029
|
-
|
|
8030
|
-
|
|
8031
|
-
|
|
8202
|
+
if (literalText === false) {
|
|
8203
|
+
const distance = itemValue.minus(valueObject).abs();
|
|
8204
|
+
const currentDistance = currentValue.minus(valueObject).abs();
|
|
8205
|
+
return keepFirstNearest ? distance.isLessThan(currentDistance).getValue() === true : distance.isLessThanOrEqual(currentDistance).getValue() === true;
|
|
8206
|
+
}
|
|
8207
|
+
const comparison = compareOrderValues(itemValue, currentValue);
|
|
8208
|
+
if (comparison !== 0) return searchType === 2 ? comparison < 0 : comparison > 0;
|
|
8209
|
+
return keepFirstNearest === false;
|
|
8210
|
+
};
|
|
8211
|
+
/**
|
|
8212
|
+
* The order of an item against the lookup value for the next smaller or larger fallback.
|
|
8213
|
+
* With literalText, text is ordered as text, so ? and * in the lookup value are not a
|
|
8214
|
+
* wildcard pattern.
|
|
8215
|
+
*/
|
|
8216
|
+
const _compareWithLookup = (itemValue) => {
|
|
8217
|
+
if (literalText && itemValue.isString() && valueObject.isString()) return compareTextOrder(String(itemValue.getValue()), String(valueObject.getValue()));
|
|
8218
|
+
if (itemValue.isLessThan(valueObject).getValue() === true) return -1;
|
|
8219
|
+
if (itemValue.isGreaterThan(valueObject).getValue() === true) return 1;
|
|
8220
|
+
return 0;
|
|
8032
8221
|
};
|
|
8033
8222
|
const _handleMatch = (itemValue, row, column) => {
|
|
8034
8223
|
if (itemValue == null || itemValue.isNull()) return true;
|
|
8035
8224
|
let matchObject;
|
|
8036
8225
|
if (isFuzzyMatching === true) matchObject = itemValue.compare(valueObject, "=");
|
|
8226
|
+
else if (literalPattern !== null) matchObject = BooleanValueObject.create(itemValue.isString() && isLiteralTextMatch(String(itemValue.getValue()), literalPattern));
|
|
8037
8227
|
else if (searchType === 0 && itemValue.isNumber() && valueObject.isNumber()) matchObject = BooleanValueObject.create(Number(itemValue.getValue()) === Number(valueObject.getValue()));
|
|
8038
8228
|
else matchObject = itemValue.isEqual(valueObject);
|
|
8039
8229
|
if ((matchObject === null || matchObject === void 0 ? void 0 : matchObject.getValue()) === true) {
|
|
@@ -8044,8 +8234,9 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8044
8234
|
};
|
|
8045
8235
|
return false;
|
|
8046
8236
|
}
|
|
8237
|
+
const comparison = _compareWithLookup(itemValue);
|
|
8047
8238
|
if (searchType === 2) {
|
|
8048
|
-
if (
|
|
8239
|
+
if (comparison > 0) {
|
|
8049
8240
|
if (maxOrMin == null || _isNearer(itemValue, maxOrMin)) {
|
|
8050
8241
|
maxOrMin = itemValue;
|
|
8051
8242
|
maxOrMinPosition = {
|
|
@@ -8055,7 +8246,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8055
8246
|
}
|
|
8056
8247
|
}
|
|
8057
8248
|
} else if (searchType === 1) {
|
|
8058
|
-
if (
|
|
8249
|
+
if (comparison < 0) {
|
|
8059
8250
|
if (maxOrMin == null || _isNearer(itemValue, maxOrMin)) {
|
|
8060
8251
|
maxOrMin = itemValue;
|
|
8061
8252
|
maxOrMinPosition = {
|
|
@@ -17573,7 +17764,7 @@ let BESSEL;
|
|
|
17573
17764
|
function _bessel_wrap(bessel0, bessel1, nonzero, sign) {
|
|
17574
17765
|
return function bessel(x, n) {
|
|
17575
17766
|
if (nonzero) {
|
|
17576
|
-
if (x === 0) return nonzero === 1 ? -
|
|
17767
|
+
if (x === 0) return nonzero === 1 ? -1e400 : 1e400;
|
|
17577
17768
|
else if (x < 0) return NaN;
|
|
17578
17769
|
}
|
|
17579
17770
|
if (n === 0) return bessel0(x);
|
|
@@ -17874,7 +18065,7 @@ let BESSEL;
|
|
|
17874
18065
|
if (_n === 1) return bessel1(x);
|
|
17875
18066
|
if (_n < 0) return NaN;
|
|
17876
18067
|
if (Math.abs(x) === 0) return 0;
|
|
17877
|
-
if (x ===
|
|
18068
|
+
if (x === 1e400) return 1e400;
|
|
17878
18069
|
let ret = 0;
|
|
17879
18070
|
let j;
|
|
17880
18071
|
const tox = 2 / Math.abs(x);
|
|
@@ -18113,7 +18304,7 @@ function performLUDecomposition(matrix, transpose = true, minimumPivot = 1e-11)
|
|
|
18113
18304
|
for (let k = 0; k < i; k++) value -= luMatrix[i][k] * luMatrix[k][c];
|
|
18114
18305
|
luMatrix[i][c] = value;
|
|
18115
18306
|
}
|
|
18116
|
-
let maxPivot = -
|
|
18307
|
+
let maxPivot = -1e400;
|
|
18117
18308
|
let pivotRow = c;
|
|
18118
18309
|
for (let r = c; r < numRows; r++) {
|
|
18119
18310
|
let value = decomposedMatrix[r][c];
|
|
@@ -18667,7 +18858,7 @@ function chisquarePDF(x, degFreedom) {
|
|
|
18667
18858
|
}
|
|
18668
18859
|
function chisquareINV(probability, degFreedom) {
|
|
18669
18860
|
if (probability <= 0) return 0;
|
|
18670
|
-
if (probability >= 1) return
|
|
18861
|
+
if (probability >= 1) return 1e400;
|
|
18671
18862
|
return 2 * lowRegGammaInverse(probability, degFreedom / 2);
|
|
18672
18863
|
}
|
|
18673
18864
|
function centralFCDF(x, degFreedom1, degFreedom2) {
|
|
@@ -18676,7 +18867,7 @@ function centralFCDF(x, degFreedom1, degFreedom2) {
|
|
|
18676
18867
|
}
|
|
18677
18868
|
function centralFPDF(x, degFreedom1, degFreedom2) {
|
|
18678
18869
|
if (x < 0) return 0;
|
|
18679
|
-
if (x === 0 && degFreedom1 < 2) return
|
|
18870
|
+
if (x === 0 && degFreedom1 < 2) return 1e400;
|
|
18680
18871
|
if (x === 0 && degFreedom1 === 2) return 1;
|
|
18681
18872
|
let result = 1 / betaFunction(degFreedom1 / 2, degFreedom2 / 2);
|
|
18682
18873
|
result *= (degFreedom1 / degFreedom2) ** (degFreedom1 / 2);
|
|
@@ -18686,7 +18877,7 @@ function centralFPDF(x, degFreedom1, degFreedom2) {
|
|
|
18686
18877
|
}
|
|
18687
18878
|
function centralFINV(probability, degFreedom1, degFreedom2) {
|
|
18688
18879
|
if (probability <= 0) return 0;
|
|
18689
|
-
if (probability >= 1) return
|
|
18880
|
+
if (probability >= 1) return 1e400;
|
|
18690
18881
|
return degFreedom2 / (degFreedom1 * (1 / betaINV(probability, degFreedom1 / 2, degFreedom2 / 2) - 1));
|
|
18691
18882
|
}
|
|
18692
18883
|
function exponentialCDF(x, lambda) {
|
|
@@ -18713,7 +18904,7 @@ function forecastLinear(x, knownYs, knownXs) {
|
|
|
18713
18904
|
num += (knownYs[i] - knownYsMean) * (knownXs[i] - knownXsMean);
|
|
18714
18905
|
den += (knownXs[i] - knownXsMean) ** 2;
|
|
18715
18906
|
}
|
|
18716
|
-
if (den === 0) return
|
|
18907
|
+
if (den === 0) return 1e400;
|
|
18717
18908
|
const b = num / den;
|
|
18718
18909
|
return knownYsMean - b * knownXsMean + b * x;
|
|
18719
18910
|
}
|
|
@@ -18740,13 +18931,13 @@ function gamma(x) {
|
|
|
18740
18931
|
];
|
|
18741
18932
|
let fact = 0;
|
|
18742
18933
|
let y = x;
|
|
18743
|
-
if (x > 171.6243769536076) return
|
|
18934
|
+
if (x > 171.6243769536076) return 1e400;
|
|
18744
18935
|
if (y <= 0) {
|
|
18745
18936
|
const resMod = y % 1 + 36e-17;
|
|
18746
18937
|
if (resMod) {
|
|
18747
18938
|
fact = (!(y & 1) ? 1 : -1) * Math.PI / Math.sin(Math.PI * resMod);
|
|
18748
18939
|
y = 1 - y;
|
|
18749
|
-
} else return
|
|
18940
|
+
} else return 1e400;
|
|
18750
18941
|
}
|
|
18751
18942
|
const yi = y;
|
|
18752
18943
|
let n = 0;
|
|
@@ -18779,7 +18970,7 @@ function gammaPDF(x, alpha, beta) {
|
|
|
18779
18970
|
}
|
|
18780
18971
|
function gammaINV(probability, alpha, beta) {
|
|
18781
18972
|
if (probability <= 0) return 0;
|
|
18782
|
-
if (probability >= 1) return
|
|
18973
|
+
if (probability >= 1) return 1e400;
|
|
18783
18974
|
return beta * lowRegGammaInverse(probability, alpha);
|
|
18784
18975
|
}
|
|
18785
18976
|
function gammaln(x) {
|
|
@@ -21606,7 +21797,7 @@ var Dmax = class extends BaseFunction {
|
|
|
21606
21797
|
if (fieldIsError) return filedErrorObject;
|
|
21607
21798
|
const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
|
|
21608
21799
|
if (criteriaIsError) return criteriaErrorObject;
|
|
21609
|
-
let result = -
|
|
21800
|
+
let result = -1e400;
|
|
21610
21801
|
let count = 0;
|
|
21611
21802
|
for (let r = 1; r < databaseValues.length; r++) {
|
|
21612
21803
|
const value = databaseValues[r][fieldIndex];
|
|
@@ -21635,7 +21826,7 @@ var Dmin = class extends BaseFunction {
|
|
|
21635
21826
|
if (fieldIsError) return filedErrorObject;
|
|
21636
21827
|
const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
|
|
21637
21828
|
if (criteriaIsError) return criteriaErrorObject;
|
|
21638
|
-
let result =
|
|
21829
|
+
let result = 1e400;
|
|
21639
21830
|
let count = 0;
|
|
21640
21831
|
for (let r = 1; r < databaseValues.length; r++) {
|
|
21641
21832
|
const value = databaseValues[r][fieldIndex];
|
|
@@ -22551,7 +22742,7 @@ var Edate = class extends BaseFunction {
|
|
|
22551
22742
|
if (startDateObject.isString() || startDateObject.isBoolean() || monthsValueObject.isString() || monthsValueObject.isBoolean()) return ErrorValueObject.create("#VALUE!");
|
|
22552
22743
|
const startDateSerial = +startDateObject.getValue();
|
|
22553
22744
|
if (startDateSerial < 0) return ErrorValueObject.create("#NUM!");
|
|
22554
|
-
const monthsValue = Math.
|
|
22745
|
+
const monthsValue = Math.trunc(+monthsValueObject.getValue());
|
|
22555
22746
|
const _startDate = (0, _univerjs_core.excelSerialToDate)(startDateSerial, this.getDateSystem());
|
|
22556
22747
|
const year = _startDate.getUTCFullYear();
|
|
22557
22748
|
const month = _startDate.getUTCMonth() + monthsValue;
|
|
@@ -22595,7 +22786,7 @@ var Eomonth = class extends BaseFunction {
|
|
|
22595
22786
|
const isDate1900SerialZero = this.getDateSystem() === _univerjs_core.DateSystem.Date1900 && startDateSerialNumber === 0;
|
|
22596
22787
|
const startYear = isDate1900SerialZero ? 1900 : startDateDate.getUTCFullYear();
|
|
22597
22788
|
const startMonth = isDate1900SerialZero ? 0 : startDateDate.getUTCMonth();
|
|
22598
|
-
const monthsValue = Math.
|
|
22789
|
+
const monthsValue = Math.trunc(+_months.getValue());
|
|
22599
22790
|
if (Number.isNaN(monthsValue)) return ErrorValueObject.create("#VALUE!");
|
|
22600
22791
|
const targetDate = new Date(Date.UTC(startYear, startMonth + monthsValue + 1, 0));
|
|
22601
22792
|
const result = (0, _univerjs_core.excelDateSerial)(targetDate, this.getDateSystem());
|
|
@@ -27797,7 +27988,7 @@ function getResultByGuessIterF(guess, iterF) {
|
|
|
27797
27988
|
eps = Math.abs(xN - x);
|
|
27798
27989
|
x = xN;
|
|
27799
27990
|
}
|
|
27800
|
-
if (Number.isNaN(x) ||
|
|
27991
|
+
if (Number.isNaN(x) || 1e400 === Math.abs(x) || nMC === nIM) return guessIsNaNorInfinity(guess, iterF);
|
|
27801
27992
|
return x;
|
|
27802
27993
|
}
|
|
27803
27994
|
function guessIsNaNorInfinity(guess, iterF) {
|
|
@@ -27986,6 +28177,139 @@ var Accrintm = class extends BaseFunction {
|
|
|
27986
28177
|
}
|
|
27987
28178
|
};
|
|
27988
28179
|
|
|
28180
|
+
// src/functions/financial/amordegrc/index.ts
|
|
28181
|
+
var Amordegrc = class extends BaseFunction {
|
|
28182
|
+
constructor(..._args) {
|
|
28183
|
+
super(..._args);
|
|
28184
|
+
_defineProperty(this, "minParams", 6);
|
|
28185
|
+
_defineProperty(this, "maxParams", 7);
|
|
28186
|
+
}
|
|
28187
|
+
calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis) {
|
|
28188
|
+
const _basis = basis ?? NumberValueObject.create(0);
|
|
28189
|
+
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(cost, datePurchased, firstPeriod, salvage, period, rate, _basis);
|
|
28190
|
+
if (isError) return errorObject;
|
|
28191
|
+
const [costObject, datePurchasedObject, firstPeriodObject, salvageObject, periodObject, rateObject, basisObject] = variants;
|
|
28192
|
+
const datePurchasedSerialNumber = getDateSerialNumberByObject(datePurchasedObject, this.getDateSystem());
|
|
28193
|
+
if (typeof datePurchasedSerialNumber !== "number") return datePurchasedSerialNumber;
|
|
28194
|
+
const firstPeriodSerialNumber = getDateSerialNumberByObject(firstPeriodObject, this.getDateSystem());
|
|
28195
|
+
if (typeof firstPeriodSerialNumber !== "number") return firstPeriodSerialNumber;
|
|
28196
|
+
const costValue = +costObject.getValue();
|
|
28197
|
+
const salvageValue = +salvageObject.getValue();
|
|
28198
|
+
const periodValue = +periodObject.getValue();
|
|
28199
|
+
const rateValue = +rateObject.getValue();
|
|
28200
|
+
const basisValue = Math.floor(+basisObject.getValue());
|
|
28201
|
+
if (Number.isNaN(costValue) || Number.isNaN(salvageValue) || Number.isNaN(periodValue) || Number.isNaN(rateValue) || Number.isNaN(basisValue)) return ErrorValueObject.create("#VALUE!");
|
|
28202
|
+
if (costValue <= 0 || salvageValue < 0 || costValue < salvageValue || Math.floor(datePurchasedSerialNumber) > Math.floor(firstPeriodSerialNumber) || periodValue < 0 || rateValue <= 0 || ![
|
|
28203
|
+
0,
|
|
28204
|
+
1,
|
|
28205
|
+
3,
|
|
28206
|
+
4
|
|
28207
|
+
].includes(basisValue)) return ErrorValueObject.create("#NUM!");
|
|
28208
|
+
return this._getResult(costValue, datePurchasedSerialNumber, firstPeriodSerialNumber, salvageValue, periodValue, rateValue, basisValue);
|
|
28209
|
+
}
|
|
28210
|
+
_getResult(costValue, datePurchasedSerialNumber, firstPeriodSerialNumber, salvageValue, periodValue, rateValue, basisValue) {
|
|
28211
|
+
if (1 / rateValue <= 2) return ErrorValueObject.create("#NUM!");
|
|
28212
|
+
const life = Math.ceil(1 / rateValue);
|
|
28213
|
+
if (costValue === salvageValue || periodValue > life) return NumberValueObject.create(0);
|
|
28214
|
+
const depreciationRate = rateValue * this._getCoefficient(life);
|
|
28215
|
+
const { days, yearDays } = getFirstPeriodDays(datePurchasedSerialNumber, firstPeriodSerialNumber, basisValue, this.getDateSystem());
|
|
28216
|
+
const prorated = days / yearDays * depreciationRate * costValue;
|
|
28217
|
+
const lastPeriods = prorated === 0 ? life : life + 1;
|
|
28218
|
+
const firstDepreciation = excelRound(Math.min(prorated === 0 ? costValue * depreciationRate : prorated, costValue - salvageValue));
|
|
28219
|
+
if (periodValue === 0) return NumberValueObject.create(firstDepreciation);
|
|
28220
|
+
let bookValue = costValue - firstDepreciation;
|
|
28221
|
+
let rate = depreciationRate;
|
|
28222
|
+
let depreciation = 0;
|
|
28223
|
+
for (let countedPeriod = 2; countedPeriod <= periodValue + 1; countedPeriod++) {
|
|
28224
|
+
const skipped = skipRegularPeriods(countedPeriod, Math.min(periodValue + 1, lastPeriods - 3), bookValue, salvageValue, rate);
|
|
28225
|
+
countedPeriod += skipped.periods;
|
|
28226
|
+
bookValue = skipped.bookValue;
|
|
28227
|
+
const isSecondToLast = Math.abs(lastPeriods - countedPeriod - 2) < 1e-4;
|
|
28228
|
+
const scheduled = isSecondToLast ? bookValue * .5 : rate * bookValue;
|
|
28229
|
+
if (isSecondToLast) rate = 1;
|
|
28230
|
+
depreciation = bookValue < salvageValue ? 0 : scheduled;
|
|
28231
|
+
bookValue -= depreciation;
|
|
28232
|
+
if (depreciation === 0 && bookValue <= salvageValue) return NumberValueObject.create(0);
|
|
28233
|
+
}
|
|
28234
|
+
return NumberValueObject.create(excelRound(depreciation));
|
|
28235
|
+
}
|
|
28236
|
+
/**
|
|
28237
|
+
* The depreciation coefficient of the French accounting system, by the life of the asset in
|
|
28238
|
+
* whole years: up to 4 is 1.5, 5 or 6 is 2 and longer is 2.5.
|
|
28239
|
+
*/
|
|
28240
|
+
_getCoefficient(life) {
|
|
28241
|
+
if (life <= 4) return 1.5;
|
|
28242
|
+
if (life <= 6) return 2;
|
|
28243
|
+
return 2.5;
|
|
28244
|
+
}
|
|
28245
|
+
};
|
|
28246
|
+
/**
|
|
28247
|
+
* Rounds the way Excel does here: first to Excel's 15 significant digits, so that
|
|
28248
|
+
* 327.49999999999994 counts as 327.5, then to a whole number with halves away from zero.
|
|
28249
|
+
*/
|
|
28250
|
+
function excelRound(value) {
|
|
28251
|
+
const rounded = Number(value.toPrecision(15));
|
|
28252
|
+
return Math.sign(rounded) * Math.round(Math.abs(rounded));
|
|
28253
|
+
}
|
|
28254
|
+
/**
|
|
28255
|
+
* Days from the purchase to the end of the first period, and the days in that year, as AMORDEGRC
|
|
28256
|
+
* counts them. This differs from YEARFRAC: with actual day counts a date on 28 or 29 February of a
|
|
28257
|
+
* leap year counts as 28 February, actual/actual uses the purchase year's length, and the US 30/360
|
|
28258
|
+
* method only moves the end of February when the purchase is also at the end of February.
|
|
28259
|
+
*/
|
|
28260
|
+
function getFirstPeriodDays(purchaseSerialNumber, firstPeriodSerialNumber, basis, dateSystem) {
|
|
28261
|
+
const parts = (serialNumber) => {
|
|
28262
|
+
const date = (0, _univerjs_core.excelSerialToDate)(serialNumber, dateSystem);
|
|
28263
|
+
return {
|
|
28264
|
+
year: date.getUTCFullYear(),
|
|
28265
|
+
month: date.getUTCMonth() + 1,
|
|
28266
|
+
day: date.getUTCDate()
|
|
28267
|
+
};
|
|
28268
|
+
};
|
|
28269
|
+
const purchase = parts(purchaseSerialNumber);
|
|
28270
|
+
const firstPeriod = parts(firstPeriodSerialNumber);
|
|
28271
|
+
if (basis === 1 || basis === 3) {
|
|
28272
|
+
const toFebruary28 = (serialNumber, date) => isLeapYear(date.year) && date.month === 2 && date.day >= 28 ? serialNumber - (date.day - 28) : serialNumber;
|
|
28273
|
+
return {
|
|
28274
|
+
days: toFebruary28(firstPeriodSerialNumber, firstPeriod) - toFebruary28(purchaseSerialNumber, purchase),
|
|
28275
|
+
yearDays: basis === 3 || !isLeapYear(purchase.year) ? 365 : 366
|
|
28276
|
+
};
|
|
28277
|
+
}
|
|
28278
|
+
let startDay = purchase.day;
|
|
28279
|
+
let endDay = firstPeriod.day;
|
|
28280
|
+
if (basis === 0) {
|
|
28281
|
+
const isEndOfFebruary = (date) => date.month === 2 && date.day === getDaysInMonth(date.year, 1);
|
|
28282
|
+
if (isEndOfFebruary(firstPeriod) && isEndOfFebruary(purchase)) endDay = 30;
|
|
28283
|
+
if (endDay === 31 && startDay >= 30) endDay = 30;
|
|
28284
|
+
if (startDay === 31 || isEndOfFebruary(purchase)) startDay = 30;
|
|
28285
|
+
} else {
|
|
28286
|
+
startDay = Math.min(startDay, 30);
|
|
28287
|
+
endDay = Math.min(endDay, 30);
|
|
28288
|
+
}
|
|
28289
|
+
return {
|
|
28290
|
+
days: (firstPeriod.year - purchase.year) * 360 + (firstPeriod.month - purchase.month) * 30 + (endDay - startDay),
|
|
28291
|
+
yearDays: 360
|
|
28292
|
+
};
|
|
28293
|
+
}
|
|
28294
|
+
const MIN_SKIPPED_PERIODS = 1e4;
|
|
28295
|
+
/**
|
|
28296
|
+
* A tiny rate gives a life of many years, and a period can ask for any of them. Each regular period
|
|
28297
|
+
* multiplies the book value by (1 - rate), so a long run of them is skipped in one step instead of
|
|
28298
|
+
* one by one, stopping before the book value would fall below the salvage value.
|
|
28299
|
+
*/
|
|
28300
|
+
function skipRegularPeriods(countedPeriod, lastRegularPeriod, bookValue, salvageValue, rate) {
|
|
28301
|
+
let periods = Math.floor(lastRegularPeriod) - countedPeriod;
|
|
28302
|
+
if (periods >= MIN_SKIPPED_PERIODS && rate > 0 && rate < 1 && bookValue > salvageValue && salvageValue > 0) periods = Math.min(periods, Math.floor(Math.log(salvageValue / bookValue) / Math.log(1 - rate)) - 1);
|
|
28303
|
+
if (periods < MIN_SKIPPED_PERIODS || rate <= 0 || rate >= 1 || bookValue <= salvageValue) return {
|
|
28304
|
+
periods: 0,
|
|
28305
|
+
bookValue
|
|
28306
|
+
};
|
|
28307
|
+
return {
|
|
28308
|
+
periods,
|
|
28309
|
+
bookValue: bookValue * (1 - rate) ** periods
|
|
28310
|
+
};
|
|
28311
|
+
}
|
|
28312
|
+
|
|
27989
28313
|
// src/functions/financial/amorlinc/index.ts
|
|
27990
28314
|
var Amorlinc = class extends BaseFunction {
|
|
27991
28315
|
constructor(..._args) {
|
|
@@ -28993,7 +29317,7 @@ var Npv = class extends BaseFunction {
|
|
|
28993
29317
|
if (isError) return errorObject;
|
|
28994
29318
|
const rateValue = +rate.getValue();
|
|
28995
29319
|
const result = calculateNpv(rateValue, values);
|
|
28996
|
-
if (Number.isNaN(result) || Math.abs(result) ===
|
|
29320
|
+
if (Number.isNaN(result) || Math.abs(result) === 1e400) return ErrorValueObject.create("#DIV/0!");
|
|
28997
29321
|
if (rowIndex === 0 && columnIndex === 0) return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));
|
|
28998
29322
|
return NumberValueObject.create(result);
|
|
28999
29323
|
}
|
|
@@ -30467,6 +30791,7 @@ var Yieldmat = class extends BaseFunction {
|
|
|
30467
30791
|
const functionFinancial = [
|
|
30468
30792
|
[Accrint, "ACCRINT"],
|
|
30469
30793
|
[Accrintm, "ACCRINTM"],
|
|
30794
|
+
[Amordegrc, "AMORDEGRC"],
|
|
30470
30795
|
[Amorlinc, "AMORLINC"],
|
|
30471
30796
|
[Coupdaybs, "COUPDAYBS"],
|
|
30472
30797
|
[Coupdays, "COUPDAYS"],
|
|
@@ -34825,7 +35150,7 @@ var Xlookup = class extends BaseFunction {
|
|
|
34825
35150
|
const matches = searchArray.compare(value, "=");
|
|
34826
35151
|
return searchModeValue === -1 ? matches.getLastTruePosition() : matches.getFirstTruePosition();
|
|
34827
35152
|
}
|
|
34828
|
-
if (matchModeValue === -1 || matchModeValue === 1) return searchArray.orderSearch(value, matchModeValue === 1 ? 2 : 1, searchModeValue === -1, false, true);
|
|
35153
|
+
if (matchModeValue === -1 || matchModeValue === 1) return searchArray.orderSearch(value, matchModeValue === 1 ? 2 : 1, searchModeValue === -1, false, true, true);
|
|
34829
35154
|
return this._findExactPosition(value, searchArray, searchModeValue !== -1);
|
|
34830
35155
|
}
|
|
34831
35156
|
_findExactPosition(value, searchArray, isFirst) {
|
|
@@ -34846,6 +35171,7 @@ var Xlookup = class extends BaseFunction {
|
|
|
34846
35171
|
_isExactMatch(candidate, value) {
|
|
34847
35172
|
if (candidate.isError() || value.isError()) return candidate.isError() && value.isError() && candidate.getValue() === value.getValue();
|
|
34848
35173
|
if (candidate.isNull() !== value.isNull() || candidate.isNumber() !== value.isNumber() || candidate.isString() !== value.isString() || candidate.isBoolean() !== value.isBoolean()) return false;
|
|
35174
|
+
if (value.isString() && isWildcard(String(value.getValue()))) return isLiteralTextMatch(String(candidate.getValue()), String(value.getValue()));
|
|
34849
35175
|
return candidate.isEqual(value).getValue() === true;
|
|
34850
35176
|
}
|
|
34851
35177
|
_blankResultAsZero(value) {
|
|
@@ -34931,12 +35257,12 @@ var Xmatch = class extends BaseFunction {
|
|
|
34931
35257
|
if (position == null) return ErrorValueObject.create("#N/A");
|
|
34932
35258
|
rowOrColumn = _lookupArray.getRowCount() === 1 ? position.column : position.row;
|
|
34933
35259
|
} else if (matchMode === -1 || matchMode === 1) {
|
|
34934
|
-
const position = _lookupArray.orderSearch(lookupValue, matchMode === 1 ? 2 : 1, searchMode === -1);
|
|
35260
|
+
const position = _lookupArray.orderSearch(lookupValue, matchMode === 1 ? 2 : 1, searchMode === -1, false, true, true);
|
|
34935
35261
|
if (position == null) return ErrorValueObject.create("#N/A");
|
|
34936
35262
|
if (position instanceof ErrorValueObject) return position;
|
|
34937
35263
|
rowOrColumn = _lookupArray.getRowCount() === 1 ? position.column : position.row;
|
|
34938
35264
|
} else {
|
|
34939
|
-
const matchObject =
|
|
35265
|
+
const matchObject = this._exactMatches(_lookupArray, lookupValue);
|
|
34940
35266
|
let position;
|
|
34941
35267
|
if (searchMode !== -1) position = matchObject.getFirstTruePosition();
|
|
34942
35268
|
else position = matchObject.getLastTruePosition();
|
|
@@ -34946,6 +35272,11 @@ var Xmatch = class extends BaseFunction {
|
|
|
34946
35272
|
if (rowOrColumn == null) return ErrorValueObject.create("#N/A");
|
|
34947
35273
|
return NumberValueObject.create(rowOrColumn + 1);
|
|
34948
35274
|
}
|
|
35275
|
+
_exactMatches(lookupArray, lookupValue) {
|
|
35276
|
+
if (!lookupValue.isString() || !isWildcard(String(lookupValue.getValue()))) return lookupArray.isEqual(lookupValue);
|
|
35277
|
+
const text = String(lookupValue.getValue());
|
|
35278
|
+
return lookupArray.mapValue((item) => BooleanValueObject.create(item.isString() && isLiteralTextMatch(String(item.getValue()), text)));
|
|
35279
|
+
}
|
|
34949
35280
|
};
|
|
34950
35281
|
|
|
34951
35282
|
// src/functions/lookup/function-map.ts
|
|
@@ -36045,6 +36376,28 @@ var Int = class extends BaseFunction {
|
|
|
36045
36376
|
}
|
|
36046
36377
|
};
|
|
36047
36378
|
|
|
36379
|
+
// src/functions/math/iso-ceiling/index.ts
|
|
36380
|
+
/**
|
|
36381
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
36382
|
+
*
|
|
36383
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
36384
|
+
* you may not use this file except in compliance with the License.
|
|
36385
|
+
* You may obtain a copy of the License at
|
|
36386
|
+
*
|
|
36387
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
36388
|
+
*
|
|
36389
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
36390
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
36391
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
36392
|
+
* See the License for the specific language governing permissions and
|
|
36393
|
+
* limitations under the License.
|
|
36394
|
+
*/
|
|
36395
|
+
/**
|
|
36396
|
+
* ISO.CEILING rounds a number up to the nearest multiple of the significance's absolute value, whatever the
|
|
36397
|
+
* signs, and returns 0 when either argument is 0. Excel defines it with the same result as CEILING.PRECISE.
|
|
36398
|
+
*/
|
|
36399
|
+
var IsoCeiling = class extends CeilingPrecise {};
|
|
36400
|
+
|
|
36048
36401
|
// src/functions/math/lcm/index.ts
|
|
36049
36402
|
var Lcm = class extends BaseFunction {
|
|
36050
36403
|
constructor(..._args) {
|
|
@@ -36880,13 +37233,7 @@ var Roundbank = class extends BaseFunction {
|
|
|
36880
37233
|
_roundBank(number, numDigits) {
|
|
36881
37234
|
if (numDigits > 16) return number;
|
|
36882
37235
|
if (numDigits < -16) return 0;
|
|
36883
|
-
|
|
36884
|
-
const adjustedNum = +(number * multiplier).toFixed(8);
|
|
36885
|
-
const integerPart = Math.floor(adjustedNum);
|
|
36886
|
-
const decimalPart = adjustedNum - integerPart;
|
|
36887
|
-
let result = Math.round(adjustedNum);
|
|
36888
|
-
if (decimalPart > .49999999 && decimalPart < .50000001) result = integerPart % 2 === 0 ? integerPart : integerPart + 1;
|
|
36889
|
-
return numDigits ? result / multiplier : result;
|
|
37236
|
+
return roundHalfEven(number, numDigits);
|
|
36890
37237
|
}
|
|
36891
37238
|
};
|
|
36892
37239
|
|
|
@@ -37855,6 +38202,7 @@ const functionMath = [
|
|
|
37855
38202
|
[FloorPrecise, "FLOOR.PRECISE"],
|
|
37856
38203
|
[Gcd, "GCD"],
|
|
37857
38204
|
[Int, "INT"],
|
|
38205
|
+
[IsoCeiling, "ISO.CEILING"],
|
|
37858
38206
|
[Lcm, "LCM"],
|
|
37859
38207
|
[Ln, "LN"],
|
|
37860
38208
|
[Log, "LOG"],
|
|
@@ -39184,7 +39532,7 @@ var Frequency = class extends BaseFunction {
|
|
|
39184
39532
|
const index = _binsArrayValues[i].index;
|
|
39185
39533
|
if (i === 0) {
|
|
39186
39534
|
newBinsArrayValues[index] = {
|
|
39187
|
-
start: -
|
|
39535
|
+
start: -1e400,
|
|
39188
39536
|
end: _binsArrayValues[i].value
|
|
39189
39537
|
};
|
|
39190
39538
|
continue;
|
|
@@ -39196,7 +39544,7 @@ var Frequency = class extends BaseFunction {
|
|
|
39196
39544
|
}
|
|
39197
39545
|
newBinsArrayValues.push({
|
|
39198
39546
|
start: _binsArrayValues[_binsArrayValues.length - 1].value,
|
|
39199
|
-
end:
|
|
39547
|
+
end: 1e400
|
|
39200
39548
|
});
|
|
39201
39549
|
return newBinsArrayValues;
|
|
39202
39550
|
}
|
|
@@ -41813,6 +42161,21 @@ var Bahttext = class extends BaseFunction {
|
|
|
41813
42161
|
};
|
|
41814
42162
|
|
|
41815
42163
|
// src/functions/text/char/index.ts
|
|
42164
|
+
/**
|
|
42165
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
42166
|
+
*
|
|
42167
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
42168
|
+
* you may not use this file except in compliance with the License.
|
|
42169
|
+
* You may obtain a copy of the License at
|
|
42170
|
+
*
|
|
42171
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
42172
|
+
*
|
|
42173
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
42174
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
42175
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42176
|
+
* See the License for the specific language governing permissions and
|
|
42177
|
+
* limitations under the License.
|
|
42178
|
+
*/
|
|
41816
42179
|
const filterCodeArray$1 = Object.values(_univerjs_core.DataStreamTreeTokenType).filter((value) => {
|
|
41817
42180
|
return [
|
|
41818
42181
|
_univerjs_core.DataStreamTreeTokenType.TABLE_START,
|
|
@@ -41843,8 +42206,9 @@ var Char = class extends BaseFunction {
|
|
|
41843
42206
|
if (isError) return errorObject;
|
|
41844
42207
|
const [numberObject] = variants;
|
|
41845
42208
|
const numberValue = Math.floor(+numberObject.getValue());
|
|
41846
|
-
if (numberValue
|
|
41847
|
-
|
|
42209
|
+
if (numberValue < 1 || numberValue > 1114111) return ErrorValueObject.create("#VALUE!");
|
|
42210
|
+
if (isSurrogateCodePoint(numberValue) || isNonCharacterCodePoint(numberValue)) return ErrorValueObject.create("#N/A");
|
|
42211
|
+
let result = String.fromCodePoint(numberValue);
|
|
41848
42212
|
if (filterCodeArray$1.some((value) => value === result)) result = String.fromCharCode(1);
|
|
41849
42213
|
return StringValueObject.create(result);
|
|
41850
42214
|
}
|
|
@@ -41893,8 +42257,8 @@ var Code = class extends BaseFunction {
|
|
|
41893
42257
|
if (text.isNull()) return ErrorValueObject.create("#VALUE!");
|
|
41894
42258
|
let textValue = text.getValue().toLocaleString();
|
|
41895
42259
|
if (text.isBoolean()) textValue = textValue.toLocaleUpperCase();
|
|
41896
|
-
|
|
41897
|
-
|
|
42260
|
+
const result = textValue.codePointAt(0);
|
|
42261
|
+
if (result === void 0 || isSurrogateCodePoint(result)) return ErrorValueObject.create("#VALUE!");
|
|
41898
42262
|
return NumberValueObject.create(result);
|
|
41899
42263
|
}
|
|
41900
42264
|
};
|
|
@@ -42041,6 +42405,125 @@ var Dollar = class extends BaseFunction {
|
|
|
42041
42405
|
}
|
|
42042
42406
|
};
|
|
42043
42407
|
|
|
42408
|
+
// src/functions/text/euroconvert/index.ts
|
|
42409
|
+
const EURO_CURRENCIES = {
|
|
42410
|
+
BEF: {
|
|
42411
|
+
rate: 40.3399,
|
|
42412
|
+
precision: 0
|
|
42413
|
+
},
|
|
42414
|
+
LUF: {
|
|
42415
|
+
rate: 40.3399,
|
|
42416
|
+
precision: 0
|
|
42417
|
+
},
|
|
42418
|
+
DEM: {
|
|
42419
|
+
rate: 1.95583,
|
|
42420
|
+
precision: 2
|
|
42421
|
+
},
|
|
42422
|
+
ESP: {
|
|
42423
|
+
rate: 166.386,
|
|
42424
|
+
precision: 0
|
|
42425
|
+
},
|
|
42426
|
+
FRF: {
|
|
42427
|
+
rate: 6.55957,
|
|
42428
|
+
precision: 2
|
|
42429
|
+
},
|
|
42430
|
+
IEP: {
|
|
42431
|
+
rate: .787564,
|
|
42432
|
+
precision: 2
|
|
42433
|
+
},
|
|
42434
|
+
ITL: {
|
|
42435
|
+
rate: 1936.27,
|
|
42436
|
+
precision: 0
|
|
42437
|
+
},
|
|
42438
|
+
NLG: {
|
|
42439
|
+
rate: 2.20371,
|
|
42440
|
+
precision: 2
|
|
42441
|
+
},
|
|
42442
|
+
ATS: {
|
|
42443
|
+
rate: 13.7603,
|
|
42444
|
+
precision: 2
|
|
42445
|
+
},
|
|
42446
|
+
PTE: {
|
|
42447
|
+
rate: 200.482,
|
|
42448
|
+
precision: 0
|
|
42449
|
+
},
|
|
42450
|
+
FIM: {
|
|
42451
|
+
rate: 5.94573,
|
|
42452
|
+
precision: 2
|
|
42453
|
+
},
|
|
42454
|
+
GRD: {
|
|
42455
|
+
rate: 340.75,
|
|
42456
|
+
precision: 0
|
|
42457
|
+
},
|
|
42458
|
+
SIT: {
|
|
42459
|
+
rate: 239.64,
|
|
42460
|
+
precision: 2
|
|
42461
|
+
},
|
|
42462
|
+
EUR: {
|
|
42463
|
+
rate: 1,
|
|
42464
|
+
precision: 2
|
|
42465
|
+
}
|
|
42466
|
+
};
|
|
42467
|
+
const EURO = "EUR";
|
|
42468
|
+
const MIN_TRIANGULATION_PRECISION = 3;
|
|
42469
|
+
const MAX_TRIANGULATION_PRECISION = 32767;
|
|
42470
|
+
const MAX_EURO_DECIMALS = 15;
|
|
42471
|
+
const roundHalfAwayFromZero = (value, decimals) => value < 0 ? -round(-value, decimals) : round(value, decimals);
|
|
42472
|
+
var Euroconvert = class extends BaseFunction {
|
|
42473
|
+
constructor(..._args) {
|
|
42474
|
+
super(..._args);
|
|
42475
|
+
_defineProperty(this, "minParams", 3);
|
|
42476
|
+
_defineProperty(this, "maxParams", 5);
|
|
42477
|
+
}
|
|
42478
|
+
calculate(number, source, target, fullPrecision, triangulationPrecision) {
|
|
42479
|
+
const { isError, errorObject, variants } = checkVariantsErrorIsArray(number, source, target, fullPrecision ?? BooleanValueObject.create(false));
|
|
42480
|
+
if (isError) return errorObject;
|
|
42481
|
+
const [numberObject, sourceObject, targetObject, fullPrecisionObject] = variants;
|
|
42482
|
+
const { isError: isNotNumeric, errorObject: notNumericObject, variants: numericVariants } = checkVariantsErrorIsStringToNumber(numberObject, fullPrecisionObject);
|
|
42483
|
+
if (isNotNumeric) return notNumericObject;
|
|
42484
|
+
const [numericNumberObject, numericFullPrecisionObject] = numericVariants;
|
|
42485
|
+
const numberValue = +numericNumberObject.getValue();
|
|
42486
|
+
const isFullPrecision = +numericFullPrecisionObject.getValue() !== 0;
|
|
42487
|
+
const sourceCurrency = this._getCurrency(sourceObject);
|
|
42488
|
+
const targetCurrency = this._getCurrency(targetObject);
|
|
42489
|
+
if (Number.isNaN(numberValue) || !sourceCurrency || !targetCurrency) return ErrorValueObject.create("#VALUE!");
|
|
42490
|
+
const triangulationDecimals = this._getTriangulationDecimals(triangulationPrecision);
|
|
42491
|
+
if (typeof triangulationDecimals !== "number" && triangulationDecimals !== null) return triangulationDecimals;
|
|
42492
|
+
if (sourceCurrency === targetCurrency) return NumberValueObject.create(numberValue);
|
|
42493
|
+
let result;
|
|
42494
|
+
if (sourceCurrency === EURO_CURRENCIES[EURO]) result = numberValue * targetCurrency.rate;
|
|
42495
|
+
else {
|
|
42496
|
+
let euros = numberValue / sourceCurrency.rate;
|
|
42497
|
+
if (triangulationDecimals !== null) euros = roundHalfAwayFromZero(euros, triangulationDecimals);
|
|
42498
|
+
result = euros * targetCurrency.rate;
|
|
42499
|
+
}
|
|
42500
|
+
if (!isFullPrecision) result = roundHalfAwayFromZero(result, targetCurrency.precision);
|
|
42501
|
+
return NumberValueObject.create(result);
|
|
42502
|
+
}
|
|
42503
|
+
_getCurrency(code) {
|
|
42504
|
+
if (!code.isString()) return;
|
|
42505
|
+
const isoCode = `${code.getValue()}`.toUpperCase();
|
|
42506
|
+
return Object.prototype.hasOwnProperty.call(EURO_CURRENCIES, isoCode) ? EURO_CURRENCIES[isoCode] : void 0;
|
|
42507
|
+
}
|
|
42508
|
+
/**
|
|
42509
|
+
* The decimals the intermediate euro value is rounded to, `null` when the argument is
|
|
42510
|
+
* omitted, or the error it produces.
|
|
42511
|
+
*/
|
|
42512
|
+
_getTriangulationDecimals(triangulationPrecision) {
|
|
42513
|
+
if (!triangulationPrecision) return null;
|
|
42514
|
+
const precisionObject = checkVariantErrorIsArray(triangulationPrecision);
|
|
42515
|
+
if (precisionObject.isError()) return precisionObject;
|
|
42516
|
+
const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(precisionObject);
|
|
42517
|
+
if (isError) return errorObject;
|
|
42518
|
+
const precision = +variants[0].getValue();
|
|
42519
|
+
if (Number.isNaN(precision)) return ErrorValueObject.create("#VALUE!");
|
|
42520
|
+
const decimals = roundHalfEven(precision, 0);
|
|
42521
|
+
if (decimals > MAX_TRIANGULATION_PRECISION) return ErrorValueObject.create("#NUM!");
|
|
42522
|
+
if (decimals < MIN_TRIANGULATION_PRECISION) return ErrorValueObject.create("#VALUE!");
|
|
42523
|
+
return Math.min(decimals, MAX_EURO_DECIMALS);
|
|
42524
|
+
}
|
|
42525
|
+
};
|
|
42526
|
+
|
|
42044
42527
|
// src/functions/text/exact/index.ts
|
|
42045
42528
|
var Exact = class extends BaseFunction {
|
|
42046
42529
|
constructor(..._args) {
|
|
@@ -42141,58 +42624,6 @@ var Find = class extends BaseFunction {
|
|
|
42141
42624
|
}
|
|
42142
42625
|
};
|
|
42143
42626
|
|
|
42144
|
-
// src/engine/utils/char-kit.ts
|
|
42145
|
-
/**
|
|
42146
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
42147
|
-
*
|
|
42148
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
42149
|
-
* you may not use this file except in compliance with the License.
|
|
42150
|
-
* You may obtain a copy of the License at
|
|
42151
|
-
*
|
|
42152
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
42153
|
-
*
|
|
42154
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
42155
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
42156
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42157
|
-
* See the License for the specific language governing permissions and
|
|
42158
|
-
* limitations under the License.
|
|
42159
|
-
*/
|
|
42160
|
-
/**
|
|
42161
|
-
* excel logic is cofusing, so we use google sheet logic
|
|
42162
|
-
*
|
|
42163
|
-
* @param text
|
|
42164
|
-
* @returns number
|
|
42165
|
-
*/
|
|
42166
|
-
function charLenByte(text) {
|
|
42167
|
-
let byteCount = 0;
|
|
42168
|
-
for (let i = 0; i < text.length; i++) byteCount += getCharLenByteInText(text, i);
|
|
42169
|
-
return byteCount;
|
|
42170
|
-
}
|
|
42171
|
-
function getCharLenByteInText(text, charIndex, direction = "ltr") {
|
|
42172
|
-
return getCodePoint(text, charIndex, direction) > 255 ? 2 : 1;
|
|
42173
|
-
}
|
|
42174
|
-
function highSurrogate(charCode) {
|
|
42175
|
-
return charCode >= 55296 && charCode <= 56319;
|
|
42176
|
-
}
|
|
42177
|
-
function lowSurrogate(charCode) {
|
|
42178
|
-
return charCode >= 56320 && charCode <= 57343;
|
|
42179
|
-
}
|
|
42180
|
-
function surrogatePair(highSurrogate, lowSurrogate) {
|
|
42181
|
-
return ((highSurrogate & 1023) << 10) + (lowSurrogate & 1023) + 65536;
|
|
42182
|
-
}
|
|
42183
|
-
function getCodePoint(str, index, direction = "ltr") {
|
|
42184
|
-
const charCode = str.charCodeAt(index);
|
|
42185
|
-
if (direction === "ltr" && highSurrogate(charCode) && index + 1 < str.length) {
|
|
42186
|
-
const nextCharCode = str.charCodeAt(index + 1);
|
|
42187
|
-
if (lowSurrogate(nextCharCode)) return surrogatePair(charCode, nextCharCode);
|
|
42188
|
-
}
|
|
42189
|
-
if (direction === "rtl" && lowSurrogate(charCode) && index - 1 >= 0) {
|
|
42190
|
-
const prevCharCode = str.charCodeAt(index - 1);
|
|
42191
|
-
if (highSurrogate(prevCharCode)) return surrogatePair(prevCharCode, charCode);
|
|
42192
|
-
}
|
|
42193
|
-
return charCode;
|
|
42194
|
-
}
|
|
42195
|
-
|
|
42196
42627
|
// src/functions/text/findb/index.ts
|
|
42197
42628
|
var Findb = class extends BaseFunction {
|
|
42198
42629
|
constructor(..._args) {
|
|
@@ -43006,7 +43437,7 @@ function tokenizer(regExpString) {
|
|
|
43006
43437
|
if (match) {
|
|
43007
43438
|
if (stack.length === 0) throwError(i);
|
|
43008
43439
|
const min = Number.parseInt(match[1], 10);
|
|
43009
|
-
const max = match[2] ? match[3] ? Number.parseInt(match[3], 10) :
|
|
43440
|
+
const max = match[2] ? match[3] ? Number.parseInt(match[3], 10) : 1e400 : min;
|
|
43010
43441
|
i += match[0].length;
|
|
43011
43442
|
stack.push({
|
|
43012
43443
|
type: 5,
|
|
@@ -43034,7 +43465,7 @@ function tokenizer(regExpString) {
|
|
|
43034
43465
|
stack.push({
|
|
43035
43466
|
type: 5,
|
|
43036
43467
|
min: 1,
|
|
43037
|
-
max:
|
|
43468
|
+
max: 1e400,
|
|
43038
43469
|
value: stack.pop()
|
|
43039
43470
|
});
|
|
43040
43471
|
break;
|
|
@@ -43043,7 +43474,7 @@ function tokenizer(regExpString) {
|
|
|
43043
43474
|
stack.push({
|
|
43044
43475
|
type: 5,
|
|
43045
43476
|
min: 0,
|
|
43046
|
-
max:
|
|
43477
|
+
max: 1e400,
|
|
43047
43478
|
value: stack.pop()
|
|
43048
43479
|
});
|
|
43049
43480
|
break;
|
|
@@ -43178,7 +43609,7 @@ function isSafeRegExp(regExp, options) {
|
|
|
43178
43609
|
const validateToken = (token, depth) => {
|
|
43179
43610
|
let _depth = depth;
|
|
43180
43611
|
if (token.type === 5) {
|
|
43181
|
-
if (depth > 0 && (token.min === 0 || token.max ===
|
|
43612
|
+
if (depth > 0 && (token.min === 0 || token.max === 1e400)) return false;
|
|
43182
43613
|
if (isDangerousRepetition(token)) {
|
|
43183
43614
|
count++;
|
|
43184
43615
|
if (count > limit) return false;
|
|
@@ -43533,15 +43964,15 @@ var Search = class extends BaseFunction {
|
|
|
43533
43964
|
return resultArray;
|
|
43534
43965
|
}
|
|
43535
43966
|
_handleSingleObject(findText, withinText, startNum) {
|
|
43536
|
-
const findTextValue = getTextValueOfNumberFormat(findText)
|
|
43537
|
-
const withinTextValue = getTextValueOfNumberFormat(withinText)
|
|
43967
|
+
const findTextValue = upperCaseKeepingPositions(getTextValueOfNumberFormat(findText));
|
|
43968
|
+
const withinTextValue = upperCaseKeepingPositions(getTextValueOfNumberFormat(withinText));
|
|
43538
43969
|
const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(startNum);
|
|
43539
43970
|
if (isError) return errorObject;
|
|
43540
43971
|
const [startNumObject] = variants;
|
|
43541
43972
|
const startNumValue = Math.floor(+startNumObject.getValue());
|
|
43542
43973
|
if (withinText.isNull() || startNumValue <= 0 || startNumValue > withinTextValue.length) return ErrorValueObject.create("#VALUE!");
|
|
43543
43974
|
if (findText.isNull() || findTextValue.length === 0) return NumberValueObject.create(startNumValue);
|
|
43544
|
-
const result = withinTextValue
|
|
43975
|
+
const result = searchWildcard(withinTextValue, parseWildcardPattern(findTextValue), startNumValue - 1);
|
|
43545
43976
|
if (result === -1) return ErrorValueObject.create("#VALUE!");
|
|
43546
43977
|
return NumberValueObject.create(result + 1);
|
|
43547
43978
|
}
|
|
@@ -43573,15 +44004,15 @@ var Searchb = class extends BaseFunction {
|
|
|
43573
44004
|
return resultArray;
|
|
43574
44005
|
}
|
|
43575
44006
|
_handleSingleObject(findText, withinText, startNum) {
|
|
43576
|
-
const findTextValue = getTextValueOfNumberFormat(findText)
|
|
43577
|
-
const withinTextValue = getTextValueOfNumberFormat(withinText)
|
|
44007
|
+
const findTextValue = upperCaseKeepingPositions(getTextValueOfNumberFormat(findText));
|
|
44008
|
+
const withinTextValue = upperCaseKeepingPositions(getTextValueOfNumberFormat(withinText));
|
|
43578
44009
|
const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(startNum);
|
|
43579
44010
|
if (isError) return errorObject;
|
|
43580
44011
|
const [startNumObject] = variants;
|
|
43581
44012
|
const startNumValue = Math.floor(+startNumObject.getValue());
|
|
43582
44013
|
if (withinText.isNull() || startNumValue <= 0 || startNumValue > withinTextValue.length) return ErrorValueObject.create("#VALUE!");
|
|
43583
44014
|
if (findText.isNull() || findTextValue.length === 0) return NumberValueObject.create(startNumValue);
|
|
43584
|
-
const index = withinTextValue
|
|
44015
|
+
const index = searchWildcard(withinTextValue, parseWildcardPattern(findTextValue), startNumValue - 1);
|
|
43585
44016
|
if (index === -1) return ErrorValueObject.create("#VALUE!");
|
|
43586
44017
|
const result = charLenByte(withinTextValue.substring(0, index)) + 1;
|
|
43587
44018
|
return NumberValueObject.create(result);
|
|
@@ -44237,12 +44668,27 @@ var Trim = class extends BaseFunction {
|
|
|
44237
44668
|
if (text.isNull()) return StringValueObject.create("");
|
|
44238
44669
|
let textValue = `${text.getValue()}`;
|
|
44239
44670
|
if (text.isBoolean()) textValue = textValue.toLocaleUpperCase();
|
|
44240
|
-
textValue = textValue.
|
|
44671
|
+
textValue = textValue.replace(/^[ \u3000]+|[ \u3000]+$/g, "").replace(/[ \u3000]{2,}/g, (run) => run.charAt(0));
|
|
44241
44672
|
return StringValueObject.create(textValue);
|
|
44242
44673
|
}
|
|
44243
44674
|
};
|
|
44244
44675
|
|
|
44245
44676
|
// src/functions/text/unichar/index.ts
|
|
44677
|
+
/**
|
|
44678
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
44679
|
+
*
|
|
44680
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
44681
|
+
* you may not use this file except in compliance with the License.
|
|
44682
|
+
* You may obtain a copy of the License at
|
|
44683
|
+
*
|
|
44684
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
44685
|
+
*
|
|
44686
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
44687
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
44688
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
44689
|
+
* See the License for the specific language governing permissions and
|
|
44690
|
+
* limitations under the License.
|
|
44691
|
+
*/
|
|
44246
44692
|
const filterCodeArray = Object.values(_univerjs_core.DataStreamTreeTokenType).filter((value) => {
|
|
44247
44693
|
return [
|
|
44248
44694
|
_univerjs_core.DataStreamTreeTokenType.TABLE_START,
|
|
@@ -44274,8 +44720,8 @@ var Unichar = class extends BaseFunction {
|
|
|
44274
44720
|
const [numberObject] = variants;
|
|
44275
44721
|
const numberValue = Math.floor(+numberObject.getValue());
|
|
44276
44722
|
if (numberValue < 1 || numberValue > 1114111) return ErrorValueObject.create("#VALUE!");
|
|
44277
|
-
if (numberValue
|
|
44278
|
-
let result = String.
|
|
44723
|
+
if (isSurrogateCodePoint(numberValue) || isNonCharacterCodePoint(numberValue)) return ErrorValueObject.create("#N/A");
|
|
44724
|
+
let result = String.fromCodePoint(numberValue);
|
|
44279
44725
|
if (filterCodeArray.some((value) => value === result)) result = String.fromCharCode(1);
|
|
44280
44726
|
return StringValueObject.create(result);
|
|
44281
44727
|
}
|
|
@@ -44301,7 +44747,8 @@ var Unicode = class extends BaseFunction {
|
|
|
44301
44747
|
if (text.isNull()) return ErrorValueObject.create("#VALUE!");
|
|
44302
44748
|
let textValue = text.getValue().toLocaleString();
|
|
44303
44749
|
if (text.isBoolean()) textValue = textValue.toLocaleUpperCase();
|
|
44304
|
-
const result = textValue.
|
|
44750
|
+
const result = textValue.codePointAt(0);
|
|
44751
|
+
if (result === void 0 || result >= 55296 && result <= 57343) return ErrorValueObject.create("#VALUE!");
|
|
44305
44752
|
return NumberValueObject.create(result);
|
|
44306
44753
|
}
|
|
44307
44754
|
};
|
|
@@ -44421,6 +44868,7 @@ const functionText = [
|
|
|
44421
44868
|
[Dbcs, "DBCS"],
|
|
44422
44869
|
[Dollar, "DOLLAR"],
|
|
44423
44870
|
[Exact, "EXACT"],
|
|
44871
|
+
[Euroconvert, "EUROCONVERT"],
|
|
44424
44872
|
[Find, "FIND"],
|
|
44425
44873
|
[Findb, "FINDB"],
|
|
44426
44874
|
[Fixed, "FIXED"],
|
|
@@ -44593,7 +45041,7 @@ const ALL_IMPLEMENTED_FUNCTIONS_SET = new Set(ALL_IMPLEMENTED_FUNCTIONS.map(([_,
|
|
|
44593
45041
|
|
|
44594
45042
|
// package.json
|
|
44595
45043
|
var name = "@univerjs/engine-formula";
|
|
44596
|
-
var version = "1.
|
|
45044
|
+
var version = "1.6.1";
|
|
44597
45045
|
|
|
44598
45046
|
// src/services/global-computing-status.service.ts
|
|
44599
45047
|
var GlobalComputingStatusService = class extends _univerjs_core.Disposable {
|
|
@@ -57841,7 +58289,7 @@ const FUNCTION_LIST_TEXT = [
|
|
|
57841
58289
|
name: "engine-formula.functionList.EUROCONVERT.functionParameter.fullPrecision.name",
|
|
57842
58290
|
detail: "engine-formula.functionList.EUROCONVERT.functionParameter.fullPrecision.detail",
|
|
57843
58291
|
example: "false",
|
|
57844
|
-
require:
|
|
58292
|
+
require: 0,
|
|
57845
58293
|
repeat: 0
|
|
57846
58294
|
},
|
|
57847
58295
|
{
|
|
@@ -59527,6 +59975,12 @@ Object.defineProperty(exports, "normalizeSheetName", {
|
|
|
59527
59975
|
return normalizeSheetName;
|
|
59528
59976
|
}
|
|
59529
59977
|
});
|
|
59978
|
+
Object.defineProperty(exports, "normalizeTextForComparison", {
|
|
59979
|
+
enumerable: true,
|
|
59980
|
+
get: function () {
|
|
59981
|
+
return normalizeTextForComparison;
|
|
59982
|
+
}
|
|
59983
|
+
});
|
|
59530
59984
|
Object.defineProperty(exports, "operatorToken", {
|
|
59531
59985
|
enumerable: true,
|
|
59532
59986
|
get: function () {
|
|
@@ -59604,4 +60058,10 @@ Object.defineProperty(exports, "unquoteSheetName", {
|
|
|
59604
60058
|
get: function () {
|
|
59605
60059
|
return unquoteSheetName;
|
|
59606
60060
|
}
|
|
60061
|
+
});
|
|
60062
|
+
Object.defineProperty(exports, "upperCaseKeepingPositions", {
|
|
60063
|
+
enumerable: true,
|
|
60064
|
+
get: function () {
|
|
60065
|
+
return upperCaseKeepingPositions;
|
|
60066
|
+
}
|
|
59607
60067
|
});
|