@zelgadis87/utils-core 5.3.6 → 5.3.8

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.
@@ -782,10 +782,46 @@ declare function average(arr: TReadableArray<number>): TMaybe<number>;
782
782
  declare function averageBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): TMaybe<number>;
783
783
  declare function sum(arr: TReadableArray<number>): number;
784
784
  declare function sumBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): number;
785
+ /**
786
+ * Finds the minimum value in an array of numbers.
787
+ * @param arr - The array of numbers to search
788
+ * @returns The minimum value, or null if the array is empty
789
+ */
785
790
  declare function min(arr: TReadableArray<number>): TMaybe<number>;
791
+ /**
792
+ * Finds the minimum numeric value extracted from array elements using a getter function.
793
+ * @param arr - The array of elements to search
794
+ * @param getter - Function to extract a numeric value from each element
795
+ * @returns The minimum extracted value, or null if the array is empty
796
+ */
786
797
  declare function minBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): TMaybe<number>;
798
+ /**
799
+ * Finds the maximum value in an array of numbers.
800
+ * @param arr - The array of numbers to search
801
+ * @returns The maximum value, or null if the array is empty
802
+ */
787
803
  declare function max(arr: TReadableArray<number>): TMaybe<number>;
804
+ /**
805
+ * Finds the maximum numeric value extracted from array elements using a getter function.
806
+ * @param arr - The array of elements to search
807
+ * @param getter - Function to extract a numeric value from each element
808
+ * @returns The maximum extracted value, or null if the array is empty
809
+ */
788
810
  declare function maxBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): TMaybe<number>;
811
+ /**
812
+ * Finds the element with the maximum numeric value extracted using a getter function.
813
+ * @param arr - The array of elements to search
814
+ * @param getter - Function to extract a numeric value from each element
815
+ * @returns The element with the maximum value, or null if the array is empty
816
+ */
817
+ declare function havingMaxBy<T>(arr: Array<T>, getter: (t: T) => number): TMaybe<T>;
818
+ /**
819
+ * Finds the element with the minimum numeric value extracted using a getter function.
820
+ * @param arr - The array of elements to search
821
+ * @param getter - Function to extract a numeric value from each element
822
+ * @returns The element with the minimum value, or null if the array is empty
823
+ */
824
+ declare function havingMinBy<T>(arr: Array<T>, getter: (t: T) => number): TMaybe<T>;
789
825
 
790
826
  declare function uniq<T>(arr: T[]): T[];
791
827
  declare function uniqBy<T, K>(arr: T[], getter: TFunction<T, K>): T[];
@@ -1103,6 +1139,8 @@ declare const NEVER: Promise<unknown>;
1103
1139
 
1104
1140
  declare function randomNumberInInterval(min: number, max: number): number;
1105
1141
  declare const randomId: (length: TPositiveNumber) => string;
1142
+ declare function randomPick<T>(arr: T[]): TMaybe<T>;
1143
+ declare function randomPicks<T>(arr: T[], count: TPositiveNumber): T[];
1106
1144
 
1107
1145
  declare class StringParts {
1108
1146
  private readonly _parts;
@@ -1444,5 +1482,5 @@ declare class DataUpgrader<X extends TUpgradable, XLatest extends X> implements
1444
1482
  }
1445
1483
  declare function isUpgradable(obj: TJsonSerializable): obj is TUpgradable;
1446
1484
 
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 };
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 };
1448
1486
  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
