@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbsoluteRefType, AsyncLock, BooleanNumber, BuildTextUtils, CellValueType, CommandType, DataStreamTreeTokenType, DateSystem, Disposable, DisposableCollection, EXCEL_1904_OFFSET, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LRUMap, LifecycleService, LifecycleStages, LocaleService,
|
|
1
|
+
import { AbsoluteRefType, AsyncLock, BooleanNumber, BuildTextUtils, CellValueType, CommandType, DataStreamTreeTokenType, DateSystem, Disposable, DisposableCollection, EXCEL_1904_OFFSET, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LRUMap, LifecycleService, LifecycleStages, LocaleService, MAX_COLUMN_COUNT, MAX_ROW_COUNT, ObjectMatrix, Optional, Plugin, RANGE_TYPE, RTree, Rectangle, RichTextBuilder, Styles, Tools, UniverInstanceType, cellToRange, columnLabelToNumber, createBaseFormulaTableNameMap, createIdentifier, excelDateSerial, excelDateTimePartsToSerial, excelDateTimeSerial, excelSerialToDate, excelSerialToDateTime, excelSerialToDateTimeParts, generateRandomId, getBaseFormulaTableName, getCurrencySymbolByLocale, getDateSystemMaxSerial, getNumfmtParseValueFilter, isFormulaId, isFormulaString, isNodeEnv, isNullCell, isRealNum, isTextFormat, isValidRange, merge, moveRangeByOffset, normalizeWorkbookCalculationSettings, numfmt, regexp, requestImmediateMacroTask, sortRules, toDisposable, touchDependencies } from "@univerjs/core";
|
|
2
2
|
import { BehaviorSubject, Observable, Subject, combineLatest, distinctUntilChanged, filter, map, shareReplay, take } from "rxjs";
|
|
3
3
|
import IntervalTree from "@flatten-js/interval-tree";
|
|
4
4
|
import Decimal$1 from "decimal.js";
|
|
@@ -929,7 +929,7 @@ function splitTableStructuredRef(ref) {
|
|
|
929
929
|
};
|
|
930
930
|
}
|
|
931
931
|
|
|
932
|
-
// \0@oxc-project+runtime@0.
|
|
932
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
933
933
|
function _typeof(o) {
|
|
934
934
|
"@babel/helpers - typeof";
|
|
935
935
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -939,7 +939,7 @@ function _typeof(o) {
|
|
|
939
939
|
}, _typeof(o);
|
|
940
940
|
}
|
|
941
941
|
|
|
942
|
-
// \0@oxc-project+runtime@0.
|
|
942
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
943
943
|
function toPrimitive(t, e) {
|
|
944
944
|
if ("object" != _typeof(t) || !t) return t;
|
|
945
945
|
var r;
|
|
@@ -951,13 +951,13 @@ function toPrimitive(t, e) {
|
|
|
951
951
|
return ("string" === e ? String : Number)(t);
|
|
952
952
|
}
|
|
953
953
|
|
|
954
|
-
// \0@oxc-project+runtime@0.
|
|
954
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
955
955
|
function toPropertyKey(t) {
|
|
956
956
|
var i = toPrimitive(t, "string");
|
|
957
957
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
958
958
|
}
|
|
959
959
|
|
|
960
|
-
// \0@oxc-project+runtime@0.
|
|
960
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
961
961
|
function _defineProperty(e, r, t) {
|
|
962
962
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
963
963
|
value: t,
|
|
@@ -967,14 +967,14 @@ function _defineProperty(e, r, t) {
|
|
|
967
967
|
}) : e[r] = t, e;
|
|
968
968
|
}
|
|
969
969
|
|
|
970
|
-
// \0@oxc-project+runtime@0.
|
|
970
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
971
971
|
function __decorateParam(paramIndex, decorator) {
|
|
972
972
|
return function(target, key) {
|
|
973
973
|
decorator(target, key, paramIndex);
|
|
974
974
|
};
|
|
975
975
|
}
|
|
976
976
|
|
|
977
|
-
// \0@oxc-project+runtime@0.
|
|
977
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
978
978
|
function __decorate(decorators, target, key, desc) {
|
|
979
979
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
980
980
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5301,6 +5301,100 @@ function getFirstBaseTable(tables, tableOrder) {
|
|
|
5301
5301
|
}
|
|
5302
5302
|
const IFormulaCurrentConfigService = createIdentifier("univer.formula.current-data.service");
|
|
5303
5303
|
|
|
5304
|
+
// src/engine/utils/char-kit.ts
|
|
5305
|
+
/**
|
|
5306
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
5307
|
+
*
|
|
5308
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5309
|
+
* you may not use this file except in compliance with the License.
|
|
5310
|
+
* You may obtain a copy of the License at
|
|
5311
|
+
*
|
|
5312
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5313
|
+
*
|
|
5314
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5315
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5316
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5317
|
+
* See the License for the specific language governing permissions and
|
|
5318
|
+
* limitations under the License.
|
|
5319
|
+
*/
|
|
5320
|
+
/**
|
|
5321
|
+
* A code point in the surrogate block is half of a UTF-16 pair, not a character.
|
|
5322
|
+
*/
|
|
5323
|
+
function isSurrogateCodePoint(codePoint) {
|
|
5324
|
+
return codePoint >= 55296 && codePoint <= 57343;
|
|
5325
|
+
}
|
|
5326
|
+
/**
|
|
5327
|
+
* U+FDD0-U+FDEF and the last two code points of every plane (xFFFE, xFFFF).
|
|
5328
|
+
*/
|
|
5329
|
+
function isNonCharacterCodePoint(codePoint) {
|
|
5330
|
+
return codePoint >= 64976 && codePoint <= 65007 || (codePoint & 65535) >= 65534;
|
|
5331
|
+
}
|
|
5332
|
+
/**
|
|
5333
|
+
* Excel logic is confusing, so we use google sheet logic
|
|
5334
|
+
*
|
|
5335
|
+
* Each UTF-16 code unit above U+00FF counts as two bytes here, so a character outside
|
|
5336
|
+
* the BMP counts as four. That length feeds LENB, LEFTB, RIGHTB, MIDB, REPLACEB,
|
|
5337
|
+
* SEARCHB and FINDB. Excel 2021 (16.0, zh-CN, DBCS default language, checked 2026-11-18)
|
|
5338
|
+
* contradicts itself on the same text: LENB("😊") is 2, but LEFTB("😊ab", 2) is "😊a",
|
|
5339
|
+
* as if 😊 were one byte, and LEFTB("😊ab", 1) returns the whole pair; MIDB("😊ab", 1, 1)
|
|
5340
|
+
* returns half a surrogate pair, while MIDB("中ab", 2, 1) returns a space standing for
|
|
5341
|
+
* the second byte of a double-byte character.
|
|
5342
|
+
*/
|
|
5343
|
+
function charLenByte(text) {
|
|
5344
|
+
let byteCount = 0;
|
|
5345
|
+
for (let i = 0; i < text.length; i++) byteCount += getCharLenByteInText(text, i);
|
|
5346
|
+
return byteCount;
|
|
5347
|
+
}
|
|
5348
|
+
function getCharLenByteInText(text, charIndex, direction = "ltr") {
|
|
5349
|
+
return getCodePoint(text, charIndex, direction) > 255 ? 2 : 1;
|
|
5350
|
+
}
|
|
5351
|
+
/**
|
|
5352
|
+
* Whether the code unit at `index` and the one after it form a surrogate pair, which
|
|
5353
|
+
* together make up one character.
|
|
5354
|
+
*/
|
|
5355
|
+
function isSurrogatePairAt(text, index) {
|
|
5356
|
+
const high = text.charCodeAt(index);
|
|
5357
|
+
const low = text.charCodeAt(index + 1);
|
|
5358
|
+
return high >= 55296 && high <= 56319 && low >= 56320 && low <= 57343;
|
|
5359
|
+
}
|
|
5360
|
+
/**
|
|
5361
|
+
* Upper-cases text for a case-insensitive search without changing its length, so an
|
|
5362
|
+
* index in the result is also the index in the original text. A character whose upper
|
|
5363
|
+
* case is longer, such as ß becoming SS, is left as it is. The host locale is ignored,
|
|
5364
|
+
* as it is for the wildcard comparisons in `compare.ts`.
|
|
5365
|
+
*/
|
|
5366
|
+
function upperCaseKeepingPositions(text) {
|
|
5367
|
+
const upperCase = text.toUpperCase();
|
|
5368
|
+
if (upperCase.length === text.length) return upperCase;
|
|
5369
|
+
let result = "";
|
|
5370
|
+
for (const char of text) {
|
|
5371
|
+
const upperChar = char.toUpperCase();
|
|
5372
|
+
result += upperChar.length === char.length ? upperChar : char;
|
|
5373
|
+
}
|
|
5374
|
+
return result;
|
|
5375
|
+
}
|
|
5376
|
+
function highSurrogate(charCode) {
|
|
5377
|
+
return charCode >= 55296 && charCode <= 56319;
|
|
5378
|
+
}
|
|
5379
|
+
function lowSurrogate(charCode) {
|
|
5380
|
+
return charCode >= 56320 && charCode <= 57343;
|
|
5381
|
+
}
|
|
5382
|
+
function surrogatePair(highSurrogate, lowSurrogate) {
|
|
5383
|
+
return ((highSurrogate & 1023) << 10) + (lowSurrogate & 1023) + 65536;
|
|
5384
|
+
}
|
|
5385
|
+
function getCodePoint(str, index, direction = "ltr") {
|
|
5386
|
+
const charCode = str.charCodeAt(index);
|
|
5387
|
+
if (direction === "ltr" && highSurrogate(charCode) && index + 1 < str.length) {
|
|
5388
|
+
const nextCharCode = str.charCodeAt(index + 1);
|
|
5389
|
+
if (lowSurrogate(nextCharCode)) return surrogatePair(charCode, nextCharCode);
|
|
5390
|
+
}
|
|
5391
|
+
if (direction === "rtl" && lowSurrogate(charCode) && index - 1 >= 0) {
|
|
5392
|
+
const prevCharCode = str.charCodeAt(index - 1);
|
|
5393
|
+
if (highSurrogate(prevCharCode)) return surrogatePair(prevCharCode, charCode);
|
|
5394
|
+
}
|
|
5395
|
+
return charCode;
|
|
5396
|
+
}
|
|
5397
|
+
|
|
5304
5398
|
// src/engine/utils/compare.ts
|
|
5305
5399
|
function getCompare() {
|
|
5306
5400
|
if (Intl && Intl.Collator) return new Intl.Collator(void 0, { numeric: false }).compare;
|
|
@@ -5327,6 +5421,13 @@ function normalizeTextForComparison(value) {
|
|
|
5327
5421
|
const lower = value.toLowerCase();
|
|
5328
5422
|
return /[\u0080-\uFFFF]/.test(lower) ? lower.normalize("NFC").replace(/[ßæœff-st]/g, (character) => TEXT_LIGATURES[character]) : lower;
|
|
5329
5423
|
}
|
|
5424
|
+
/**
|
|
5425
|
+
* Text equality for an exact lookup, where ? and * are ordinary characters (XLOOKUP and XMATCH
|
|
5426
|
+
* match mode 0). It ignores case, as the `=` comparison does.
|
|
5427
|
+
*/
|
|
5428
|
+
function isLiteralTextMatch(currentValue, value) {
|
|
5429
|
+
return normalizeTextForComparison(currentValue) === normalizeTextForComparison(value);
|
|
5430
|
+
}
|
|
5330
5431
|
function isMatchWildcard(currentValue, value) {
|
|
5331
5432
|
const pattern = escapeRegExpForWildcard(value).replace(/~?[*?]/g, (match) => {
|
|
5332
5433
|
if (match.startsWith("~")) return `\\${match.substring(1)}`;
|
|
@@ -5342,6 +5443,67 @@ function replaceWildcard(value) {
|
|
|
5342
5443
|
return " ";
|
|
5343
5444
|
});
|
|
5344
5445
|
}
|
|
5446
|
+
function parseWildcardPattern(pattern) {
|
|
5447
|
+
const segments = [[]];
|
|
5448
|
+
let hasWildcard = false;
|
|
5449
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
5450
|
+
const char = pattern[i];
|
|
5451
|
+
if (char === "~") {
|
|
5452
|
+
if (i + 1 < pattern.length) {
|
|
5453
|
+
segments[segments.length - 1].push(pattern[i + 1]);
|
|
5454
|
+
i++;
|
|
5455
|
+
}
|
|
5456
|
+
} else if (char === "*") {
|
|
5457
|
+
hasWildcard = true;
|
|
5458
|
+
segments.push([]);
|
|
5459
|
+
} else if (char === "?") {
|
|
5460
|
+
hasWildcard = true;
|
|
5461
|
+
segments[segments.length - 1].push(null);
|
|
5462
|
+
} else segments[segments.length - 1].push(char);
|
|
5463
|
+
}
|
|
5464
|
+
return {
|
|
5465
|
+
literal: hasWildcard ? null : segments[0].join(""),
|
|
5466
|
+
segments
|
|
5467
|
+
};
|
|
5468
|
+
}
|
|
5469
|
+
/**
|
|
5470
|
+
* Index of the earliest match of `pattern` in `text` at or after `fromIndex`, or -1.
|
|
5471
|
+
*
|
|
5472
|
+
* The parts of a wildcard pattern are placed at their leftmost position, so the cost
|
|
5473
|
+
* is text length times pattern length and no input can make the search backtrack.
|
|
5474
|
+
*/
|
|
5475
|
+
function searchWildcard(text, pattern, fromIndex) {
|
|
5476
|
+
if (pattern.literal !== null) return text.indexOf(pattern.literal, fromIndex);
|
|
5477
|
+
const { segments } = pattern;
|
|
5478
|
+
const start = findSegment(text, segments[0], fromIndex);
|
|
5479
|
+
if (start === -1) return -1;
|
|
5480
|
+
let position = matchSegmentAt(text, segments[0], start);
|
|
5481
|
+
for (let i = 1; i < segments.length; i++) {
|
|
5482
|
+
const found = findSegment(text, segments[i], position);
|
|
5483
|
+
if (found === -1) return -1;
|
|
5484
|
+
position = matchSegmentAt(text, segments[i], found);
|
|
5485
|
+
}
|
|
5486
|
+
return start;
|
|
5487
|
+
}
|
|
5488
|
+
/** Leftmost start at or after `fromIndex` where `segment` matches, or -1. */
|
|
5489
|
+
function findSegment(text, segment, fromIndex) {
|
|
5490
|
+
for (let start = fromIndex; start + segment.length <= text.length; start++) if (matchSegmentAt(text, segment, start) !== -1) return start;
|
|
5491
|
+
return -1;
|
|
5492
|
+
}
|
|
5493
|
+
/**
|
|
5494
|
+
* End of `segment` matched at `start`, or -1. A `?` covers one character, so a surrogate
|
|
5495
|
+
* pair such as an emoji is a single `?`; positions stay in UTF-16 units, as LEN counts them.
|
|
5496
|
+
*/
|
|
5497
|
+
function matchSegmentAt(text, segment, start) {
|
|
5498
|
+
let position = start;
|
|
5499
|
+
for (const token of segment) {
|
|
5500
|
+
if (position >= text.length) return -1;
|
|
5501
|
+
if (token === null) position += isSurrogatePairAt(text, position) ? 2 : 1;
|
|
5502
|
+
else if (token === text[position]) position++;
|
|
5503
|
+
else return -1;
|
|
5504
|
+
}
|
|
5505
|
+
return position;
|
|
5506
|
+
}
|
|
5345
5507
|
function compareWithWildcard(currentValue, value, operator, isCaseSensitive = true) {
|
|
5346
5508
|
let currentText = currentValue;
|
|
5347
5509
|
let pattern = value;
|
|
@@ -5862,39 +6024,12 @@ const numberFormatTypeCache = new FormulaAstLRU(1e5);
|
|
|
5862
6024
|
function clearNumberFormatTypeCache() {
|
|
5863
6025
|
numberFormatTypeCache.clear();
|
|
5864
6026
|
}
|
|
5865
|
-
/**
|
|
5866
|
-
* Get the currency symbol based on the locale
|
|
5867
|
-
*/
|
|
5868
|
-
const localeCurrencySymbolMap = /* @__PURE__ */ new Map([
|
|
5869
|
-
[LocaleType.EN_US, "$"],
|
|
5870
|
-
[LocaleType.RU_RU, "₽"],
|
|
5871
|
-
[LocaleType.VI_VN, "₫"],
|
|
5872
|
-
[LocaleType.ZH_CN, "¥"],
|
|
5873
|
-
[LocaleType.ZH_TW, "NT$"],
|
|
5874
|
-
[LocaleType.ZH_HK, "HK$"],
|
|
5875
|
-
[LocaleType.FR_FR, "€"],
|
|
5876
|
-
[LocaleType.FA_IR, "﷼"],
|
|
5877
|
-
[LocaleType.KO_KR, "₩"],
|
|
5878
|
-
[LocaleType.ES_ES, "€"],
|
|
5879
|
-
[LocaleType.CA_ES, "€"],
|
|
5880
|
-
[LocaleType.SK_SK, "€"],
|
|
5881
|
-
[LocaleType.JA_JP, "¥"],
|
|
5882
|
-
[LocaleType.PT_BR, "R$"],
|
|
5883
|
-
[LocaleType.DE_DE, "€"],
|
|
5884
|
-
[LocaleType.IT_IT, "€"],
|
|
5885
|
-
[LocaleType.ID_ID, "Rp"],
|
|
5886
|
-
[LocaleType.PL_PL, "zł"],
|
|
5887
|
-
[LocaleType.AR_SA, "﷼"]
|
|
5888
|
-
]);
|
|
5889
|
-
function getCurrencySymbol(locale) {
|
|
5890
|
-
return localeCurrencySymbolMap.get(locale) || "$";
|
|
5891
|
-
}
|
|
5892
6027
|
function getCurrencyFormat(locale, numberDigits = 2) {
|
|
5893
6028
|
let _numberDigits = numberDigits;
|
|
5894
6029
|
if (numberDigits > 127) _numberDigits = 127;
|
|
5895
6030
|
let decimal = "";
|
|
5896
6031
|
if (_numberDigits > 0) decimal = `.${"0".repeat(_numberDigits)}`;
|
|
5897
|
-
return `"${
|
|
6032
|
+
return `"${getCurrencySymbolByLocale(locale)}"#,##0${decimal}_);[Red]("${getCurrencySymbolByLocale(locale)}"#,##0${decimal})`;
|
|
5898
6033
|
}
|
|
5899
6034
|
function applyCurrencyFormat(locale, number, numberDigits = 2) {
|
|
5900
6035
|
return numfmt.format(getCurrencyFormat(locale, numberDigits), number);
|
|
@@ -6510,6 +6645,20 @@ function round(base, precision) {
|
|
|
6510
6645
|
return Math.round(multiply(base, factor) + epsilon) / factor;
|
|
6511
6646
|
}
|
|
6512
6647
|
/**
|
|
6648
|
+
* Rounds a number to a specified number of decimal places, halves to even ('banker's rounding').
|
|
6649
|
+
* @param base The number to round.
|
|
6650
|
+
* @param precision The number of decimal places to round to.
|
|
6651
|
+
* @returns The rounded number.
|
|
6652
|
+
*/
|
|
6653
|
+
function roundHalfEven(base, precision) {
|
|
6654
|
+
const factor = 10 ** Math.trunc(precision);
|
|
6655
|
+
const scaled = +multiply(base, factor).toFixed(8);
|
|
6656
|
+
const lower = Math.floor(scaled);
|
|
6657
|
+
const decimalPart = scaled - lower;
|
|
6658
|
+
if (Math.abs(decimalPart - .5) > 1e-8) return Math.round(scaled) / factor;
|
|
6659
|
+
return (lower % 2 === 0 ? lower : lower + 1) / factor;
|
|
6660
|
+
}
|
|
6661
|
+
/**
|
|
6513
6662
|
* Rounds down a number to a specified number of decimal places.
|
|
6514
6663
|
* @param base The number to round down.
|
|
6515
6664
|
* @param precision The number of decimal places to round down to.
|
|
@@ -7558,7 +7707,7 @@ var StringValueObject = class StringValueObject extends BaseValueObject {
|
|
|
7558
7707
|
const rawValue = this.getValue();
|
|
7559
7708
|
if (rawValue.trim() === "") return ErrorValueObject.create("#VALUE!");
|
|
7560
7709
|
const parseData = getNumfmtParseValueFilter(rawValue, { dateSystem: this.getDateSystem() });
|
|
7561
|
-
if (parseData
|
|
7710
|
+
if (parseData) return createNumberValueObjectByRawValue(parseData.v, parseData.z).withDateSystem(this.getDateSystem());
|
|
7562
7711
|
const compactMonthYear = parseCompactEnglishMonthYear(rawValue, this.getDateSystem());
|
|
7563
7712
|
if (compactMonthYear !== null) return createNumberValueObjectByRawValue(compactMonthYear).withDateSystem(this.getDateSystem());
|
|
7564
7713
|
return createNumberValueObjectByRawValue(rawValue).withDateSystem(this.getDateSystem());
|
|
@@ -7603,6 +7752,25 @@ function createNumberValueObjectByRawValue(rawValue, pattern = "") {
|
|
|
7603
7752
|
}
|
|
7604
7753
|
|
|
7605
7754
|
// src/engine/value-object/array-value-object.ts
|
|
7755
|
+
/** Literal text order: case-insensitive, and ? and * are ordinary characters rather than wildcards. */
|
|
7756
|
+
function compareTextOrder(left, right) {
|
|
7757
|
+
const leftText = normalizeTextForComparison(left);
|
|
7758
|
+
const rightText = normalizeTextForComparison(right);
|
|
7759
|
+
if (leftText === rightText) return 0;
|
|
7760
|
+
return leftText.localeCompare(rightText) < 0 ? -1 : 1;
|
|
7761
|
+
}
|
|
7762
|
+
/**
|
|
7763
|
+
* Order two values for the next smaller or larger item that XLOOKUP and XMATCH match modes -1
|
|
7764
|
+
* and 1 fall back to. Text compares as text, so ? and * inside an array item are ordinary
|
|
7765
|
+
* characters, and the other types keep the order of the value objects.
|
|
7766
|
+
*/
|
|
7767
|
+
function compareOrderValues(left, right) {
|
|
7768
|
+
if (left.isString() && right.isString()) return compareTextOrder(String(left.getValue()), String(right.getValue()));
|
|
7769
|
+
if (left.isEqual(right).getValue() === true) return 0;
|
|
7770
|
+
if (left.isLessThan(right).getValue() === true) return -1;
|
|
7771
|
+
if (left.isGreaterThan(right).getValue() === true) return 1;
|
|
7772
|
+
return 0;
|
|
7773
|
+
}
|
|
7606
7774
|
function transformToValueObject(array = [], isIgnoreNumberPattern = false, dateSystem) {
|
|
7607
7775
|
const arrayValueList = [];
|
|
7608
7776
|
for (let r = 0; r < array.length; r++) {
|
|
@@ -7991,21 +8159,43 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
7991
8159
|
* Due to the inability to effectively utilize the cache,
|
|
7992
8160
|
* the sequential matching approach is only used for special matches in XLOOKUP and XMATCH.
|
|
7993
8161
|
* For example, when match_mode is set to 1 and -1 for an exact match. If not found, it returns the next smaller item.
|
|
8162
|
+
*
|
|
8163
|
+
* With literalText, the exact match and the next smaller or larger fallback read ? and * in a text value as
|
|
8164
|
+
* ordinary characters, as XLOOKUP and XMATCH do outside match mode 2. MATCH leaves it off, because its exact
|
|
8165
|
+
* match accepts wildcards.
|
|
7994
8166
|
*/
|
|
7995
|
-
orderSearch(valueObject, searchType = 1, isDesc = false, isFuzzyMatching = false, keepFirstNearest = false) {
|
|
8167
|
+
orderSearch(valueObject, searchType = 1, isDesc = false, isFuzzyMatching = false, keepFirstNearest = false, literalText = false) {
|
|
8168
|
+
const literalPattern = literalText && valueObject.isString() && isWildcard(String(valueObject.getValue())) ? String(valueObject.getValue()) : null;
|
|
7996
8169
|
let result;
|
|
7997
8170
|
let maxOrMin;
|
|
7998
8171
|
let resultPosition;
|
|
7999
8172
|
let maxOrMinPosition;
|
|
8000
8173
|
const _isNearer = (itemValue, currentValue) => {
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8174
|
+
if (literalText === false) {
|
|
8175
|
+
const distance = itemValue.minus(valueObject).abs();
|
|
8176
|
+
const currentDistance = currentValue.minus(valueObject).abs();
|
|
8177
|
+
return keepFirstNearest ? distance.isLessThan(currentDistance).getValue() === true : distance.isLessThanOrEqual(currentDistance).getValue() === true;
|
|
8178
|
+
}
|
|
8179
|
+
const comparison = compareOrderValues(itemValue, currentValue);
|
|
8180
|
+
if (comparison !== 0) return searchType === 2 ? comparison < 0 : comparison > 0;
|
|
8181
|
+
return keepFirstNearest === false;
|
|
8182
|
+
};
|
|
8183
|
+
/**
|
|
8184
|
+
* The order of an item against the lookup value for the next smaller or larger fallback.
|
|
8185
|
+
* With literalText, text is ordered as text, so ? and * in the lookup value are not a
|
|
8186
|
+
* wildcard pattern.
|
|
8187
|
+
*/
|
|
8188
|
+
const _compareWithLookup = (itemValue) => {
|
|
8189
|
+
if (literalText && itemValue.isString() && valueObject.isString()) return compareTextOrder(String(itemValue.getValue()), String(valueObject.getValue()));
|
|
8190
|
+
if (itemValue.isLessThan(valueObject).getValue() === true) return -1;
|
|
8191
|
+
if (itemValue.isGreaterThan(valueObject).getValue() === true) return 1;
|
|
8192
|
+
return 0;
|
|
8004
8193
|
};
|
|
8005
8194
|
const _handleMatch = (itemValue, row, column) => {
|
|
8006
8195
|
if (itemValue == null || itemValue.isNull()) return true;
|
|
8007
8196
|
let matchObject;
|
|
8008
8197
|
if (isFuzzyMatching === true) matchObject = itemValue.compare(valueObject, "=");
|
|
8198
|
+
else if (literalPattern !== null) matchObject = BooleanValueObject.create(itemValue.isString() && isLiteralTextMatch(String(itemValue.getValue()), literalPattern));
|
|
8009
8199
|
else if (searchType === 0 && itemValue.isNumber() && valueObject.isNumber()) matchObject = BooleanValueObject.create(Number(itemValue.getValue()) === Number(valueObject.getValue()));
|
|
8010
8200
|
else matchObject = itemValue.isEqual(valueObject);
|
|
8011
8201
|
if ((matchObject === null || matchObject === void 0 ? void 0 : matchObject.getValue()) === true) {
|
|
@@ -8016,8 +8206,9 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8016
8206
|
};
|
|
8017
8207
|
return false;
|
|
8018
8208
|
}
|
|
8209
|
+
const comparison = _compareWithLookup(itemValue);
|
|
8019
8210
|
if (searchType === 2) {
|
|
8020
|
-
if (
|
|
8211
|
+
if (comparison > 0) {
|
|
8021
8212
|
if (maxOrMin == null || _isNearer(itemValue, maxOrMin)) {
|
|
8022
8213
|
maxOrMin = itemValue;
|
|
8023
8214
|
maxOrMinPosition = {
|
|
@@ -8027,7 +8218,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8027
8218
|
}
|
|
8028
8219
|
}
|
|
8029
8220
|
} else if (searchType === 1) {
|
|
8030
|
-
if (
|
|
8221
|
+
if (comparison < 0) {
|
|
8031
8222
|
if (maxOrMin == null || _isNearer(itemValue, maxOrMin)) {
|
|
8032
8223
|
maxOrMin = itemValue;
|
|
8033
8224
|
maxOrMinPosition = {
|
|
@@ -17545,7 +17736,7 @@ let BESSEL;
|
|
|
17545
17736
|
function _bessel_wrap(bessel0, bessel1, nonzero, sign) {
|
|
17546
17737
|
return function bessel(x, n) {
|
|
17547
17738
|
if (nonzero) {
|
|
17548
|
-
if (x === 0) return nonzero === 1 ? -
|
|
17739
|
+
if (x === 0) return nonzero === 1 ? -1e400 : 1e400;
|
|
17549
17740
|
else if (x < 0) return NaN;
|
|
17550
17741
|
}
|
|
17551
17742
|
if (n === 0) return bessel0(x);
|
|
@@ -17846,7 +18037,7 @@ let BESSEL;
|
|
|
17846
18037
|
if (_n === 1) return bessel1(x);
|
|
17847
18038
|
if (_n < 0) return NaN;
|
|
17848
18039
|
if (Math.abs(x) === 0) return 0;
|
|
17849
|
-
if (x ===
|
|
18040
|
+
if (x === 1e400) return 1e400;
|
|
17850
18041
|
let ret = 0;
|
|
17851
18042
|
let j;
|
|
17852
18043
|
const tox = 2 / Math.abs(x);
|
|
@@ -18085,7 +18276,7 @@ function performLUDecomposition(matrix, transpose = true, minimumPivot = 1e-11)
|
|
|
18085
18276
|
for (let k = 0; k < i; k++) value -= luMatrix[i][k] * luMatrix[k][c];
|
|
18086
18277
|
luMatrix[i][c] = value;
|
|
18087
18278
|
}
|
|
18088
|
-
let maxPivot = -
|
|
18279
|
+
let maxPivot = -1e400;
|
|
18089
18280
|
let pivotRow = c;
|
|
18090
18281
|
for (let r = c; r < numRows; r++) {
|
|
18091
18282
|
let value = decomposedMatrix[r][c];
|
|
@@ -18639,7 +18830,7 @@ function chisquarePDF(x, degFreedom) {
|
|
|
18639
18830
|
}
|
|
18640
18831
|
function chisquareINV(probability, degFreedom) {
|
|
18641
18832
|
if (probability <= 0) return 0;
|
|
18642
|
-
if (probability >= 1) return
|
|
18833
|
+
if (probability >= 1) return 1e400;
|
|
18643
18834
|
return 2 * lowRegGammaInverse(probability, degFreedom / 2);
|
|
18644
18835
|
}
|
|
18645
18836
|
function centralFCDF(x, degFreedom1, degFreedom2) {
|
|
@@ -18648,7 +18839,7 @@ function centralFCDF(x, degFreedom1, degFreedom2) {
|
|
|
18648
18839
|
}
|
|
18649
18840
|
function centralFPDF(x, degFreedom1, degFreedom2) {
|
|
18650
18841
|
if (x < 0) return 0;
|
|
18651
|
-
if (x === 0 && degFreedom1 < 2) return
|
|
18842
|
+
if (x === 0 && degFreedom1 < 2) return 1e400;
|
|
18652
18843
|
if (x === 0 && degFreedom1 === 2) return 1;
|
|
18653
18844
|
let result = 1 / betaFunction(degFreedom1 / 2, degFreedom2 / 2);
|
|
18654
18845
|
result *= (degFreedom1 / degFreedom2) ** (degFreedom1 / 2);
|
|
@@ -18658,7 +18849,7 @@ function centralFPDF(x, degFreedom1, degFreedom2) {
|
|
|
18658
18849
|
}
|
|
18659
18850
|
function centralFINV(probability, degFreedom1, degFreedom2) {
|
|
18660
18851
|
if (probability <= 0) return 0;
|
|
18661
|
-
if (probability >= 1) return
|
|
18852
|
+
if (probability >= 1) return 1e400;
|
|
18662
18853
|
return degFreedom2 / (degFreedom1 * (1 / betaINV(probability, degFreedom1 / 2, degFreedom2 / 2) - 1));
|
|
18663
18854
|
}
|
|
18664
18855
|
function exponentialCDF(x, lambda) {
|
|
@@ -18685,7 +18876,7 @@ function forecastLinear(x, knownYs, knownXs) {
|
|
|
18685
18876
|
num += (knownYs[i] - knownYsMean) * (knownXs[i] - knownXsMean);
|
|
18686
18877
|
den += (knownXs[i] - knownXsMean) ** 2;
|
|
18687
18878
|
}
|
|
18688
|
-
if (den === 0) return
|
|
18879
|
+
if (den === 0) return 1e400;
|
|
18689
18880
|
const b = num / den;
|
|
18690
18881
|
return knownYsMean - b * knownXsMean + b * x;
|
|
18691
18882
|
}
|
|
@@ -18712,13 +18903,13 @@ function gamma(x) {
|
|
|
18712
18903
|
];
|
|
18713
18904
|
let fact = 0;
|
|
18714
18905
|
let y = x;
|
|
18715
|
-
if (x > 171.6243769536076) return
|
|
18906
|
+
if (x > 171.6243769536076) return 1e400;
|
|
18716
18907
|
if (y <= 0) {
|
|
18717
18908
|
const resMod = y % 1 + 36e-17;
|
|
18718
18909
|
if (resMod) {
|
|
18719
18910
|
fact = (!(y & 1) ? 1 : -1) * Math.PI / Math.sin(Math.PI * resMod);
|
|
18720
18911
|
y = 1 - y;
|
|
18721
|
-
} else return
|
|
18912
|
+
} else return 1e400;
|
|
18722
18913
|
}
|
|
18723
18914
|
const yi = y;
|
|
18724
18915
|
let n = 0;
|
|
@@ -18751,7 +18942,7 @@ function gammaPDF(x, alpha, beta) {
|
|
|
18751
18942
|
}
|
|
18752
18943
|
function gammaINV(probability, alpha, beta) {
|
|
18753
18944
|
if (probability <= 0) return 0;
|
|
18754
|
-
if (probability >= 1) return
|
|
18945
|
+
if (probability >= 1) return 1e400;
|
|
18755
18946
|
return beta * lowRegGammaInverse(probability, alpha);
|
|
18756
18947
|
}
|
|
18757
18948
|
function gammaln(x) {
|
|
@@ -21578,7 +21769,7 @@ var Dmax = class extends BaseFunction {
|
|
|
21578
21769
|
if (fieldIsError) return filedErrorObject;
|
|
21579
21770
|
const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
|
|
21580
21771
|
if (criteriaIsError) return criteriaErrorObject;
|
|
21581
|
-
let result = -
|
|
21772
|
+
let result = -1e400;
|
|
21582
21773
|
let count = 0;
|
|
21583
21774
|
for (let r = 1; r < databaseValues.length; r++) {
|
|
21584
21775
|
const value = databaseValues[r][fieldIndex];
|
|
@@ -21607,7 +21798,7 @@ var Dmin = class extends BaseFunction {
|
|
|
21607
21798
|
if (fieldIsError) return filedErrorObject;
|
|
21608
21799
|
const { isError: criteriaIsError, errorObject: criteriaErrorObject, criteriaValues } = checkCriteria(criteria);
|
|
21609
21800
|
if (criteriaIsError) return criteriaErrorObject;
|
|
21610
|
-
let result =
|
|
21801
|
+
let result = 1e400;
|
|
21611
21802
|
let count = 0;
|
|
21612
21803
|
for (let r = 1; r < databaseValues.length; r++) {
|
|
21613
21804
|
const value = databaseValues[r][fieldIndex];
|
|
@@ -22523,7 +22714,7 @@ var Edate = class extends BaseFunction {
|
|
|
22523
22714
|
if (startDateObject.isString() || startDateObject.isBoolean() || monthsValueObject.isString() || monthsValueObject.isBoolean()) return ErrorValueObject.create("#VALUE!");
|
|
22524
22715
|
const startDateSerial = +startDateObject.getValue();
|
|
22525
22716
|
if (startDateSerial < 0) return ErrorValueObject.create("#NUM!");
|
|
22526
|
-
const monthsValue = Math.
|
|
22717
|
+
const monthsValue = Math.trunc(+monthsValueObject.getValue());
|
|
22527
22718
|
const _startDate = excelSerialToDate(startDateSerial, this.getDateSystem());
|
|
22528
22719
|
const year = _startDate.getUTCFullYear();
|
|
22529
22720
|
const month = _startDate.getUTCMonth() + monthsValue;
|
|
@@ -22567,7 +22758,7 @@ var Eomonth = class extends BaseFunction {
|
|
|
22567
22758
|
const isDate1900SerialZero = this.getDateSystem() === DateSystem.Date1900 && startDateSerialNumber === 0;
|
|
22568
22759
|
const startYear = isDate1900SerialZero ? 1900 : startDateDate.getUTCFullYear();
|
|
22569
22760
|
const startMonth = isDate1900SerialZero ? 0 : startDateDate.getUTCMonth();
|
|
22570
|
-
const monthsValue = Math.
|
|
22761
|
+
const monthsValue = Math.trunc(+_months.getValue());
|
|
22571
22762
|
if (Number.isNaN(monthsValue)) return ErrorValueObject.create("#VALUE!");
|
|
22572
22763
|
const targetDate = new Date(Date.UTC(startYear, startMonth + monthsValue + 1, 0));
|
|
22573
22764
|
const result = excelDateSerial(targetDate, this.getDateSystem());
|
|
@@ -27769,7 +27960,7 @@ function getResultByGuessIterF(guess, iterF) {
|
|
|
27769
27960
|
eps = Math.abs(xN - x);
|
|
27770
27961
|
x = xN;
|
|
27771
27962
|
}
|
|
27772
|
-
if (Number.isNaN(x) ||
|
|
27963
|
+
if (Number.isNaN(x) || 1e400 === Math.abs(x) || nMC === nIM) return guessIsNaNorInfinity(guess, iterF);
|
|
27773
27964
|
return x;
|
|
27774
27965
|
}
|
|
27775
27966
|
function guessIsNaNorInfinity(guess, iterF) {
|
|
@@ -27958,6 +28149,139 @@ var Accrintm = class extends BaseFunction {
|
|
|
27958
28149
|
}
|
|
27959
28150
|
};
|
|
27960
28151
|
|
|
28152
|
+
// src/functions/financial/amordegrc/index.ts
|
|
28153
|
+
var Amordegrc = class extends BaseFunction {
|
|
28154
|
+
constructor(..._args) {
|
|
28155
|
+
super(..._args);
|
|
28156
|
+
_defineProperty(this, "minParams", 6);
|
|
28157
|
+
_defineProperty(this, "maxParams", 7);
|
|
28158
|
+
}
|
|
28159
|
+
calculate(cost, datePurchased, firstPeriod, salvage, period, rate, basis) {
|
|
28160
|
+
const _basis = basis ?? NumberValueObject.create(0);
|
|
28161
|
+
const { isError, errorObject, variants } = checkVariantsErrorIsArrayOrBoolean(cost, datePurchased, firstPeriod, salvage, period, rate, _basis);
|
|
28162
|
+
if (isError) return errorObject;
|
|
28163
|
+
const [costObject, datePurchasedObject, firstPeriodObject, salvageObject, periodObject, rateObject, basisObject] = variants;
|
|
28164
|
+
const datePurchasedSerialNumber = getDateSerialNumberByObject(datePurchasedObject, this.getDateSystem());
|
|
28165
|
+
if (typeof datePurchasedSerialNumber !== "number") return datePurchasedSerialNumber;
|
|
28166
|
+
const firstPeriodSerialNumber = getDateSerialNumberByObject(firstPeriodObject, this.getDateSystem());
|
|
28167
|
+
if (typeof firstPeriodSerialNumber !== "number") return firstPeriodSerialNumber;
|
|
28168
|
+
const costValue = +costObject.getValue();
|
|
28169
|
+
const salvageValue = +salvageObject.getValue();
|
|
28170
|
+
const periodValue = +periodObject.getValue();
|
|
28171
|
+
const rateValue = +rateObject.getValue();
|
|
28172
|
+
const basisValue = Math.floor(+basisObject.getValue());
|
|
28173
|
+
if (Number.isNaN(costValue) || Number.isNaN(salvageValue) || Number.isNaN(periodValue) || Number.isNaN(rateValue) || Number.isNaN(basisValue)) return ErrorValueObject.create("#VALUE!");
|
|
28174
|
+
if (costValue <= 0 || salvageValue < 0 || costValue < salvageValue || Math.floor(datePurchasedSerialNumber) > Math.floor(firstPeriodSerialNumber) || periodValue < 0 || rateValue <= 0 || ![
|
|
28175
|
+
0,
|
|
28176
|
+
1,
|
|
28177
|
+
3,
|
|
28178
|
+
4
|
|
28179
|
+
].includes(basisValue)) return ErrorValueObject.create("#NUM!");
|
|
28180
|
+
return this._getResult(costValue, datePurchasedSerialNumber, firstPeriodSerialNumber, salvageValue, periodValue, rateValue, basisValue);
|
|
28181
|
+
}
|
|
28182
|
+
_getResult(costValue, datePurchasedSerialNumber, firstPeriodSerialNumber, salvageValue, periodValue, rateValue, basisValue) {
|
|
28183
|
+
if (1 / rateValue <= 2) return ErrorValueObject.create("#NUM!");
|
|
28184
|
+
const life = Math.ceil(1 / rateValue);
|
|
28185
|
+
if (costValue === salvageValue || periodValue > life) return NumberValueObject.create(0);
|
|
28186
|
+
const depreciationRate = rateValue * this._getCoefficient(life);
|
|
28187
|
+
const { days, yearDays } = getFirstPeriodDays(datePurchasedSerialNumber, firstPeriodSerialNumber, basisValue, this.getDateSystem());
|
|
28188
|
+
const prorated = days / yearDays * depreciationRate * costValue;
|
|
28189
|
+
const lastPeriods = prorated === 0 ? life : life + 1;
|
|
28190
|
+
const firstDepreciation = excelRound(Math.min(prorated === 0 ? costValue * depreciationRate : prorated, costValue - salvageValue));
|
|
28191
|
+
if (periodValue === 0) return NumberValueObject.create(firstDepreciation);
|
|
28192
|
+
let bookValue = costValue - firstDepreciation;
|
|
28193
|
+
let rate = depreciationRate;
|
|
28194
|
+
let depreciation = 0;
|
|
28195
|
+
for (let countedPeriod = 2; countedPeriod <= periodValue + 1; countedPeriod++) {
|
|
28196
|
+
const skipped = skipRegularPeriods(countedPeriod, Math.min(periodValue + 1, lastPeriods - 3), bookValue, salvageValue, rate);
|
|
28197
|
+
countedPeriod += skipped.periods;
|
|
28198
|
+
bookValue = skipped.bookValue;
|
|
28199
|
+
const isSecondToLast = Math.abs(lastPeriods - countedPeriod - 2) < 1e-4;
|
|
28200
|
+
const scheduled = isSecondToLast ? bookValue * .5 : rate * bookValue;
|
|
28201
|
+
if (isSecondToLast) rate = 1;
|
|
28202
|
+
depreciation = bookValue < salvageValue ? 0 : scheduled;
|
|
28203
|
+
bookValue -= depreciation;
|
|
28204
|
+
if (depreciation === 0 && bookValue <= salvageValue) return NumberValueObject.create(0);
|
|
28205
|
+
}
|
|
28206
|
+
return NumberValueObject.create(excelRound(depreciation));
|
|
28207
|
+
}
|
|
28208
|
+
/**
|
|
28209
|
+
* The depreciation coefficient of the French accounting system, by the life of the asset in
|
|
28210
|
+
* whole years: up to 4 is 1.5, 5 or 6 is 2 and longer is 2.5.
|
|
28211
|
+
*/
|
|
28212
|
+
_getCoefficient(life) {
|
|
28213
|
+
if (life <= 4) return 1.5;
|
|
28214
|
+
if (life <= 6) return 2;
|
|
28215
|
+
return 2.5;
|
|
28216
|
+
}
|
|
28217
|
+
};
|
|
28218
|
+
/**
|
|
28219
|
+
* Rounds the way Excel does here: first to Excel's 15 significant digits, so that
|
|
28220
|
+
* 327.49999999999994 counts as 327.5, then to a whole number with halves away from zero.
|
|
28221
|
+
*/
|
|
28222
|
+
function excelRound(value) {
|
|
28223
|
+
const rounded = Number(value.toPrecision(15));
|
|
28224
|
+
return Math.sign(rounded) * Math.round(Math.abs(rounded));
|
|
28225
|
+
}
|
|
28226
|
+
/**
|
|
28227
|
+
* Days from the purchase to the end of the first period, and the days in that year, as AMORDEGRC
|
|
28228
|
+
* counts them. This differs from YEARFRAC: with actual day counts a date on 28 or 29 February of a
|
|
28229
|
+
* leap year counts as 28 February, actual/actual uses the purchase year's length, and the US 30/360
|
|
28230
|
+
* method only moves the end of February when the purchase is also at the end of February.
|
|
28231
|
+
*/
|
|
28232
|
+
function getFirstPeriodDays(purchaseSerialNumber, firstPeriodSerialNumber, basis, dateSystem) {
|
|
28233
|
+
const parts = (serialNumber) => {
|
|
28234
|
+
const date = excelSerialToDate(serialNumber, dateSystem);
|
|
28235
|
+
return {
|
|
28236
|
+
year: date.getUTCFullYear(),
|
|
28237
|
+
month: date.getUTCMonth() + 1,
|
|
28238
|
+
day: date.getUTCDate()
|
|
28239
|
+
};
|
|
28240
|
+
};
|
|
28241
|
+
const purchase = parts(purchaseSerialNumber);
|
|
28242
|
+
const firstPeriod = parts(firstPeriodSerialNumber);
|
|
28243
|
+
if (basis === 1 || basis === 3) {
|
|
28244
|
+
const toFebruary28 = (serialNumber, date) => isLeapYear(date.year) && date.month === 2 && date.day >= 28 ? serialNumber - (date.day - 28) : serialNumber;
|
|
28245
|
+
return {
|
|
28246
|
+
days: toFebruary28(firstPeriodSerialNumber, firstPeriod) - toFebruary28(purchaseSerialNumber, purchase),
|
|
28247
|
+
yearDays: basis === 3 || !isLeapYear(purchase.year) ? 365 : 366
|
|
28248
|
+
};
|
|
28249
|
+
}
|
|
28250
|
+
let startDay = purchase.day;
|
|
28251
|
+
let endDay = firstPeriod.day;
|
|
28252
|
+
if (basis === 0) {
|
|
28253
|
+
const isEndOfFebruary = (date) => date.month === 2 && date.day === getDaysInMonth(date.year, 1);
|
|
28254
|
+
if (isEndOfFebruary(firstPeriod) && isEndOfFebruary(purchase)) endDay = 30;
|
|
28255
|
+
if (endDay === 31 && startDay >= 30) endDay = 30;
|
|
28256
|
+
if (startDay === 31 || isEndOfFebruary(purchase)) startDay = 30;
|
|
28257
|
+
} else {
|
|
28258
|
+
startDay = Math.min(startDay, 30);
|
|
28259
|
+
endDay = Math.min(endDay, 30);
|
|
28260
|
+
}
|
|
28261
|
+
return {
|
|
28262
|
+
days: (firstPeriod.year - purchase.year) * 360 + (firstPeriod.month - purchase.month) * 30 + (endDay - startDay),
|
|
28263
|
+
yearDays: 360
|
|
28264
|
+
};
|
|
28265
|
+
}
|
|
28266
|
+
const MIN_SKIPPED_PERIODS = 1e4;
|
|
28267
|
+
/**
|
|
28268
|
+
* A tiny rate gives a life of many years, and a period can ask for any of them. Each regular period
|
|
28269
|
+
* multiplies the book value by (1 - rate), so a long run of them is skipped in one step instead of
|
|
28270
|
+
* one by one, stopping before the book value would fall below the salvage value.
|
|
28271
|
+
*/
|
|
28272
|
+
function skipRegularPeriods(countedPeriod, lastRegularPeriod, bookValue, salvageValue, rate) {
|
|
28273
|
+
let periods = Math.floor(lastRegularPeriod) - countedPeriod;
|
|
28274
|
+
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);
|
|
28275
|
+
if (periods < MIN_SKIPPED_PERIODS || rate <= 0 || rate >= 1 || bookValue <= salvageValue) return {
|
|
28276
|
+
periods: 0,
|
|
28277
|
+
bookValue
|
|
28278
|
+
};
|
|
28279
|
+
return {
|
|
28280
|
+
periods,
|
|
28281
|
+
bookValue: bookValue * (1 - rate) ** periods
|
|
28282
|
+
};
|
|
28283
|
+
}
|
|
28284
|
+
|
|
27961
28285
|
// src/functions/financial/amorlinc/index.ts
|
|
27962
28286
|
var Amorlinc = class extends BaseFunction {
|
|
27963
28287
|
constructor(..._args) {
|
|
@@ -28965,7 +29289,7 @@ var Npv = class extends BaseFunction {
|
|
|
28965
29289
|
if (isError) return errorObject;
|
|
28966
29290
|
const rateValue = +rate.getValue();
|
|
28967
29291
|
const result = calculateNpv(rateValue, values);
|
|
28968
|
-
if (Number.isNaN(result) || Math.abs(result) ===
|
|
29292
|
+
if (Number.isNaN(result) || Math.abs(result) === 1e400) return ErrorValueObject.create("#DIV/0!");
|
|
28969
29293
|
if (rowIndex === 0 && columnIndex === 0) return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));
|
|
28970
29294
|
return NumberValueObject.create(result);
|
|
28971
29295
|
}
|
|
@@ -30439,6 +30763,7 @@ var Yieldmat = class extends BaseFunction {
|
|
|
30439
30763
|
const functionFinancial = [
|
|
30440
30764
|
[Accrint, "ACCRINT"],
|
|
30441
30765
|
[Accrintm, "ACCRINTM"],
|
|
30766
|
+
[Amordegrc, "AMORDEGRC"],
|
|
30442
30767
|
[Amorlinc, "AMORLINC"],
|
|
30443
30768
|
[Coupdaybs, "COUPDAYBS"],
|
|
30444
30769
|
[Coupdays, "COUPDAYS"],
|
|
@@ -34797,7 +35122,7 @@ var Xlookup = class extends BaseFunction {
|
|
|
34797
35122
|
const matches = searchArray.compare(value, "=");
|
|
34798
35123
|
return searchModeValue === -1 ? matches.getLastTruePosition() : matches.getFirstTruePosition();
|
|
34799
35124
|
}
|
|
34800
|
-
if (matchModeValue === -1 || matchModeValue === 1) return searchArray.orderSearch(value, matchModeValue === 1 ? 2 : 1, searchModeValue === -1, false, true);
|
|
35125
|
+
if (matchModeValue === -1 || matchModeValue === 1) return searchArray.orderSearch(value, matchModeValue === 1 ? 2 : 1, searchModeValue === -1, false, true, true);
|
|
34801
35126
|
return this._findExactPosition(value, searchArray, searchModeValue !== -1);
|
|
34802
35127
|
}
|
|
34803
35128
|
_findExactPosition(value, searchArray, isFirst) {
|
|
@@ -34818,6 +35143,7 @@ var Xlookup = class extends BaseFunction {
|
|
|
34818
35143
|
_isExactMatch(candidate, value) {
|
|
34819
35144
|
if (candidate.isError() || value.isError()) return candidate.isError() && value.isError() && candidate.getValue() === value.getValue();
|
|
34820
35145
|
if (candidate.isNull() !== value.isNull() || candidate.isNumber() !== value.isNumber() || candidate.isString() !== value.isString() || candidate.isBoolean() !== value.isBoolean()) return false;
|
|
35146
|
+
if (value.isString() && isWildcard(String(value.getValue()))) return isLiteralTextMatch(String(candidate.getValue()), String(value.getValue()));
|
|
34821
35147
|
return candidate.isEqual(value).getValue() === true;
|
|
34822
35148
|
}
|
|
34823
35149
|
_blankResultAsZero(value) {
|
|
@@ -34903,12 +35229,12 @@ var Xmatch = class extends BaseFunction {
|
|
|
34903
35229
|
if (position == null) return ErrorValueObject.create("#N/A");
|
|
34904
35230
|
rowOrColumn = _lookupArray.getRowCount() === 1 ? position.column : position.row;
|
|
34905
35231
|
} else if (matchMode === -1 || matchMode === 1) {
|
|
34906
|
-
const position = _lookupArray.orderSearch(lookupValue, matchMode === 1 ? 2 : 1, searchMode === -1);
|
|
35232
|
+
const position = _lookupArray.orderSearch(lookupValue, matchMode === 1 ? 2 : 1, searchMode === -1, false, true, true);
|
|
34907
35233
|
if (position == null) return ErrorValueObject.create("#N/A");
|
|
34908
35234
|
if (position instanceof ErrorValueObject) return position;
|
|
34909
35235
|
rowOrColumn = _lookupArray.getRowCount() === 1 ? position.column : position.row;
|
|
34910
35236
|
} else {
|
|
34911
|
-
const matchObject =
|
|
35237
|
+
const matchObject = this._exactMatches(_lookupArray, lookupValue);
|
|
34912
35238
|
let position;
|
|
34913
35239
|
if (searchMode !== -1) position = matchObject.getFirstTruePosition();
|
|
34914
35240
|
else position = matchObject.getLastTruePosition();
|
|
@@ -34918,6 +35244,11 @@ var Xmatch = class extends BaseFunction {
|
|
|
34918
35244
|
if (rowOrColumn == null) return ErrorValueObject.create("#N/A");
|
|
34919
35245
|
return NumberValueObject.create(rowOrColumn + 1);
|
|
34920
35246
|
}
|
|
35247
|
+
_exactMatches(lookupArray, lookupValue) {
|
|
35248
|
+
if (!lookupValue.isString() || !isWildcard(String(lookupValue.getValue()))) return lookupArray.isEqual(lookupValue);
|
|
35249
|
+
const text = String(lookupValue.getValue());
|
|
35250
|
+
return lookupArray.mapValue((item) => BooleanValueObject.create(item.isString() && isLiteralTextMatch(String(item.getValue()), text)));
|
|
35251
|
+
}
|
|
34921
35252
|
};
|
|
34922
35253
|
|
|
34923
35254
|
// src/functions/lookup/function-map.ts
|
|
@@ -36017,6 +36348,28 @@ var Int = class extends BaseFunction {
|
|
|
36017
36348
|
}
|
|
36018
36349
|
};
|
|
36019
36350
|
|
|
36351
|
+
// src/functions/math/iso-ceiling/index.ts
|
|
36352
|
+
/**
|
|
36353
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
36354
|
+
*
|
|
36355
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
36356
|
+
* you may not use this file except in compliance with the License.
|
|
36357
|
+
* You may obtain a copy of the License at
|
|
36358
|
+
*
|
|
36359
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
36360
|
+
*
|
|
36361
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
36362
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
36363
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
36364
|
+
* See the License for the specific language governing permissions and
|
|
36365
|
+
* limitations under the License.
|
|
36366
|
+
*/
|
|
36367
|
+
/**
|
|
36368
|
+
* ISO.CEILING rounds a number up to the nearest multiple of the significance's absolute value, whatever the
|
|
36369
|
+
* signs, and returns 0 when either argument is 0. Excel defines it with the same result as CEILING.PRECISE.
|
|
36370
|
+
*/
|
|
36371
|
+
var IsoCeiling = class extends CeilingPrecise {};
|
|
36372
|
+
|
|
36020
36373
|
// src/functions/math/lcm/index.ts
|
|
36021
36374
|
var Lcm = class extends BaseFunction {
|
|
36022
36375
|
constructor(..._args) {
|
|
@@ -36852,13 +37205,7 @@ var Roundbank = class extends BaseFunction {
|
|
|
36852
37205
|
_roundBank(number, numDigits) {
|
|
36853
37206
|
if (numDigits > 16) return number;
|
|
36854
37207
|
if (numDigits < -16) return 0;
|
|
36855
|
-
|
|
36856
|
-
const adjustedNum = +(number * multiplier).toFixed(8);
|
|
36857
|
-
const integerPart = Math.floor(adjustedNum);
|
|
36858
|
-
const decimalPart = adjustedNum - integerPart;
|
|
36859
|
-
let result = Math.round(adjustedNum);
|
|
36860
|
-
if (decimalPart > .49999999 && decimalPart < .50000001) result = integerPart % 2 === 0 ? integerPart : integerPart + 1;
|
|
36861
|
-
return numDigits ? result / multiplier : result;
|
|
37208
|
+
return roundHalfEven(number, numDigits);
|
|
36862
37209
|
}
|
|
36863
37210
|
};
|
|
36864
37211
|
|
|
@@ -37827,6 +38174,7 @@ const functionMath = [
|
|
|
37827
38174
|
[FloorPrecise, "FLOOR.PRECISE"],
|
|
37828
38175
|
[Gcd, "GCD"],
|
|
37829
38176
|
[Int, "INT"],
|
|
38177
|
+
[IsoCeiling, "ISO.CEILING"],
|
|
37830
38178
|
[Lcm, "LCM"],
|
|
37831
38179
|
[Ln, "LN"],
|
|
37832
38180
|
[Log, "LOG"],
|
|
@@ -39156,7 +39504,7 @@ var Frequency = class extends BaseFunction {
|
|
|
39156
39504
|
const index = _binsArrayValues[i].index;
|
|
39157
39505
|
if (i === 0) {
|
|
39158
39506
|
newBinsArrayValues[index] = {
|
|
39159
|
-
start: -
|
|
39507
|
+
start: -1e400,
|
|
39160
39508
|
end: _binsArrayValues[i].value
|
|
39161
39509
|
};
|
|
39162
39510
|
continue;
|
|
@@ -39168,7 +39516,7 @@ var Frequency = class extends BaseFunction {
|
|
|
39168
39516
|
}
|
|
39169
39517
|
newBinsArrayValues.push({
|
|
39170
39518
|
start: _binsArrayValues[_binsArrayValues.length - 1].value,
|
|
39171
|
-
end:
|
|
39519
|
+
end: 1e400
|
|
39172
39520
|
});
|
|
39173
39521
|
return newBinsArrayValues;
|
|
39174
39522
|
}
|
|
@@ -41785,6 +42133,21 @@ var Bahttext = class extends BaseFunction {
|
|
|
41785
42133
|
};
|
|
41786
42134
|
|
|
41787
42135
|
// src/functions/text/char/index.ts
|
|
42136
|
+
/**
|
|
42137
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
42138
|
+
*
|
|
42139
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
42140
|
+
* you may not use this file except in compliance with the License.
|
|
42141
|
+
* You may obtain a copy of the License at
|
|
42142
|
+
*
|
|
42143
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
42144
|
+
*
|
|
42145
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
42146
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
42147
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42148
|
+
* See the License for the specific language governing permissions and
|
|
42149
|
+
* limitations under the License.
|
|
42150
|
+
*/
|
|
41788
42151
|
const filterCodeArray$1 = Object.values(DataStreamTreeTokenType).filter((value) => {
|
|
41789
42152
|
return [
|
|
41790
42153
|
DataStreamTreeTokenType.TABLE_START,
|
|
@@ -41815,8 +42178,9 @@ var Char = class extends BaseFunction {
|
|
|
41815
42178
|
if (isError) return errorObject;
|
|
41816
42179
|
const [numberObject] = variants;
|
|
41817
42180
|
const numberValue = Math.floor(+numberObject.getValue());
|
|
41818
|
-
if (numberValue
|
|
41819
|
-
|
|
42181
|
+
if (numberValue < 1 || numberValue > 1114111) return ErrorValueObject.create("#VALUE!");
|
|
42182
|
+
if (isSurrogateCodePoint(numberValue) || isNonCharacterCodePoint(numberValue)) return ErrorValueObject.create("#N/A");
|
|
42183
|
+
let result = String.fromCodePoint(numberValue);
|
|
41820
42184
|
if (filterCodeArray$1.some((value) => value === result)) result = String.fromCharCode(1);
|
|
41821
42185
|
return StringValueObject.create(result);
|
|
41822
42186
|
}
|
|
@@ -41865,8 +42229,8 @@ var Code = class extends BaseFunction {
|
|
|
41865
42229
|
if (text.isNull()) return ErrorValueObject.create("#VALUE!");
|
|
41866
42230
|
let textValue = text.getValue().toLocaleString();
|
|
41867
42231
|
if (text.isBoolean()) textValue = textValue.toLocaleUpperCase();
|
|
41868
|
-
|
|
41869
|
-
|
|
42232
|
+
const result = textValue.codePointAt(0);
|
|
42233
|
+
if (result === void 0 || isSurrogateCodePoint(result)) return ErrorValueObject.create("#VALUE!");
|
|
41870
42234
|
return NumberValueObject.create(result);
|
|
41871
42235
|
}
|
|
41872
42236
|
};
|
|
@@ -42013,6 +42377,125 @@ var Dollar = class extends BaseFunction {
|
|
|
42013
42377
|
}
|
|
42014
42378
|
};
|
|
42015
42379
|
|
|
42380
|
+
// src/functions/text/euroconvert/index.ts
|
|
42381
|
+
const EURO_CURRENCIES = {
|
|
42382
|
+
BEF: {
|
|
42383
|
+
rate: 40.3399,
|
|
42384
|
+
precision: 0
|
|
42385
|
+
},
|
|
42386
|
+
LUF: {
|
|
42387
|
+
rate: 40.3399,
|
|
42388
|
+
precision: 0
|
|
42389
|
+
},
|
|
42390
|
+
DEM: {
|
|
42391
|
+
rate: 1.95583,
|
|
42392
|
+
precision: 2
|
|
42393
|
+
},
|
|
42394
|
+
ESP: {
|
|
42395
|
+
rate: 166.386,
|
|
42396
|
+
precision: 0
|
|
42397
|
+
},
|
|
42398
|
+
FRF: {
|
|
42399
|
+
rate: 6.55957,
|
|
42400
|
+
precision: 2
|
|
42401
|
+
},
|
|
42402
|
+
IEP: {
|
|
42403
|
+
rate: .787564,
|
|
42404
|
+
precision: 2
|
|
42405
|
+
},
|
|
42406
|
+
ITL: {
|
|
42407
|
+
rate: 1936.27,
|
|
42408
|
+
precision: 0
|
|
42409
|
+
},
|
|
42410
|
+
NLG: {
|
|
42411
|
+
rate: 2.20371,
|
|
42412
|
+
precision: 2
|
|
42413
|
+
},
|
|
42414
|
+
ATS: {
|
|
42415
|
+
rate: 13.7603,
|
|
42416
|
+
precision: 2
|
|
42417
|
+
},
|
|
42418
|
+
PTE: {
|
|
42419
|
+
rate: 200.482,
|
|
42420
|
+
precision: 0
|
|
42421
|
+
},
|
|
42422
|
+
FIM: {
|
|
42423
|
+
rate: 5.94573,
|
|
42424
|
+
precision: 2
|
|
42425
|
+
},
|
|
42426
|
+
GRD: {
|
|
42427
|
+
rate: 340.75,
|
|
42428
|
+
precision: 0
|
|
42429
|
+
},
|
|
42430
|
+
SIT: {
|
|
42431
|
+
rate: 239.64,
|
|
42432
|
+
precision: 2
|
|
42433
|
+
},
|
|
42434
|
+
EUR: {
|
|
42435
|
+
rate: 1,
|
|
42436
|
+
precision: 2
|
|
42437
|
+
}
|
|
42438
|
+
};
|
|
42439
|
+
const EURO = "EUR";
|
|
42440
|
+
const MIN_TRIANGULATION_PRECISION = 3;
|
|
42441
|
+
const MAX_TRIANGULATION_PRECISION = 32767;
|
|
42442
|
+
const MAX_EURO_DECIMALS = 15;
|
|
42443
|
+
const roundHalfAwayFromZero = (value, decimals) => value < 0 ? -round(-value, decimals) : round(value, decimals);
|
|
42444
|
+
var Euroconvert = class extends BaseFunction {
|
|
42445
|
+
constructor(..._args) {
|
|
42446
|
+
super(..._args);
|
|
42447
|
+
_defineProperty(this, "minParams", 3);
|
|
42448
|
+
_defineProperty(this, "maxParams", 5);
|
|
42449
|
+
}
|
|
42450
|
+
calculate(number, source, target, fullPrecision, triangulationPrecision) {
|
|
42451
|
+
const { isError, errorObject, variants } = checkVariantsErrorIsArray(number, source, target, fullPrecision ?? BooleanValueObject.create(false));
|
|
42452
|
+
if (isError) return errorObject;
|
|
42453
|
+
const [numberObject, sourceObject, targetObject, fullPrecisionObject] = variants;
|
|
42454
|
+
const { isError: isNotNumeric, errorObject: notNumericObject, variants: numericVariants } = checkVariantsErrorIsStringToNumber(numberObject, fullPrecisionObject);
|
|
42455
|
+
if (isNotNumeric) return notNumericObject;
|
|
42456
|
+
const [numericNumberObject, numericFullPrecisionObject] = numericVariants;
|
|
42457
|
+
const numberValue = +numericNumberObject.getValue();
|
|
42458
|
+
const isFullPrecision = +numericFullPrecisionObject.getValue() !== 0;
|
|
42459
|
+
const sourceCurrency = this._getCurrency(sourceObject);
|
|
42460
|
+
const targetCurrency = this._getCurrency(targetObject);
|
|
42461
|
+
if (Number.isNaN(numberValue) || !sourceCurrency || !targetCurrency) return ErrorValueObject.create("#VALUE!");
|
|
42462
|
+
const triangulationDecimals = this._getTriangulationDecimals(triangulationPrecision);
|
|
42463
|
+
if (typeof triangulationDecimals !== "number" && triangulationDecimals !== null) return triangulationDecimals;
|
|
42464
|
+
if (sourceCurrency === targetCurrency) return NumberValueObject.create(numberValue);
|
|
42465
|
+
let result;
|
|
42466
|
+
if (sourceCurrency === EURO_CURRENCIES[EURO]) result = numberValue * targetCurrency.rate;
|
|
42467
|
+
else {
|
|
42468
|
+
let euros = numberValue / sourceCurrency.rate;
|
|
42469
|
+
if (triangulationDecimals !== null) euros = roundHalfAwayFromZero(euros, triangulationDecimals);
|
|
42470
|
+
result = euros * targetCurrency.rate;
|
|
42471
|
+
}
|
|
42472
|
+
if (!isFullPrecision) result = roundHalfAwayFromZero(result, targetCurrency.precision);
|
|
42473
|
+
return NumberValueObject.create(result);
|
|
42474
|
+
}
|
|
42475
|
+
_getCurrency(code) {
|
|
42476
|
+
if (!code.isString()) return;
|
|
42477
|
+
const isoCode = `${code.getValue()}`.toUpperCase();
|
|
42478
|
+
return Object.prototype.hasOwnProperty.call(EURO_CURRENCIES, isoCode) ? EURO_CURRENCIES[isoCode] : void 0;
|
|
42479
|
+
}
|
|
42480
|
+
/**
|
|
42481
|
+
* The decimals the intermediate euro value is rounded to, `null` when the argument is
|
|
42482
|
+
* omitted, or the error it produces.
|
|
42483
|
+
*/
|
|
42484
|
+
_getTriangulationDecimals(triangulationPrecision) {
|
|
42485
|
+
if (!triangulationPrecision) return null;
|
|
42486
|
+
const precisionObject = checkVariantErrorIsArray(triangulationPrecision);
|
|
42487
|
+
if (precisionObject.isError()) return precisionObject;
|
|
42488
|
+
const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(precisionObject);
|
|
42489
|
+
if (isError) return errorObject;
|
|
42490
|
+
const precision = +variants[0].getValue();
|
|
42491
|
+
if (Number.isNaN(precision)) return ErrorValueObject.create("#VALUE!");
|
|
42492
|
+
const decimals = roundHalfEven(precision, 0);
|
|
42493
|
+
if (decimals > MAX_TRIANGULATION_PRECISION) return ErrorValueObject.create("#NUM!");
|
|
42494
|
+
if (decimals < MIN_TRIANGULATION_PRECISION) return ErrorValueObject.create("#VALUE!");
|
|
42495
|
+
return Math.min(decimals, MAX_EURO_DECIMALS);
|
|
42496
|
+
}
|
|
42497
|
+
};
|
|
42498
|
+
|
|
42016
42499
|
// src/functions/text/exact/index.ts
|
|
42017
42500
|
var Exact = class extends BaseFunction {
|
|
42018
42501
|
constructor(..._args) {
|
|
@@ -42113,58 +42596,6 @@ var Find = class extends BaseFunction {
|
|
|
42113
42596
|
}
|
|
42114
42597
|
};
|
|
42115
42598
|
|
|
42116
|
-
// src/engine/utils/char-kit.ts
|
|
42117
|
-
/**
|
|
42118
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
42119
|
-
*
|
|
42120
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
42121
|
-
* you may not use this file except in compliance with the License.
|
|
42122
|
-
* You may obtain a copy of the License at
|
|
42123
|
-
*
|
|
42124
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
42125
|
-
*
|
|
42126
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
42127
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
42128
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42129
|
-
* See the License for the specific language governing permissions and
|
|
42130
|
-
* limitations under the License.
|
|
42131
|
-
*/
|
|
42132
|
-
/**
|
|
42133
|
-
* excel logic is cofusing, so we use google sheet logic
|
|
42134
|
-
*
|
|
42135
|
-
* @param text
|
|
42136
|
-
* @returns number
|
|
42137
|
-
*/
|
|
42138
|
-
function charLenByte(text) {
|
|
42139
|
-
let byteCount = 0;
|
|
42140
|
-
for (let i = 0; i < text.length; i++) byteCount += getCharLenByteInText(text, i);
|
|
42141
|
-
return byteCount;
|
|
42142
|
-
}
|
|
42143
|
-
function getCharLenByteInText(text, charIndex, direction = "ltr") {
|
|
42144
|
-
return getCodePoint(text, charIndex, direction) > 255 ? 2 : 1;
|
|
42145
|
-
}
|
|
42146
|
-
function highSurrogate(charCode) {
|
|
42147
|
-
return charCode >= 55296 && charCode <= 56319;
|
|
42148
|
-
}
|
|
42149
|
-
function lowSurrogate(charCode) {
|
|
42150
|
-
return charCode >= 56320 && charCode <= 57343;
|
|
42151
|
-
}
|
|
42152
|
-
function surrogatePair(highSurrogate, lowSurrogate) {
|
|
42153
|
-
return ((highSurrogate & 1023) << 10) + (lowSurrogate & 1023) + 65536;
|
|
42154
|
-
}
|
|
42155
|
-
function getCodePoint(str, index, direction = "ltr") {
|
|
42156
|
-
const charCode = str.charCodeAt(index);
|
|
42157
|
-
if (direction === "ltr" && highSurrogate(charCode) && index + 1 < str.length) {
|
|
42158
|
-
const nextCharCode = str.charCodeAt(index + 1);
|
|
42159
|
-
if (lowSurrogate(nextCharCode)) return surrogatePair(charCode, nextCharCode);
|
|
42160
|
-
}
|
|
42161
|
-
if (direction === "rtl" && lowSurrogate(charCode) && index - 1 >= 0) {
|
|
42162
|
-
const prevCharCode = str.charCodeAt(index - 1);
|
|
42163
|
-
if (highSurrogate(prevCharCode)) return surrogatePair(prevCharCode, charCode);
|
|
42164
|
-
}
|
|
42165
|
-
return charCode;
|
|
42166
|
-
}
|
|
42167
|
-
|
|
42168
42599
|
// src/functions/text/findb/index.ts
|
|
42169
42600
|
var Findb = class extends BaseFunction {
|
|
42170
42601
|
constructor(..._args) {
|
|
@@ -42978,7 +43409,7 @@ function tokenizer(regExpString) {
|
|
|
42978
43409
|
if (match) {
|
|
42979
43410
|
if (stack.length === 0) throwError(i);
|
|
42980
43411
|
const min = Number.parseInt(match[1], 10);
|
|
42981
|
-
const max = match[2] ? match[3] ? Number.parseInt(match[3], 10) :
|
|
43412
|
+
const max = match[2] ? match[3] ? Number.parseInt(match[3], 10) : 1e400 : min;
|
|
42982
43413
|
i += match[0].length;
|
|
42983
43414
|
stack.push({
|
|
42984
43415
|
type: 5,
|
|
@@ -43006,7 +43437,7 @@ function tokenizer(regExpString) {
|
|
|
43006
43437
|
stack.push({
|
|
43007
43438
|
type: 5,
|
|
43008
43439
|
min: 1,
|
|
43009
|
-
max:
|
|
43440
|
+
max: 1e400,
|
|
43010
43441
|
value: stack.pop()
|
|
43011
43442
|
});
|
|
43012
43443
|
break;
|
|
@@ -43015,7 +43446,7 @@ function tokenizer(regExpString) {
|
|
|
43015
43446
|
stack.push({
|
|
43016
43447
|
type: 5,
|
|
43017
43448
|
min: 0,
|
|
43018
|
-
max:
|
|
43449
|
+
max: 1e400,
|
|
43019
43450
|
value: stack.pop()
|
|
43020
43451
|
});
|
|
43021
43452
|
break;
|
|
@@ -43150,7 +43581,7 @@ function isSafeRegExp(regExp, options) {
|
|
|
43150
43581
|
const validateToken = (token, depth) => {
|
|
43151
43582
|
let _depth = depth;
|
|
43152
43583
|
if (token.type === 5) {
|
|
43153
|
-
if (depth > 0 && (token.min === 0 || token.max ===
|
|
43584
|
+
if (depth > 0 && (token.min === 0 || token.max === 1e400)) return false;
|
|
43154
43585
|
if (isDangerousRepetition(token)) {
|
|
43155
43586
|
count++;
|
|
43156
43587
|
if (count > limit) return false;
|
|
@@ -43505,15 +43936,15 @@ var Search = class extends BaseFunction {
|
|
|
43505
43936
|
return resultArray;
|
|
43506
43937
|
}
|
|
43507
43938
|
_handleSingleObject(findText, withinText, startNum) {
|
|
43508
|
-
const findTextValue = getTextValueOfNumberFormat(findText)
|
|
43509
|
-
const withinTextValue = getTextValueOfNumberFormat(withinText)
|
|
43939
|
+
const findTextValue = upperCaseKeepingPositions(getTextValueOfNumberFormat(findText));
|
|
43940
|
+
const withinTextValue = upperCaseKeepingPositions(getTextValueOfNumberFormat(withinText));
|
|
43510
43941
|
const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(startNum);
|
|
43511
43942
|
if (isError) return errorObject;
|
|
43512
43943
|
const [startNumObject] = variants;
|
|
43513
43944
|
const startNumValue = Math.floor(+startNumObject.getValue());
|
|
43514
43945
|
if (withinText.isNull() || startNumValue <= 0 || startNumValue > withinTextValue.length) return ErrorValueObject.create("#VALUE!");
|
|
43515
43946
|
if (findText.isNull() || findTextValue.length === 0) return NumberValueObject.create(startNumValue);
|
|
43516
|
-
const result = withinTextValue
|
|
43947
|
+
const result = searchWildcard(withinTextValue, parseWildcardPattern(findTextValue), startNumValue - 1);
|
|
43517
43948
|
if (result === -1) return ErrorValueObject.create("#VALUE!");
|
|
43518
43949
|
return NumberValueObject.create(result + 1);
|
|
43519
43950
|
}
|
|
@@ -43545,15 +43976,15 @@ var Searchb = class extends BaseFunction {
|
|
|
43545
43976
|
return resultArray;
|
|
43546
43977
|
}
|
|
43547
43978
|
_handleSingleObject(findText, withinText, startNum) {
|
|
43548
|
-
const findTextValue = getTextValueOfNumberFormat(findText)
|
|
43549
|
-
const withinTextValue = getTextValueOfNumberFormat(withinText)
|
|
43979
|
+
const findTextValue = upperCaseKeepingPositions(getTextValueOfNumberFormat(findText));
|
|
43980
|
+
const withinTextValue = upperCaseKeepingPositions(getTextValueOfNumberFormat(withinText));
|
|
43550
43981
|
const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(startNum);
|
|
43551
43982
|
if (isError) return errorObject;
|
|
43552
43983
|
const [startNumObject] = variants;
|
|
43553
43984
|
const startNumValue = Math.floor(+startNumObject.getValue());
|
|
43554
43985
|
if (withinText.isNull() || startNumValue <= 0 || startNumValue > withinTextValue.length) return ErrorValueObject.create("#VALUE!");
|
|
43555
43986
|
if (findText.isNull() || findTextValue.length === 0) return NumberValueObject.create(startNumValue);
|
|
43556
|
-
const index = withinTextValue
|
|
43987
|
+
const index = searchWildcard(withinTextValue, parseWildcardPattern(findTextValue), startNumValue - 1);
|
|
43557
43988
|
if (index === -1) return ErrorValueObject.create("#VALUE!");
|
|
43558
43989
|
const result = charLenByte(withinTextValue.substring(0, index)) + 1;
|
|
43559
43990
|
return NumberValueObject.create(result);
|
|
@@ -44209,12 +44640,27 @@ var Trim = class extends BaseFunction {
|
|
|
44209
44640
|
if (text.isNull()) return StringValueObject.create("");
|
|
44210
44641
|
let textValue = `${text.getValue()}`;
|
|
44211
44642
|
if (text.isBoolean()) textValue = textValue.toLocaleUpperCase();
|
|
44212
|
-
textValue = textValue.
|
|
44643
|
+
textValue = textValue.replace(/^[ \u3000]+|[ \u3000]+$/g, "").replace(/[ \u3000]{2,}/g, (run) => run.charAt(0));
|
|
44213
44644
|
return StringValueObject.create(textValue);
|
|
44214
44645
|
}
|
|
44215
44646
|
};
|
|
44216
44647
|
|
|
44217
44648
|
// src/functions/text/unichar/index.ts
|
|
44649
|
+
/**
|
|
44650
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
44651
|
+
*
|
|
44652
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
44653
|
+
* you may not use this file except in compliance with the License.
|
|
44654
|
+
* You may obtain a copy of the License at
|
|
44655
|
+
*
|
|
44656
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
44657
|
+
*
|
|
44658
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
44659
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
44660
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
44661
|
+
* See the License for the specific language governing permissions and
|
|
44662
|
+
* limitations under the License.
|
|
44663
|
+
*/
|
|
44218
44664
|
const filterCodeArray = Object.values(DataStreamTreeTokenType).filter((value) => {
|
|
44219
44665
|
return [
|
|
44220
44666
|
DataStreamTreeTokenType.TABLE_START,
|
|
@@ -44246,8 +44692,8 @@ var Unichar = class extends BaseFunction {
|
|
|
44246
44692
|
const [numberObject] = variants;
|
|
44247
44693
|
const numberValue = Math.floor(+numberObject.getValue());
|
|
44248
44694
|
if (numberValue < 1 || numberValue > 1114111) return ErrorValueObject.create("#VALUE!");
|
|
44249
|
-
if (numberValue
|
|
44250
|
-
let result = String.
|
|
44695
|
+
if (isSurrogateCodePoint(numberValue) || isNonCharacterCodePoint(numberValue)) return ErrorValueObject.create("#N/A");
|
|
44696
|
+
let result = String.fromCodePoint(numberValue);
|
|
44251
44697
|
if (filterCodeArray.some((value) => value === result)) result = String.fromCharCode(1);
|
|
44252
44698
|
return StringValueObject.create(result);
|
|
44253
44699
|
}
|
|
@@ -44273,7 +44719,8 @@ var Unicode = class extends BaseFunction {
|
|
|
44273
44719
|
if (text.isNull()) return ErrorValueObject.create("#VALUE!");
|
|
44274
44720
|
let textValue = text.getValue().toLocaleString();
|
|
44275
44721
|
if (text.isBoolean()) textValue = textValue.toLocaleUpperCase();
|
|
44276
|
-
const result = textValue.
|
|
44722
|
+
const result = textValue.codePointAt(0);
|
|
44723
|
+
if (result === void 0 || result >= 55296 && result <= 57343) return ErrorValueObject.create("#VALUE!");
|
|
44277
44724
|
return NumberValueObject.create(result);
|
|
44278
44725
|
}
|
|
44279
44726
|
};
|
|
@@ -44393,6 +44840,7 @@ const functionText = [
|
|
|
44393
44840
|
[Dbcs, "DBCS"],
|
|
44394
44841
|
[Dollar, "DOLLAR"],
|
|
44395
44842
|
[Exact, "EXACT"],
|
|
44843
|
+
[Euroconvert, "EUROCONVERT"],
|
|
44396
44844
|
[Find, "FIND"],
|
|
44397
44845
|
[Findb, "FINDB"],
|
|
44398
44846
|
[Fixed, "FIXED"],
|
|
@@ -44565,7 +45013,7 @@ const ALL_IMPLEMENTED_FUNCTIONS_SET = new Set(ALL_IMPLEMENTED_FUNCTIONS.map(([_,
|
|
|
44565
45013
|
|
|
44566
45014
|
// package.json
|
|
44567
45015
|
var name = "@univerjs/engine-formula";
|
|
44568
|
-
var version = "1.
|
|
45016
|
+
var version = "1.6.1";
|
|
44569
45017
|
|
|
44570
45018
|
// src/services/global-computing-status.service.ts
|
|
44571
45019
|
var GlobalComputingStatusService = class extends Disposable {
|
|
@@ -57813,7 +58261,7 @@ const FUNCTION_LIST_TEXT = [
|
|
|
57813
58261
|
name: "engine-formula.functionList.EUROCONVERT.functionParameter.fullPrecision.name",
|
|
57814
58262
|
detail: "engine-formula.functionList.EUROCONVERT.functionParameter.fullPrecision.detail",
|
|
57815
58263
|
example: "false",
|
|
57816
|
-
require:
|
|
58264
|
+
require: 0,
|
|
57817
58265
|
repeat: 0
|
|
57818
58266
|
},
|
|
57819
58267
|
{
|
|
@@ -58257,4 +58705,4 @@ _defineProperty(UniverFormulaEnginePlugin, "packageName", name);
|
|
|
58257
58705
|
_defineProperty(UniverFormulaEnginePlugin, "version", version);
|
|
58258
58706
|
UniverFormulaEnginePlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverFormulaEnginePlugin);
|
|
58259
58707
|
|
|
58260
|
-
export { SuperTableActiveDirtyController as $,
|
|
58708
|
+
export { SuperTableActiveDirtyController as $, SetFormulaCalculationNotificationMutation as $n, operatorToken as $r, RangeReferenceObject as $t, functionUniver as A, NEW_EXCEL_FUNCTIONS as An, serializeRangeWithSheet as Ar, UnionNodeFactory as At, functionDate as B, ENGINE_FORMULA_PLUGIN_CONFIG_KEY as Bn, DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER as Br, Interpreter as Bt, FUNCTION_LIST_ARRAY as C, SheetRowFilteredService as Cn, handleRefStringInfo as Cr, FeatureCalculationManagerService as Ct, ALL_IMPLEMENTED_FUNCTIONS as D, generateStringWithSequence as Dn, quoteSheetName as Dr, IDependencyManagerService as Dt, GlobalComputingStatusService as E, LexerNode as En, needsQuoting as Er, DependencyManagerService as Et, functionLookup as F, FUNCTION_NAMES_LOGICAL as Fn, SetArrayFormulaDataMutation as Fr, OperatorNodeFactory as Ft, FUNCTION_NAMES_CUBE as G, ISuperTableService as Gn, includeFormulaLexerToken as Gr, normalizeFormulaUnitName as Gt, FUNCTION_NAMES_DATABASE as H, RemoveSuperTableMutation as Hn, DEFAULT_TOKEN_TYPE_ROOT as Hr, PrefixNodeFactory as Ht, functionLogical as I, FUNCTION_NAMES_INFORMATION as In, RegisterFunctionMutation as Ir, LambdaParameterNodeFactory as It, FUNCTION_NAMES_COMPATIBILITY as J, SetOtherFormulaMutation as Jn, normalizeSheetName as Jr, FormulaExecutedStateType as Jt, functionCube as K, SuperTableService as Kn, isFormulaLexerToken as Kr, AstRootNodeFactory as Kt, functionInformation as L, FUNCTION_NAMES_FINANCIAL as Ln, OtherFormulaMarkDirty as Lr, LambdaNodeFactory as Lt, functionStatistical as M, FUNCTION_NAMES_STATISTICAL as Mn, singleReferenceToGrid as Mr, ReferenceNodeFactory as Mt, functionMeta as N, FUNCTION_NAMES_MATH as Nn, splitTableStructuredRef as Nr, IFormulaExternalReferenceDataLoader as Nt, ALL_IMPLEMENTED_FUNCTIONS_SET as O, sequenceNodeType as On, serializeRange as Or, AstTreeBuilder as Ot, functionMath as P, FUNCTION_NAMES_LOOKUP as Pn, unquoteSheetName as Pr, NoopFormulaExternalReferenceDataLoader as Pt, deserializeRangeForR1C1 as Q, SetCellFormulaDependencyCalculationResultMutation as Qn, matchToken as Qr, IHyperlinkEngineFormulaService as Qt, functionFinancial as R, FUNCTION_NAMES_ENGINEERING as Rn, DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME as Rr, LambdaValueObjectObject as Rt, FUNCTION_LIST_COMPATIBILITY as S, ISheetRowFilteredService as Sn, getRangeWithRefsString as Sr, OtherFormulaManagerService as St, mergeDirtyData as T, LexerTreeBuilder as Tn, isReferenceStrings as Tr, DependencyManagerBaseService as Tt, AsyncCustomFunction as U, SetSuperTableMutation as Un, convertUnitDataToRuntime as Ur, FormulaUnitReferenceResolver as Ut, functionDatabase as V, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE as Vn, DEFAULT_TOKEN_TYPE_PARAMETER as Vr, FunctionNodeFactory as Vt, CustomFunction as W, SetSuperTableOptionMutation as Wn, isReferenceString as Wr, IFormulaUnitReferenceResolver as Wt, FUNCTION_NAMES_ARRAY as X, SetFormulaDataMutation as Xn, SUFFIX_TOKEN_SET as Xr, IFormulaRuntimeService as Xt, functionArray as Y, SetImageFormulaDataMutation as Yn, OPERATOR_TOKEN_SET as Yr, FormulaRuntimeService as Yt, BaseFunction as Z, SetCellFormulaDependencyCalculationMutation as Zn, compareToken as Zr, HyperlinkEngineFormulaService as Zt, FUNCTION_LIST_FINANCIAL as _, IFunctionService as _n, DefinedNamesService as _r, FormulaDependencyTreeModel as _t, IDescriptionService as a, isInDirtyRange as ai, BooleanValueObject as an, SetFormulaStringBatchCalculationMutation as ar, IActiveDirtyManagerService as at, FUNCTION_LIST_DATABASE as b, FormulaCurrentConfigService as bn, getAbsoluteRefTypeWitString as br, generateAstNode as bt, FUNCTION_LIST as c, StringValueObject as cn, SetQueryFormulaDependencyAllResultMutation as cr, CalculateController as ct, FUNCTION_LIST_TEXT as d, extractFormulaError as dn, SetTriggerFormulaCalculationStartMutation as dr, ICalculateFormulaService as dt, prefixToken as ei, AsyncArrayObject as en, SetFormulaCalculationResultMutation as er, FormulaCalculationSessionController as et, FUNCTION_LIST_STATISTICAL as f, BaseValueObject as fn, RemoveFeatureCalculationMutation as fr, FormulaResultService as ft, FUNCTION_LIST_INFORMATION as g, FunctionService as gn, SetDefinedNameMutationFactory as gr, FormulaDependencyTree as gt, FUNCTION_LIST_LOGICAL as h, Lexer as hn, SetDefinedNameMutation as hr, generateRandomDependencyTreeId as ht, DescriptionService as i, ErrorType$1 as ii, ValueObjectFactory as in, SetFormulaDependencyCalculationResultMutation as ir, ActiveDirtyManagerService as it, functionText as j, FUNCTION_NAMES_WEB as jn, serializeRangeWithSpreadsheet as jr, SuffixNodeFactory as jt, functionWeb as k, deserializeRangeWithSheetWithCache as kn, serializeRangeToRefString as kr, ValueNodeFactory as kt, FUNCTION_LIST_WEB as l, strip as ln, SetQueryFormulaDependencyMutation as lr, CalculateFormulaService as lt, FUNCTION_LIST_LOOKUP as m, handleNumfmtInCell as mn, RemoveDefinedNameMutation as mr, IFormulaDependencyGenerator as mt, IRegisterFunctionService as n, FUNCTION_NAMES_TEXT as ni, BaseReferenceObject as nn, SetFormulaCalculationStopMutation as nr, RegisterOtherFormulaService as nt, generateParam as o, BooleanValue as oi, NullValueObject as on, SetFormulaStringBatchCalculationResultMutation as or, FormulaCalculationSessionService as ot, FUNCTION_LIST_MATH as p, ErrorValueObject as pn, SetFeatureCalculationMutation as pr, FormulaDependencyGenerator as pt, functionCompatibility as q, RemoveOtherFormulaMutation as qn, matchRefDrawToken as qr, FormulaExecuteStageType as qt, RegisterFunctionService as r, ERROR_TYPE_SET as ri, ArrayValueObject as rn, SetFormulaDependencyCalculationMutation as rr, FormulaResultStatus as rt, getFunctionName as s, NumberValueObject as sn, SetQueryFormulaDependencyAllMutation as sr, FormulaResultApplicationType as st, UniverFormulaEnginePlugin as t, FunctionType as ti, AsyncObject as tn, SetFormulaCalculationStartMutation as tr, OtherFormulaBizType as tt, FUNCTION_LIST_UNIVER as u, stripErrorMargin as un, SetQueryFormulaDependencyResultMutation as ur, DEFAULT_INTERVAL_COUNT as ut, FUNCTION_LIST_ENGINEERING as v, normalizeTextForComparison as vn, IDefinedNamesService as vr, FormulaDependencyTreeType as vt, FormulaCalculationTriggerService as w, FormulaDataModel as wn, isReferenceStringWithEffectiveColumn as wr, IFeatureCalculationManagerService as wt, FUNCTION_LIST_CUBE as x, IFormulaCurrentConfigService as xn, getAbsoluteRefTypeWithSingleString as xr, IOtherFormulaManagerService as xt, FUNCTION_LIST_DATE as y, upperCaseKeepingPositions as yn, deserializeRangeWithSheet as yr, FormulaDependencyTreeVirtual as yt, functionEngineering as z, FUNCTION_NAMES_DATE as zn, DEFAULT_TOKEN_LET_FUNCTION_NAME as zr, generateExecuteAstNodeData as zt };
|