@zelgadis87/utils-core 5.3.8 → 5.4.0

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.
@@ -133,6 +133,8 @@ declare class Optional<T> implements TOptional<T> {
133
133
  static empty<T>(): TEmptyOptional<T>;
134
134
  static of<T>(t: T): TPresentOptional<T>;
135
135
  static ofNullable<T>(t: T | null | undefined): TOptional<T>;
136
+ static findInArray<T>(arr: ReadonlyArray<T>, predicate: TPredicate<T>): TOptional<T>;
137
+ static findIndexInArray<T>(arr: ReadonlyArray<T>, predicate: TPredicate<T>): TOptional<number>;
136
138
  }
137
139
 
138
140
  type TOptional<T> = {
@@ -901,7 +903,9 @@ declare function partition<T>(arr: T[], predicate: TPredicate<T>): [T[], T[]];
901
903
  declare function mapFirstTruthy<T, R>(arr: T[], mapFn: TTransformer<T, R>): R | null;
902
904
  declare function listToDict<T, K extends string, V>(arr: T[], mapFn: TTransformer<T, [K, V]>): Record<K, V>;
903
905
  declare function shallowArrayEquals(a: unknown[], b: unknown[]): boolean;
906
+ /** @deprecated[2026.03.01]: Use {@link Optional.findInArray} instead. */
904
907
  declare function findInArray<T>(arr: T[], predicate: TPredicate<T>): TOptional<T>;
908
+ /** @deprecated[2026.03.01]: Use {@link Optional.findIndexInArray} instead. */
905
909
  declare function findIndexInArray<T>(arr: T[], predicate: TPredicate<T>): TOptional<number>;
906
910
  declare function zip<T, R>(ts: T[], rs: R[]): [T, R][];
907
911
  declare function unzip<T, R>(arr: [T, R][]): [T[], R[]];
@@ -1137,7 +1141,25 @@ declare class TimeoutError extends Error {
1137
1141
  declare function awaitAtMost<T>(promise: Promise<T>, duration: TimeDuration): Promise<T>;
1138
1142
  declare const NEVER: Promise<unknown>;
1139
1143
 
1144
+ /**
1145
+ * Returns a random integer in the range [min, max].
1146
+ * @deprecated Use randomIntegerInInterval or randomDecimalInInterval instead
1147
+ */
1140
1148
  declare function randomNumberInInterval(min: number, max: number): number;
1149
+ /**
1150
+ * Returns a random integer in the range [min, max].
1151
+ * @param min - Minimum value (inclusive)
1152
+ * @param max - Maximum value (inclusive)
1153
+ * @returns A random integer between min and max
1154
+ */
1155
+ declare function randomIntegerInInterval(min: number, max: number): number;
1156
+ /**
1157
+ * Returns a random decimal in the range [min, max).
1158
+ * @param min - Minimum value (inclusive)
1159
+ * @param max - Maximum value (exclusive)
1160
+ * @returns A random decimal between min and max
1161
+ */
1162
+ declare function randomDecimalInInterval(min: number, max: number): number;
1141
1163
  declare const randomId: (length: TPositiveNumber) => string;
1142
1164
  declare function randomPick<T>(arr: T[]): TMaybe<T>;
1143
1165
  declare function randomPicks<T>(arr: T[], count: TPositiveNumber): T[];
@@ -1482,5 +1504,5 @@ declare class DataUpgrader<X extends TUpgradable, XLatest extends X> implements
1482
1504
  }
1483
1505
  declare function isUpgradable(obj: TJsonSerializable): obj is TUpgradable;
1484
1506
 
1485
- 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, havingMaxBy, havingMinBy, 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, randomPick, randomPicks, 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 };
1507
+ 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, havingMaxBy, havingMinBy, 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, randomDecimalInInterval, randomId, randomIntegerInInterval, randomNumberInInterval, randomPick, randomPicks, 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 };
1486
1508
  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
@@ -360,6 +360,13 @@ class Optional {
360
360
  static ofNullable(t) {
361
361
  return new Optional(t);
362
362
  }
363
+ static findInArray(arr, predicate) {
364
+ return Optional.ofNullable(arr.find(predicate));
365
+ }
366
+ static findIndexInArray(arr, predicate) {
367
+ const idx = arr.findIndex(predicate);
368
+ return idx === -1 ? Optional.empty() : Optional.of(idx);
369
+ }
363
370
  }