@@ -459,22 +459,82 @@ function sum(arr) {
459
459
  function sumBy(arr, getter) {
460
460
  return sum(arr.map(getter));
461
461
  }
462
+ /**
463
+ * Finds the minimum value in an array of numbers.
464
+ * @param arr - The array of numbers to search
465
+ * @returns The minimum value, or null if the array is empty
466
+ */
462
467
  function min(arr) {
463
468
  if (arr.length === 0)
464
469
  return null;
465
470
  return arr.reduce((min, cur) => cur < min ? cur : min);
466
471
  }
472
+ /**
473
+ * Finds the minimum numeric value extracted from array elements using a getter function.
474
+ * @param arr - The array of elements to search
475
+ * @param getter - Function to extract a numeric value from each element
476
+ * @returns The minimum extracted value, or null if the array is empty
477
+ */
467
478
  function minBy(arr, getter) {
468
479
  return min(arr.map(getter));
469
480
  }
481
+ /**
482
+ * Finds the maximum value in an array of numbers.
483
+ * @param arr - The array of numbers to search
484
+ * @returns The maximum value, or null if the array is empty
485
+ */
470
486
  function max(arr) {
471
487
  if (arr.length === 0)
472
488
  return null;
473
489
  return arr.reduce((max, cur) => cur > max ? cur : max);
474
490
  }
491
+ /**
492
+ * Finds the maximum numeric value extracted from array elements using a getter function.
493
+ * @param arr - The array of elements to search
494
+ * @param getter - Function to extract a numeric value from each element
495
+ * @returns The maximum extracted value, or null if the array is empty
496
+ */
475
497
  function maxBy(arr, getter) {
476
498
  return max(arr.map(getter));
477
499
  }
500
+ /**
501
+ * Finds the element with the maximum numeric value extracted using a getter function.
502
+ * @param arr - The array of elements to search
503
+ * @param getter - Function to extract a numeric value from each element
504
+ * @returns The element with the maximum value, or null if the array is empty
505
+ */
506
+ function havingMaxBy(arr, getter) {
507
+ if (arr.length === 0)
508
+ return null;
509
+ return arr.reduce((ret, cur) => {
510
+ const curValue = getter(cur);
511
+ if (curValue > ret.max) {
512
+ return { value: cur, max: curValue };
513
+ }
514
+ else {
515
+ return ret;
516
+ }
517
+ }, { value: null, max: -Infinity }).value;
518
+ }
519
+ /**
520
+ * Finds the element with the minimum numeric value extracted using a getter function.
521
+ * @param arr - The array of elements to search
522
+ * @param getter - Function to extract a numeric value from each element
523
+ * @returns The element with the minimum value, or null if the array is empty
524
+ */
525
+ function havingMinBy(arr, getter) {
526
+ if (arr.length === 0)
527
+ return null;
528
+ return arr.reduce((ret, cur) => {
529
+ const curValue = getter(cur);
530
+ if (curValue < ret.min) {
531
+ return { value: cur, min: curValue };
532
+ }
533
+ else {
534
+ return ret;
535
+ }
536
+ }, { value: null, min: +Infinity }).value;
537
+ }
478
538
 
479
539
  function constant(v) { return () => v; }
480
540
  function identity(t) { return t; }
@@ -1078,6 +1138,20 @@ function randomNumberInInterval(min, max) {
1078
1138
  const randomId = (length) => {
1079
1139
  return Math.random().toString(36).substring(2, length + 2);
1080
1140
  };
1141
+ function randomPick(arr) {
1142
+ return first$1(randomPicks(arr, 1));
1143
+ }
1144
+ function randomPicks(arr, count) {
1145
+ const available = [...arr];
1146
+ const result = [];
1147
+ while (available.length > 0 && count > 0) {
1148
+ const randomIndex = randomNumberInInterval(0, available.length - 1);
1149
+ result.push(available[randomIndex]);
1150
+ available.splice(randomIndex, 1);
1151
+ count--;
1152
+ }
1153
+ return result;
1154
+ }
1081
1155
 
1082
1156
  function dictToEntries(obj) {
1083
1157
  return Object.entries(obj);
@@ -3559,5 +3633,5 @@ function isUpgradable(obj) {
3559
3633
  return isDefined(obj) && typeof obj === "object" && VERSION_FIELD in obj && isNumber(obj.$version) && isPositiveNumber(obj.$version);
3560
3634
  }
3561
3635
 
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 };
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 };
3563
3637
  //# sourceMappingURL=index.mjs.map