@zelgadis87/utils-core 5.3.4 → 5.3.6
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/.rollup/index.cjs +116 -28
- package/.rollup/index.cjs.map +1 -1
- package/.rollup/index.d.ts +29 -7
- package/.rollup/index.mjs +115 -29
- package/.rollup/index.mjs.map +1 -1
- package/.rollup/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +14 -0
- package/package.json +7 -7
- package/src/time/TimeInstant.ts +111 -50
- package/src/utils/arrays/statistics.ts +16 -7
- package/src/utils/arrays.ts +30 -2
package/.rollup/index.d.ts
CHANGED
|
@@ -563,7 +563,7 @@ type TBasicTimePattern = 'y' | 'yy' | 'yyyy' | 'M' | 'MM' | 'd' | 'dd' | 'H' | '
|
|
|
563
563
|
* @returns Partial time instant parameters that were parsed from the string
|
|
564
564
|
* @throws Error if the string doesn't match the pattern or contains invalid values
|
|
565
565
|
*/
|
|
566
|
-
declare function parseTimeInstantBasicComponents(dateString: string, pattern: TBasicTimePattern): Partial<TTimeInstantParameters>;
|
|
566
|
+
declare function parseTimeInstantBasicComponents(dateString: string, pattern: TBasicTimePattern, ignoreIntlAvailability?: boolean): Partial<TTimeInstantParameters>;
|
|
567
567
|
|
|
568
568
|
declare class TimeDuration extends TimeBase<TimeDuration> {
|
|
569
569
|
protected constructor(value: number, unit: TimeUnit);
|
|
@@ -778,13 +778,14 @@ declare function indexByNumberWith<V, R = V>(arr: V[], keyGetter: TFunction<V, n
|
|
|
778
778
|
declare function indexBySymbolWith<V, R = V>(arr: V[], keyGetter: TFunction<V, symbol>, valueMapper?: TFunction<V, R>): Record<symbol, R>;
|
|
779
779
|
declare function indexByWith<K extends string | number | symbol, V, R = V>(arr: V[], keyGetter: TFunction<V, K>, valueMapper?: TFunction<V, R>): Record<K, R>;
|
|
780
780
|
|
|
781
|
-
declare function average(arr: TReadableArray<number>): number
|
|
781
|
+
declare function average(arr: TReadableArray<number>): TMaybe<number>;
|
|
782
|
+
declare function averageBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): TMaybe<number>;
|
|
782
783
|
declare function sum(arr: TReadableArray<number>): number;
|
|
783
784
|
declare function sumBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): number;
|
|
784
|
-
declare function min(arr: TReadableArray<number>): number
|
|
785
|
-
declare function minBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): number
|
|
786
|
-
declare function max(arr: TReadableArray<number>): number
|
|
787
|
-
declare function maxBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): number
|
|
785
|
+
declare function min(arr: TReadableArray<number>): TMaybe<number>;
|
|
786
|
+
declare function minBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): TMaybe<number>;
|
|
787
|
+
declare function max(arr: TReadableArray<number>): TMaybe<number>;
|
|
788
|
+
declare function maxBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): TMaybe<number>;
|
|
788
789
|
|
|
789
790
|
declare function uniq<T>(arr: T[]): T[];
|
|
790
791
|
declare function uniqBy<T, K>(arr: T[], getter: TFunction<T, K>): T[];
|
|
@@ -807,7 +808,28 @@ declare function isArray<const T>(t: unknown): t is Array<T>;
|
|
|
807
808
|
*/
|
|
808
809
|
declare function upsert<T>(arr: ReadonlyArray<T>, item: T, isEqual: TBiPredicate<T>): Array<T>;
|
|
809
810
|
declare function range(start: number, end: number): Array<number>;
|
|
811
|
+
/**
|
|
812
|
+
* Creates an array of the specified length, where each element is filled with the given value.
|
|
813
|
+
* @param length - The length of the array to create. Must be a non-negative integer.
|
|
814
|
+
* @param value - The value to fill each element with.
|
|
815
|
+
* @returns A new array with all elements set to the given value.
|
|
816
|
+
* @throws {RangeError} If length is negative, not an integer, or NaN.
|
|
817
|
+
* @example
|
|
818
|
+
* ```ts
|
|
819
|
+
* fill(3, 'a'); // ['a', 'a', 'a']
|
|
820
|
+
* fill(0, 42); // []
|
|
821
|
+
* fill(5, null); // [null, null, null, null, null]
|
|
822
|
+
* ```
|
|
823
|
+
*/
|
|
810
824
|
declare function fill<T>(length: number, value: T): Array<T>;
|
|
825
|
+
/**
|
|
826
|
+
* Creates an array of the specified length, where each element is generated by the provided generator function.
|
|
827
|
+
* @param length - The length of the array to create. Must be a non-negative integer.
|
|
828
|
+
* @param generator - A function that takes an index and returns the value for that position.
|
|
829
|
+
* @returns A new array with elements generated by the generator function.
|
|
830
|
+
* @throws {RangeError} If length is negative or not an integer.
|
|
831
|
+
*/
|
|
832
|
+
declare function fillWith<T>(length: number, generator: TFunction<number, T>): Array<T>;
|
|
811
833
|
declare function extendArray<T extends Record<string | number | symbol, unknown>, X extends Record<string | number | symbol, unknown>>(arr: TReadableArray<T>, props: X): Array<(T & X)>;
|
|
812
834
|
declare function extendArrayWith<T extends Record<string | number | symbol, unknown>, X extends Record<string | number | symbol, unknown>>(arr: TReadableArray<T>, propsFn: (t: T) => X): Array<(T & X)>;
|
|
813
835
|
declare function reverse<T>(arr: TReadableArray<T>): Array<T>;
|
|
@@ -1422,5 +1444,5 @@ declare class DataUpgrader<X extends TUpgradable, XLatest extends X> implements
|
|
|
1422
1444
|
}
|
|
1423
1445
|
declare function isUpgradable(obj: TJsonSerializable): obj is TUpgradable;
|
|
1424
1446
|
|
|
1425
|
-
export { Cached, DataUpgrader, Deferred, DeferredCanceledError, ErrorCannotInstantiatePresentOptionalWithEmptyValue, ErrorGetEmptyOptional, ErrorSetEmptyOptional, Lazy, LazyAsync, LazyDictionary, Logger, NEVER, NonExhaustiveSwitchError, Operation, Optional, PredicateBuilder, RandomTimeDuration, RateThrottler, Semaphore, Sorter, StringParts, TimeDuration, TimeFrequency, TimeInstant, TimeRange, TimeUnit, TimeoutError, alwaysFalse, alwaysTrue, and, arrayGet, arrayIncludes, asError, asPromise, average, awaitAtMost, capitalizeWord, clamp, clampInt0_100, constant, constantFalse, constantNull, constantOne, constantTrue, constantUndefined, constantZero, cssDeclarationRulesDictionaryToCss, decrement, decrementBy, delayPromise, dictToEntries, dictToList, divideBy, ellipsis, ensureArray, ensureDefined, ensureNegativeNumber, ensureNonNegativeNumber, ensureNonPositiveNumber, ensurePositiveNumber, ensureReadableArray, entriesToDict, entriesToEntries, entriesToList, extendArray, extendArrayWith, fill, filterMap, filterMapReduce, filterWithTypePredicate, findInArray, findIndexInArray, first, flatMapTruthys, getCauseMessageFromError, getCauseStackFromError, getMessageFromError, getStackFromError, groupByBoolean, groupByBooleanWith, groupByNumber, groupByNumberWith, groupByString, groupByStringWith, groupBySymbol, groupBySymbolWith, hashCode, head, identity, ifDefined, ifNullOrUndefined, iff, includes, increment, incrementBy, indexByNumber, indexByNumberWith, indexByString, indexByStringWith, indexBySymbol, indexBySymbolWith, indexByWith, isAllowedTimeDuration, isArray, isDefined, isEmpty, isError, isFalse, isFunction, isNegativeNumber, isNullOrUndefined, isNullOrUndefinedOrEmpty, isNumber, isPositiveNumber, isString, isTimeInstant, isTrue, isUpgradable, isZero, jsonCloneDeep, last, listToDict, mapDefined, mapEntries, mapFirstTruthy, mapTruthys, max, maxBy, min, minBy, multiplyBy, noop, not, omitFromJsonObject, or, pad, padLeft, padRight, parseJson, parseTimeInstantBasicComponents, parseTimeInstantComponents, partition, pick, pipedInvoke, pipedInvokeFromArray, pluralize, promiseSequence, randomId, randomNumberInInterval, range, repeat, reverse, round, roundAwayFromZero, roundToLower, roundToNearest, roundToUpper, roundTowardsZero, shallowArrayEquals, shallowRecordEquals, sortedArray, splitWords, stringToNumber, stringifyJson, sum, sumBy, tail, throttle, throwIfNullOrUndefined, transformCssDictionary, tryToParseJson, tryToParseNumber, uniq, uniqBy, uniqByKey, unzip, upsert, withTryCatch, withTryCatchAsync, wrapWithString, xor, zip };
|
|
1447
|
+
export { Cached, DataUpgrader, Deferred, DeferredCanceledError, ErrorCannotInstantiatePresentOptionalWithEmptyValue, ErrorGetEmptyOptional, ErrorSetEmptyOptional, Lazy, LazyAsync, LazyDictionary, Logger, NEVER, NonExhaustiveSwitchError, Operation, Optional, PredicateBuilder, RandomTimeDuration, RateThrottler, Semaphore, Sorter, StringParts, TimeDuration, TimeFrequency, TimeInstant, TimeRange, TimeUnit, TimeoutError, alwaysFalse, alwaysTrue, and, arrayGet, arrayIncludes, asError, asPromise, average, averageBy, awaitAtMost, capitalizeWord, clamp, clampInt0_100, constant, constantFalse, constantNull, constantOne, constantTrue, constantUndefined, constantZero, cssDeclarationRulesDictionaryToCss, decrement, decrementBy, delayPromise, dictToEntries, dictToList, divideBy, ellipsis, ensureArray, ensureDefined, ensureNegativeNumber, ensureNonNegativeNumber, ensureNonPositiveNumber, ensurePositiveNumber, ensureReadableArray, entriesToDict, entriesToEntries, entriesToList, extendArray, extendArrayWith, fill, fillWith, filterMap, filterMapReduce, filterWithTypePredicate, findInArray, findIndexInArray, first, flatMapTruthys, getCauseMessageFromError, getCauseStackFromError, getMessageFromError, getStackFromError, groupByBoolean, groupByBooleanWith, groupByNumber, groupByNumberWith, groupByString, groupByStringWith, groupBySymbol, groupBySymbolWith, hashCode, head, identity, ifDefined, ifNullOrUndefined, iff, includes, increment, incrementBy, indexByNumber, indexByNumberWith, indexByString, indexByStringWith, indexBySymbol, indexBySymbolWith, indexByWith, isAllowedTimeDuration, isArray, isDefined, isEmpty, isError, isFalse, isFunction, isNegativeNumber, isNullOrUndefined, isNullOrUndefinedOrEmpty, isNumber, isPositiveNumber, isString, isTimeInstant, isTrue, isUpgradable, isZero, jsonCloneDeep, last, listToDict, mapDefined, mapEntries, mapFirstTruthy, mapTruthys, max, maxBy, min, minBy, multiplyBy, noop, not, omitFromJsonObject, or, pad, padLeft, padRight, parseJson, parseTimeInstantBasicComponents, parseTimeInstantComponents, partition, pick, pipedInvoke, pipedInvokeFromArray, pluralize, promiseSequence, randomId, randomNumberInInterval, range, repeat, reverse, round, roundAwayFromZero, roundToLower, roundToNearest, roundToUpper, roundTowardsZero, shallowArrayEquals, shallowRecordEquals, sortedArray, splitWords, stringToNumber, stringifyJson, sum, sumBy, tail, throttle, throwIfNullOrUndefined, transformCssDictionary, tryToParseJson, tryToParseNumber, uniq, uniqBy, uniqByKey, unzip, upsert, withTryCatch, withTryCatchAsync, wrapWithString, xor, zip };
|
|
1426
1448
|
export type { ICancelable, ICancelablePromise, IDataUpgrader, TAccumulator, TAllKeysOptional, TAnyFunction, TArrayable, TAsyncAnyFunction, TAsyncBiConsumer, TAsyncBiFunction, TAsyncBiPredicate, TAsyncConsumer, TAsyncFunction, TAsyncOperation, TAsyncOperationTuple, TAsyncPredicate, TAsyncProducer, TAsyncValidation, TAsyncVoidFunction, TBasicTimePattern, TBiConsumer, TBiFunction, TBiPredicate, TComparisonDirection, TComparisonFunction, TComparisonResult, TConditionalOptionalType, TConditionalParameter, TConditionalParameterOptions, TConsumer, TCssDeclarationRulesDictionary, TCssSelectorDeclarationRulesDictionary, TDayOfMonth, TDayOfWeek, TDigit, TDigit1_9, TEmpty, TEmptyArray, TEmptyObject, TEmptyOptional, TFourDigits, TFourDigitsMillisecond, TFourDigitsYear, TFunction, THasNever, THourOfDay, THtmlString, TIdentityFunction, TIntervalHandle, TIsEmptyObject, TIso8601DateString, TIso8601DateUtcString, TJsonArray, TJsonObject, TJsonPrimitive, TJsonSerializable, TKeysOfType, TLoggerOpts, TMaybe, TMillisecondOfSecond, TMinuteOfHour, TMonth, TMonthName, TNegativeNumber, TNumber0_10, TNumber0_100, TNumber0_1000, TNumber0_15, TNumber0_20, TNumber0_5, TNumber1_10, TNumericFloatingPointString, TNumericString, TOneDigit, TOperation, TOperationTuple, TOptional, TOptionalKeysForType, TOptionsWithoutDefaults, TParseInt, TParseableInt, TPositiveNumber, TPredefinedTimeDuration, TPredicate, TPresentOptional, TPrettify, TPrimitive, TProducer, TPromisable, TReadableArray, TRelativeUrl, TReplaceType, TRequiredKeysForType, TSecondOfMinute, TSorter, TSorterBuilder, TStrictComparisonResult, TThreeDigits, TThreeDigitsMillisecond, TTimeInUnits, TTimeoutHandle, TTransformer, TTwoDigits, TTwoDigitsDate, TTwoDigitsHour, TTwoDigitsMinute, TTwoDigitsMonth, TTwoDigitsSecond, TTypePredicate, TUpToFourDigits, TUpToThreeDigits, TUpToTwoDigits, TUpgradable, TUrl, TValidTimeDuration, TValidation, TVoidFunction, TWeekNumber, TWithExtras, TWithRequiredProperties, TWithRequiredProperty, TYear, TZero };
|
package/.rollup/index.mjs
CHANGED
|
@@ -445,9 +445,14 @@ function indexByWith(arr, keyGetter, valueMapper = v => v) {
|
|
|
445
445
|
}
|
|
446
446
|
|
|
447
447
|
function average(arr) {
|
|
448
|
+
if (arr.length === 0)
|
|
449
|
+
return null;
|
|
448
450
|
const f = 1 / arr.length;
|
|
449
451
|
return arr.reduce((tot, cur) => tot + (cur * f), 0);
|
|
450
452
|
}
|
|
453
|
+
function averageBy(arr, getter) {
|
|
454
|
+
return average(arr.map(getter));
|
|
455
|
+
}
|
|
451
456
|
function sum(arr) {
|
|
452
457
|
return arr.reduce((tot, cur) => tot + cur, 0);
|
|
453
458
|
}
|
|
@@ -456,7 +461,7 @@ function sumBy(arr, getter) {
|
|
|
456
461
|
}
|
|
457
462
|
function min(arr) {
|
|
458
463
|
if (arr.length === 0)
|
|
459
|
-
|
|
464
|
+
return null;
|
|
460
465
|
return arr.reduce((min, cur) => cur < min ? cur : min);
|
|
461
466
|
}
|
|
462
467
|
function minBy(arr, getter) {
|
|
@@ -464,7 +469,7 @@ function minBy(arr, getter) {
|
|
|
464
469
|
}
|
|
465
470
|
function max(arr) {
|
|
466
471
|
if (arr.length === 0)
|
|
467
|
-
|
|
472
|
+
return null;
|
|
468
473
|
return arr.reduce((max, cur) => cur > max ? cur : max);
|
|
469
474
|
}
|
|
470
475
|
function maxBy(arr, getter) {
|
|
@@ -619,9 +624,36 @@ function range(start, end) {
|
|
|
619
624
|
let length = (end - start) + 1;
|
|
620
625
|
return new Array(length).fill(1).map((_, i) => start + i);
|
|
621
626
|
}
|
|
627
|
+
/**
|
|
628
|
+
* Creates an array of the specified length, where each element is filled with the given value.
|
|
629
|
+
* @param length - The length of the array to create. Must be a non-negative integer.
|
|
630
|
+
* @param value - The value to fill each element with.
|
|
631
|
+
* @returns A new array with all elements set to the given value.
|
|
632
|
+
* @throws {RangeError} If length is negative, not an integer, or NaN.
|
|
633
|
+
* @example
|
|
634
|
+
* ```ts
|
|
635
|
+
* fill(3, 'a'); // ['a', 'a', 'a']
|
|
636
|
+
* fill(0, 42); // []
|
|
637
|
+
* fill(5, null); // [null, null, null, null, null]
|
|
638
|
+
* ```
|
|
639
|
+
*/
|
|
622
640
|
function fill(length, value) {
|
|
641
|
+
if (!Number.isInteger(length) || length < 0)
|
|
642
|
+
throw new RangeError(`Length must be a non-negative integer. Got: ${length}`);
|
|
623
643
|
return new Array(length).fill(value);
|
|
624
644
|
}
|
|
645
|
+
/**
|
|
646
|
+
* Creates an array of the specified length, where each element is generated by the provided generator function.
|
|
647
|
+
* @param length - The length of the array to create. Must be a non-negative integer.
|
|
648
|
+
* @param generator - A function that takes an index and returns the value for that position.
|
|
649
|
+
* @returns A new array with elements generated by the generator function.
|
|
650
|
+
* @throws {RangeError} If length is negative or not an integer.
|
|
651
|
+
*/
|
|
652
|
+
function fillWith(length, generator) {
|
|
653
|
+
if (!Number.isInteger(length) || length < 0)
|
|
654
|
+
throw new RangeError(`Length must be a non-negative integer. Got: ${length}`);
|
|
655
|
+
return Array.from({ length }, (_, i) => generator(i));
|
|
656
|
+
}
|
|
625
657
|
function extendArray(arr, props) {
|
|
626
658
|
return arr.map((t) => ({
|
|
627
659
|
...t,
|
|
@@ -2311,8 +2343,48 @@ function normalizeMonthName(name) {
|
|
|
2311
2343
|
// Trim whitespace
|
|
2312
2344
|
.trim();
|
|
2313
2345
|
}
|
|
2314
|
-
const PATTERN_REGEX = /(M|y|d|D|h|H|m|s|S|G|Z|P|a)+/g;
|
|
2315
2346
|
const ESCAPE_REGEX = /\\"|"((?:\\"|[^"])*)"/g;
|
|
2347
|
+
/**
|
|
2348
|
+
* Tokenize a date/time pattern by detecting character changes.
|
|
2349
|
+
*
|
|
2350
|
+
* This function uses a character-change detection algorithm to split a pattern into tokens:
|
|
2351
|
+
* 1. Iterates through the pattern character by character
|
|
2352
|
+
* 2. Detects when the character changes (e.g., 'y' → 'M' → 'd')
|
|
2353
|
+
* 3. Creates tokens based on consecutive identical characters
|
|
2354
|
+
* 4. Marks tokens as pattern tokens only if they consist of repeated pattern characters
|
|
2355
|
+
*
|
|
2356
|
+
* This approach works correctly for patterns with or without separators:
|
|
2357
|
+
* - "yyyy-MM-dd" → [{token:"yyyy", type:"y"}, {token:"-", type:null}, {token:"MM", type:"M"}, {token:"-", type:null}, {token:"dd", type:"d"}]
|
|
2358
|
+
* - "yyyyMMdd" → [{token:"yyyy", type:"y"}, {token:"MM", type:"M"}, {token:"dd", type:"d"}]
|
|
2359
|
+
*
|
|
2360
|
+
* @param pattern - The date/time pattern to tokenize
|
|
2361
|
+
* @returns Array of tokens with their types (null for separators/literals, pattern char for pattern tokens)
|
|
2362
|
+
*/
|
|
2363
|
+
function tokenizePattern(pattern) {
|
|
2364
|
+
const result = [];
|
|
2365
|
+
let currentToken = '';
|
|
2366
|
+
let currentChar = '';
|
|
2367
|
+
for (const char of pattern) {
|
|
2368
|
+
if (char === currentChar) {
|
|
2369
|
+
// Same character, extend current token
|
|
2370
|
+
currentToken += char;
|
|
2371
|
+
}
|
|
2372
|
+
else {
|
|
2373
|
+
// Character changed, end current token and start new one
|
|
2374
|
+
if (currentToken) {
|
|
2375
|
+
// Mark the token with its character (caller will decide if it's a valid pattern)
|
|
2376
|
+
result.push({ token: currentToken, type: currentChar });
|
|
2377
|
+
}
|
|
2378
|
+
currentToken = char;
|
|
2379
|
+
currentChar = char;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
// Don't forget the last token
|
|
2383
|
+
if (currentToken) {
|
|
2384
|
+
result.push({ token: currentToken, type: currentChar });
|
|
2385
|
+
}
|
|
2386
|
+
return result;
|
|
2387
|
+
}
|
|
2316
2388
|
// Formatter configuration mapping: token pattern -> configuration with optional extraction rules
|
|
2317
2389
|
const formatterConfigs = {
|
|
2318
2390
|
// Year
|
|
@@ -2394,11 +2466,16 @@ function formatTimeInstant(instant, pattern, config = {}) {
|
|
|
2394
2466
|
if (index % 2 !== 0) {
|
|
2395
2467
|
return sub;
|
|
2396
2468
|
}
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2469
|
+
// Tokenize the pattern by detecting character changes
|
|
2470
|
+
const tokens = tokenizePattern(sub);
|
|
2471
|
+
// Format each token and join the results
|
|
2472
|
+
return tokens.map(({ token, type }) => {
|
|
2473
|
+
// If type is null or formatting fails, keep token as-is
|
|
2474
|
+
if (!type)
|
|
2475
|
+
return token;
|
|
2476
|
+
const formatted = formatType(type, token.length, date, locale, timeZone);
|
|
2477
|
+
return formatted !== undefined ? formatted : token;
|
|
2478
|
+
}).join('');
|
|
2402
2479
|
})
|
|
2403
2480
|
.join('');
|
|
2404
2481
|
}
|
|
@@ -2426,53 +2503,62 @@ function parseTimeInstantComponents(dateString, pattern, config = {}) {
|
|
|
2426
2503
|
if (index % 2 !== 0) {
|
|
2427
2504
|
return sub.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // Escape special regex chars
|
|
2428
2505
|
}
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2506
|
+
// Tokenize the pattern by detecting character changes
|
|
2507
|
+
const patternTokens = tokenizePattern(sub);
|
|
2508
|
+
// Build regex pattern from tokens
|
|
2509
|
+
return patternTokens.map(({ token, type }) => {
|
|
2510
|
+
// Check if this is a valid pattern by looking it up in formatterConfigs
|
|
2511
|
+
const isValidPattern = type && formatterConfigs[token];
|
|
2512
|
+
if (!isValidPattern) {
|
|
2513
|
+
// This is a literal/separator, escape it for regex
|
|
2514
|
+
return token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
2515
|
+
}
|
|
2516
|
+
// This is a pattern token, track it and create regex
|
|
2517
|
+
tokens.push({ type, length: token.length, position: position++ });
|
|
2432
2518
|
// Create appropriate regex for each token type
|
|
2433
2519
|
switch (type) {
|
|
2434
2520
|
case 'y':
|
|
2435
|
-
return
|
|
2521
|
+
return token.length === 2 ? '(\\d{2})' : '(\\d{4})';
|
|
2436
2522
|
case 'M':
|
|
2437
|
-
if (
|
|
2523
|
+
if (token.length === 1)
|
|
2438
2524
|
return '(\\d{1,2})';
|
|
2439
|
-
if (
|
|
2525
|
+
if (token.length === 2)
|
|
2440
2526
|
return '(\\d{2})';
|
|
2441
|
-
if (
|
|
2527
|
+
if (token.length === 3)
|
|
2442
2528
|
return '([A-Za-z.]{1,7})';
|
|
2443
2529
|
return '([A-Za-z]+)';
|
|
2444
2530
|
case 'd':
|
|
2445
|
-
return
|
|
2531
|
+
return token.length === 1 ? '(\\d{1,2})' : '(\\d{2})';
|
|
2446
2532
|
case 'H':
|
|
2447
2533
|
case 'h':
|
|
2448
|
-
return
|
|
2534
|
+
return token.length === 1 ? '(\\d{1,2})' : '(\\d{2})';
|
|
2449
2535
|
case 'm':
|
|
2450
2536
|
case 's':
|
|
2451
|
-
return
|
|
2537
|
+
return token.length === 1 ? '(\\d{1,2})' : '(\\d{2})';
|
|
2452
2538
|
case 'S':
|
|
2453
|
-
return `(\\d{${
|
|
2539
|
+
return `(\\d{${token.length}})`;
|
|
2454
2540
|
case 'a':
|
|
2455
2541
|
return '([aApP][mM])';
|
|
2456
2542
|
case 'D':
|
|
2457
|
-
if (
|
|
2543
|
+
if (token.length === 1)
|
|
2458
2544
|
return '([A-Za-z])';
|
|
2459
|
-
if (
|
|
2545
|
+
if (token.length === 2)
|
|
2460
2546
|
return '([A-Za-z]{3})';
|
|
2461
2547
|
return '([A-Za-z]+)';
|
|
2462
2548
|
case 'G':
|
|
2463
|
-
if (
|
|
2549
|
+
if (token.length === 1)
|
|
2464
2550
|
return '([A-Za-z])';
|
|
2465
|
-
if (
|
|
2551
|
+
if (token.length === 2)
|
|
2466
2552
|
return '([A-Za-z]{2})';
|
|
2467
2553
|
return '([A-Za-z\\s]+)';
|
|
2468
2554
|
case 'Z':
|
|
2469
|
-
return
|
|
2555
|
+
return token.length === 1 ? '([A-Za-z0-9+\\-:]+)' : '([A-Za-z\\s]+)';
|
|
2470
2556
|
case 'P':
|
|
2471
2557
|
return '([A-Za-z\\s]+)';
|
|
2472
2558
|
default:
|
|
2473
|
-
return
|
|
2559
|
+
return token;
|
|
2474
2560
|
}
|
|
2475
|
-
});
|
|
2561
|
+
}).join('');
|
|
2476
2562
|
}).join('');
|
|
2477
2563
|
const regex = new RegExp('^' + regexPattern + '$');
|
|
2478
2564
|
const matches = dateString.match(regex);
|
|
@@ -2598,10 +2684,10 @@ function parseTimeInstantComponents(dateString, pattern, config = {}) {
|
|
|
2598
2684
|
* @returns Partial time instant parameters that were parsed from the string
|
|
2599
2685
|
* @throws Error if the string doesn't match the pattern or contains invalid values
|
|
2600
2686
|
*/
|
|
2601
|
-
function parseTimeInstantBasicComponents(dateString, pattern) {
|
|
2687
|
+
function parseTimeInstantBasicComponents(dateString, pattern, ignoreIntlAvailability = false) {
|
|
2602
2688
|
// Check if Intl is available, if so warn the user about the existing function
|
|
2603
2689
|
const isIntlAvailable = typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat !== 'undefined';
|
|
2604
|
-
if (isIntlAvailable)
|
|
2690
|
+
if (isIntlAvailable && !ignoreIntlAvailability)
|
|
2605
2691
|
console.warn('Intl is available, use parseTimeInstantComponents instead of parseTimeInstantBasicComponents.');
|
|
2606
2692
|
const result = {};
|
|
2607
2693
|
let patternIndex = 0;
|
|
@@ -3473,5 +3559,5 @@ function isUpgradable(obj) {
|
|
|
3473
3559
|
return isDefined(obj) && typeof obj === "object" && VERSION_FIELD in obj && isNumber(obj.$version) && isPositiveNumber(obj.$version);
|
|
3474
3560
|
}
|
|
3475
3561
|
|
|
3476
|
-
export { Cached, DataUpgrader, Deferred, DeferredCanceledError, ErrorCannotInstantiatePresentOptionalWithEmptyValue, ErrorGetEmptyOptional, ErrorSetEmptyOptional, Lazy, LazyAsync, LazyDictionary, Logger, NEVER, NonExhaustiveSwitchError, Operation, Optional, PredicateBuilder, RandomTimeDuration, RateThrottler, Semaphore, Sorter, StringParts, TimeDuration, TimeFrequency, TimeInstant, TimeRange, TimeUnit, TimeoutError, alwaysFalse, alwaysTrue, and, arrayGet, arrayIncludes, asError, asPromise, average, awaitAtMost, capitalizeWord, clamp, clampInt0_100, constant, constantFalse, constantNull, constantOne, constantTrue, constantUndefined, constantZero, cssDeclarationRulesDictionaryToCss, decrement, decrementBy, delayPromise, dictToEntries, dictToList, divideBy, ellipsis, ensureArray, ensureDefined, ensureNegativeNumber, ensureNonNegativeNumber, ensureNonPositiveNumber, ensurePositiveNumber, ensureReadableArray, entriesToDict, entriesToEntries, entriesToList, extendArray, extendArrayWith, fill, filterMap, filterMapReduce, filterWithTypePredicate, findInArray, findIndexInArray, first$1 as first, flatMapTruthys, getCauseMessageFromError, getCauseStackFromError, getMessageFromError, getStackFromError, groupByBoolean, groupByBooleanWith, groupByNumber, groupByNumberWith, groupByString, groupByStringWith, groupBySymbol, groupBySymbolWith, hashCode, head, identity, ifDefined, ifNullOrUndefined, iff, includes, increment, incrementBy, indexByNumber, indexByNumberWith, indexByString, indexByStringWith, indexBySymbol, indexBySymbolWith, indexByWith, isAllowedTimeDuration, isArray, isDefined, isEmpty, isError, isFalse, isFunction, isNegativeNumber, isNullOrUndefined, isNullOrUndefinedOrEmpty, isNumber, isPositiveNumber, isString, isTimeInstant, isTrue, isUpgradable, isZero, jsonCloneDeep, last$1 as last, listToDict, mapDefined, mapEntries, mapFirstTruthy, mapTruthys, max, maxBy, min, minBy, multiplyBy, noop, not, omitFromJsonObject, or, pad, padLeft, padRight, parseJson, parseTimeInstantBasicComponents, parseTimeInstantComponents, partition, pick, pipedInvoke, pipedInvokeFromArray, pluralize, promiseSequence, randomId, randomNumberInInterval, range, repeat, reverse$1 as reverse, round, roundAwayFromZero, roundToLower, roundToNearest, roundToUpper, roundTowardsZero, shallowArrayEquals, shallowRecordEquals, sortedArray, splitWords, stringToNumber, stringifyJson, sum, sumBy, tail, throttle, throwIfNullOrUndefined, transformCssDictionary, tryToParseJson, tryToParseNumber, uniq, uniqBy, uniqByKey, unzip, upsert, withTryCatch, withTryCatchAsync, wrapWithString, xor, zip };
|
|
3562
|
+
export { Cached, DataUpgrader, Deferred, DeferredCanceledError, ErrorCannotInstantiatePresentOptionalWithEmptyValue, ErrorGetEmptyOptional, ErrorSetEmptyOptional, Lazy, LazyAsync, LazyDictionary, Logger, NEVER, NonExhaustiveSwitchError, Operation, Optional, PredicateBuilder, RandomTimeDuration, RateThrottler, Semaphore, Sorter, StringParts, TimeDuration, TimeFrequency, TimeInstant, TimeRange, TimeUnit, TimeoutError, alwaysFalse, alwaysTrue, and, arrayGet, arrayIncludes, asError, asPromise, average, averageBy, awaitAtMost, capitalizeWord, clamp, clampInt0_100, constant, constantFalse, constantNull, constantOne, constantTrue, constantUndefined, constantZero, cssDeclarationRulesDictionaryToCss, decrement, decrementBy, delayPromise, dictToEntries, dictToList, divideBy, ellipsis, ensureArray, ensureDefined, ensureNegativeNumber, ensureNonNegativeNumber, ensureNonPositiveNumber, ensurePositiveNumber, ensureReadableArray, entriesToDict, entriesToEntries, entriesToList, extendArray, extendArrayWith, fill, fillWith, filterMap, filterMapReduce, filterWithTypePredicate, findInArray, findIndexInArray, first$1 as first, flatMapTruthys, getCauseMessageFromError, getCauseStackFromError, getMessageFromError, getStackFromError, groupByBoolean, groupByBooleanWith, groupByNumber, groupByNumberWith, groupByString, groupByStringWith, groupBySymbol, groupBySymbolWith, hashCode, head, identity, ifDefined, ifNullOrUndefined, iff, includes, increment, incrementBy, indexByNumber, indexByNumberWith, indexByString, indexByStringWith, indexBySymbol, indexBySymbolWith, indexByWith, isAllowedTimeDuration, isArray, isDefined, isEmpty, isError, isFalse, isFunction, isNegativeNumber, isNullOrUndefined, isNullOrUndefinedOrEmpty, isNumber, isPositiveNumber, isString, isTimeInstant, isTrue, isUpgradable, isZero, jsonCloneDeep, last$1 as last, listToDict, mapDefined, mapEntries, mapFirstTruthy, mapTruthys, max, maxBy, min, minBy, multiplyBy, noop, not, omitFromJsonObject, or, pad, padLeft, padRight, parseJson, parseTimeInstantBasicComponents, parseTimeInstantComponents, partition, pick, pipedInvoke, pipedInvokeFromArray, pluralize, promiseSequence, randomId, randomNumberInInterval, range, repeat, reverse$1 as reverse, round, roundAwayFromZero, roundToLower, roundToNearest, roundToUpper, roundTowardsZero, shallowArrayEquals, shallowRecordEquals, sortedArray, splitWords, stringToNumber, stringifyJson, sum, sumBy, tail, throttle, throwIfNullOrUndefined, transformCssDictionary, tryToParseJson, tryToParseNumber, uniq, uniqBy, uniqByKey, unzip, upsert, withTryCatch, withTryCatchAsync, wrapWithString, xor, zip };
|
|
3477
3563
|
//# sourceMappingURL=index.mjs.map
|