364
371
  class ErrorGetEmptyOptional extends Error {
365
372
  constructor() {
@@ -805,12 +812,13 @@ function shallowArrayEquals(a, b) {
805
812
  }
806
813
  return true;
807
814
  }
815
+ /** @deprecated[2026.03.01]: Use {@link Optional.findInArray} instead. */
808
816
  function findInArray(arr, predicate) {
809
- return Optional.ofNullable(arr.find(predicate));
817
+ return Optional.findInArray(arr, predicate);
810
818
  }
819
+ /** @deprecated[2026.03.01]: Use {@link Optional.findIndexInArray} instead. */
811
820
  function findIndexInArray(arr, predicate) {
812
- const idx = arr.findIndex(predicate);
813
- return idx === -1 ? Optional.empty() : Optional.of(idx);
821
+ return Optional.findIndexInArray(arr, predicate);
814
822
  }
815
823
  function zip(ts, rs) {
816
824
  if (ts.length !== rs.length)
@@ -1132,11 +1140,38 @@ async function awaitAtMost(promise, duration) {
1132
1140
  }
1133
1141
  const NEVER = new Promise(_resolve => { });
1134
1142
 
1143
+ /**
1144
+ * Returns a random integer in the range [min, max].
1145
+ * @deprecated Use randomIntegerInInterval or randomDecimalInInterval instead
1146
+ */
1135
1147
  function randomNumberInInterval(min, max) {
1136
1148
  return Math.floor(Math.random() * (max - min + 1) + min);
1137
1149
  }
1150
+ /**
1151
+ * Returns a random integer in the range [min, max].
1152
+ * @param min - Minimum value (inclusive)
1153
+ * @param max - Maximum value (inclusive)
1154
+ * @returns A random integer between min and max
1155
+ */
1156
+ function randomIntegerInInterval(min, max) {
1157
+ return Math.floor(Math.random() * (max - min + 1) + min);
1158
+ }
1159
+ /**
1160
+ * Returns a random decimal in the range [min, max).
1161
+ * @param min - Minimum value (inclusive)
1162
+ * @param max - Maximum value (exclusive)
1163
+ * @returns A random decimal between min and max
1164
+ */
1165
+ function randomDecimalInInterval(min, max) {
1166
+ return Math.random() * (max - min) + min;
1167
+ }
1138
1168
  const randomId = (length) => {
1139
- return Math.random().toString(36).substring(2, length + 2);
1169
+ const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
1170
+ let result = '';
1171
+ for (let i = 0; i < length; i++) {
1172
+ result += characters.charAt(randomIntegerInInterval(0, characters.length - 1));
1173
+ }
1174
+ return result;
1140
1175
  };
1141
1176
  function randomPick(arr) {
1142
1177
  return first$1(randomPicks(arr, 1));
@@ -1145,7 +1180,7 @@ function randomPicks(arr, count) {
1145
1180
  const available = [...arr];
1146
1181
  const result = [];
1147
1182
  while (available.length > 0 && count > 0) {
1148
- const randomIndex = randomNumberInInterval(0, available.length - 1);
1183
+ const randomIndex = randomIntegerInInterval(0, available.length - 1);
1149
1184
  result.push(available[randomIndex]);
1150
1185
  available.splice(randomIndex, 1);
1151
1186
  count--;
@@ -2680,7 +2715,7 @@ function parseTimeInstantComponents(dateString, pattern, config = {}) {
2680
2715
  break;
2681
2716
  }
2682
2717
  default:
2683
- throw new Error(`Invalid month pattern: ${token}`);
2718
+ throw new Error(`Invalid month pattern: ${JSON.stringify(token)}`);
2684
2719
  }
2685
2720
  break;
2686
2721
  case 'd':
@@ -2762,6 +2797,7 @@ function parseTimeInstantBasicComponents(dateString, pattern, ignoreIntlAvailabi
2762
2797
  // Check if Intl is available, if so warn the user about the existing function
2763
2798
  const isIntlAvailable = typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat !== 'undefined';
2764
2799
  if (isIntlAvailable && !ignoreIntlAvailability)
2800
+ // eslint-disable-next-line no-restricted-globals
2765
2801
  console.warn('Intl is available, use parseTimeInstantComponents instead of parseTimeInstantBasicComponents.');
2766
2802
  const result = {};
2767
2803
  let patternIndex = 0;
@@ -3450,7 +3486,7 @@ const Sorter = {
3450
3486
 
3451
3487
  function randomize(unit) {
3452
3488
  return (a, b) => {
3453
- return TimeDuration.fromMs(randomNumberInInterval(unit.toMs(a), unit.toMs(b)));
3489
+ return TimeDuration.fromMs(randomIntegerInInterval(unit.toMs(a), unit.toMs(b)));
3454
3490
  };
3455
3491
  }
3456
3492
  class RandomTimeDuration {
@@ -3633,5 +3669,5 @@ function isUpgradable(obj) {
3633
3669
  return isDefined(obj) && typeof obj === "object" && VERSION_FIELD in obj && isNumber(obj.$version) && isPositiveNumber(obj.$version);
3634
3670
  }
3635
3671
 
3636
- 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, havingMaxBy, havingMinBy, 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, randomPick, randomPicks, 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 };
3672
+ 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, havingMaxBy, havingMinBy, 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, randomDecimalInInterval, randomId, randomIntegerInInterval, randomNumberInInterval, randomPick, randomPicks, 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 };
3637
3673
  //# sourceMappingURL=index.mjs.map