@zelgadis87/utils-core 5.3.7 → 5.3.9
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 +105 -6
- package/.rollup/index.cjs.map +1 -1
- package/.rollup/index.d.ts +59 -1
- package/.rollup/index.mjs +102 -7
- package/.rollup/index.mjs.map +1 -1
- package/.rollup/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +13 -0
- package/package.json +8 -8
- package/src/Optional.ts +9 -0
- package/src/time/RandomTimeDuration.ts +2 -2
- package/src/utils/arrays/statistics.ts +60 -0
- package/src/utils/arrays.ts +4 -3
- package/src/utils/random.ts +31 -2
package/.rollup/index.d.ts
CHANGED
|
@@ -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> = {
|
|
@@ -782,10 +784,46 @@ declare function average(arr: TReadableArray<number>): TMaybe<number>;
|
|
|
782
784
|
declare function averageBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): TMaybe<number>;
|
|
783
785
|
declare function sum(arr: TReadableArray<number>): number;
|
|
784
786
|
declare function sumBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): number;
|
|
787
|
+
/**
|
|
788
|
+
* Finds the minimum value in an array of numbers.
|
|
789
|
+
* @param arr - The array of numbers to search
|
|
790
|
+
* @returns The minimum value, or null if the array is empty
|
|
791
|
+
*/
|
|
785
792
|
declare function min(arr: TReadableArray<number>): TMaybe<number>;
|
|
793
|
+
/**
|
|
794
|
+
* Finds the minimum numeric value extracted from array elements using a getter function.
|
|
795
|
+
* @param arr - The array of elements to search
|
|
796
|
+
* @param getter - Function to extract a numeric value from each element
|
|
797
|
+
* @returns The minimum extracted value, or null if the array is empty
|
|
798
|
+
*/
|
|
786
799
|
declare function minBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): TMaybe<number>;
|
|
800
|
+
/**
|
|
801
|
+
* Finds the maximum value in an array of numbers.
|
|
802
|
+
* @param arr - The array of numbers to search
|
|
803
|
+
* @returns The maximum value, or null if the array is empty
|
|
804
|
+
*/
|
|
787
805
|
declare function max(arr: TReadableArray<number>): TMaybe<number>;
|
|
806
|
+
/**
|
|
807
|
+
* Finds the maximum numeric value extracted from array elements using a getter function.
|
|
808
|
+
* @param arr - The array of elements to search
|
|
809
|
+
* @param getter - Function to extract a numeric value from each element
|
|
810
|
+
* @returns The maximum extracted value, or null if the array is empty
|
|
811
|
+
*/
|
|
788
812
|
declare function maxBy<T>(arr: TReadableArray<T>, getter: (t: T) => number): TMaybe<number>;
|
|
813
|
+
/**
|
|
814
|
+
* Finds the element with the maximum numeric value extracted using a getter function.
|
|
815
|
+
* @param arr - The array of elements to search
|
|
816
|
+
* @param getter - Function to extract a numeric value from each element
|
|
817
|
+
* @returns The element with the maximum value, or null if the array is empty
|
|
818
|
+
*/
|
|
819
|
+
declare function havingMaxBy<T>(arr: Array<T>, getter: (t: T) => number): TMaybe<T>;
|
|
820
|
+
/**
|
|
821
|
+
* Finds the element with the minimum numeric value extracted using a getter function.
|
|
822
|
+
* @param arr - The array of elements to search
|
|
823
|
+
* @param getter - Function to extract a numeric value from each element
|
|
824
|
+
* @returns The element with the minimum value, or null if the array is empty
|
|
825
|
+
*/
|
|
826
|
+
declare function havingMinBy<T>(arr: Array<T>, getter: (t: T) => number): TMaybe<T>;
|
|
789
827
|
|
|
790
828
|
declare function uniq<T>(arr: T[]): T[];
|
|
791
829
|
declare function uniqBy<T, K>(arr: T[], getter: TFunction<T, K>): T[];
|
|
@@ -865,7 +903,9 @@ declare function partition<T>(arr: T[], predicate: TPredicate<T>): [T[], T[]];
|
|
|
865
903
|
declare function mapFirstTruthy<T, R>(arr: T[], mapFn: TTransformer<T, R>): R | null;
|
|
866
904
|
declare function listToDict<T, K extends string, V>(arr: T[], mapFn: TTransformer<T, [K, V]>): Record<K, V>;
|
|
867
905
|
declare function shallowArrayEquals(a: unknown[], b: unknown[]): boolean;
|
|
906
|
+
/** @deprecated[2026.03.01]: Use {@link Optional.findInArray} instead. */
|
|
868
907
|
declare function findInArray<T>(arr: T[], predicate: TPredicate<T>): TOptional<T>;
|
|
908
|
+
/** @deprecated[2026.03.01]: Use {@link Optional.findIndexInArray} instead. */
|
|
869
909
|
declare function findIndexInArray<T>(arr: T[], predicate: TPredicate<T>): TOptional<number>;
|
|
870
910
|
declare function zip<T, R>(ts: T[], rs: R[]): [T, R][];
|
|
871
911
|
declare function unzip<T, R>(arr: [T, R][]): [T[], R[]];
|
|
@@ -1101,7 +1141,25 @@ declare class TimeoutError extends Error {
|
|
|
1101
1141
|
declare function awaitAtMost<T>(promise: Promise<T>, duration: TimeDuration): Promise<T>;
|
|
1102
1142
|
declare const NEVER: Promise<unknown>;
|
|
1103
1143
|
|
|
1144
|
+
/**
|
|
1145
|
+
* Returns a random integer in the range [min, max].
|
|
1146
|
+
* @deprecated Use randomIntegerInInterval or randomDecimalInInterval instead
|
|
1147
|
+
*/
|
|
1104
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;
|
|
1105
1163
|
declare const randomId: (length: TPositiveNumber) => string;
|
|
1106
1164
|
declare function randomPick<T>(arr: T[]): TMaybe<T>;
|
|
1107
1165
|
declare function randomPicks<T>(arr: T[], count: TPositiveNumber): T[];
|
|
@@ -1446,5 +1504,5 @@ declare class DataUpgrader<X extends TUpgradable, XLatest extends X> implements
|
|
|
1446
1504
|
}
|
|
1447
1505
|
declare function isUpgradable(obj: TJsonSerializable): obj is TUpgradable;
|
|
1448
1506
|
|
|
1449
|
-
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, 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 };
|
|
1450
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() {
|
|
@@ -459,22 +466,82 @@ function sum(arr) {
|
|
|
459
466
|
function sumBy(arr, getter) {
|
|
460
467
|
return sum(arr.map(getter));
|
|
461
468
|
}
|
|
469
|
+
/**
|
|
470
|
+
* Finds the minimum value in an array of numbers.
|
|
471
|
+
* @param arr - The array of numbers to search
|
|
472
|
+
* @returns The minimum value, or null if the array is empty
|
|
473
|
+
*/
|
|
462
474
|
function min(arr) {
|
|
463
475
|
if (arr.length === 0)
|
|
464
476
|
return null;
|
|
465
477
|
return arr.reduce((min, cur) => cur < min ? cur : min);
|
|
466
478
|
}
|
|
479
|
+
/**
|
|
480
|
+
* Finds the minimum numeric value extracted from array elements using a getter function.
|
|
481
|
+
* @param arr - The array of elements to search
|
|
482
|
+
* @param getter - Function to extract a numeric value from each element
|
|
483
|
+
* @returns The minimum extracted value, or null if the array is empty
|
|
484
|
+
*/
|
|
467
485
|
function minBy(arr, getter) {
|
|
468
486
|
return min(arr.map(getter));
|
|
469
487
|
}
|
|
488
|
+
/**
|
|
489
|
+
* Finds the maximum value in an array of numbers.
|
|
490
|
+
* @param arr - The array of numbers to search
|
|
491
|
+
* @returns The maximum value, or null if the array is empty
|
|
492
|
+
*/
|
|
470
493
|
function max(arr) {
|
|
471
494
|
if (arr.length === 0)
|
|
472
495
|
return null;
|
|
473
496
|
return arr.reduce((max, cur) => cur > max ? cur : max);
|
|
474
497
|
}
|
|
498
|
+
/**
|
|
499
|
+
* Finds the maximum numeric value extracted from array elements using a getter function.
|
|
500
|
+
* @param arr - The array of elements to search
|
|
501
|
+
* @param getter - Function to extract a numeric value from each element
|
|
502
|
+
* @returns The maximum extracted value, or null if the array is empty
|
|
503
|
+
*/
|
|
475
504
|
function maxBy(arr, getter) {
|
|
476
505
|
return max(arr.map(getter));
|
|
477
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* Finds the element with the maximum numeric value extracted using a getter function.
|
|
509
|
+
* @param arr - The array of elements to search
|
|
510
|
+
* @param getter - Function to extract a numeric value from each element
|
|
511
|
+
* @returns The element with the maximum value, or null if the array is empty
|
|
512
|
+
*/
|
|
513
|
+
function havingMaxBy(arr, getter) {
|
|
514
|
+
if (arr.length === 0)
|
|
515
|
+
return null;
|
|
516
|
+
return arr.reduce((ret, cur) => {
|
|
517
|
+
const curValue = getter(cur);
|
|
518
|
+
if (curValue > ret.max) {
|
|
519
|
+
return { value: cur, max: curValue };
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
return ret;
|
|
523
|
+
}
|
|
524
|
+
}, { value: null, max: -Infinity }).value;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Finds the element with the minimum numeric value extracted using a getter function.
|
|
528
|
+
* @param arr - The array of elements to search
|
|
529
|
+
* @param getter - Function to extract a numeric value from each element
|
|
530
|
+
* @returns The element with the minimum value, or null if the array is empty
|
|
531
|
+
*/
|
|
532
|
+
function havingMinBy(arr, getter) {
|
|
533
|
+
if (arr.length === 0)
|
|
534
|
+
return null;
|
|
535
|
+
return arr.reduce((ret, cur) => {
|
|
536
|
+
const curValue = getter(cur);
|
|
537
|
+
if (curValue < ret.min) {
|
|
538
|
+
return { value: cur, min: curValue };
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
return ret;
|
|
542
|
+
}
|
|
543
|
+
}, { value: null, min: +Infinity }).value;
|
|
544
|
+
}
|
|
478
545
|
|
|
479
546
|
function constant(v) { return () => v; }
|
|
480
547
|
function identity(t) { return t; }
|
|
@@ -745,12 +812,13 @@ function shallowArrayEquals(a, b) {
|
|
|
745
812
|
}
|
|
746
813
|
return true;
|
|
747
814
|
}
|
|
815
|
+
/** @deprecated[2026.03.01]: Use {@link Optional.findInArray} instead. */
|
|
748
816
|
function findInArray(arr, predicate) {
|
|
749
|
-
return Optional.
|
|
817
|
+
return Optional.findInArray(arr, predicate);
|
|
750
818
|
}
|
|
819
|
+
/** @deprecated[2026.03.01]: Use {@link Optional.findIndexInArray} instead. */
|
|
751
820
|
function findIndexInArray(arr, predicate) {
|
|
752
|
-
|
|
753
|
-
return idx === -1 ? Optional.empty() : Optional.of(idx);
|
|
821
|
+
return Optional.findIndexInArray(arr, predicate);
|
|
754
822
|
}
|
|
755
823
|
function zip(ts, rs) {
|
|
756
824
|
if (ts.length !== rs.length)
|
|
@@ -1072,11 +1140,38 @@ async function awaitAtMost(promise, duration) {
|
|
|
1072
1140
|
}
|
|
1073
1141
|
const NEVER = new Promise(_resolve => { });
|
|
1074
1142
|
|
|
1143
|
+
/**
|
|
1144
|
+
* Returns a random integer in the range [min, max].
|
|
1145
|
+
* @deprecated Use randomIntegerInInterval or randomDecimalInInterval instead
|
|
1146
|
+
*/
|
|
1075
1147
|
function randomNumberInInterval(min, max) {
|
|
1076
1148
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
1077
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
|
+
}
|
|
1078
1168
|
const randomId = (length) => {
|
|
1079
|
-
|
|
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;
|
|
1080
1175
|
};
|
|
1081
1176
|
function randomPick(arr) {
|
|
1082
1177
|
return first$1(randomPicks(arr, 1));
|
|
@@ -1085,7 +1180,7 @@ function randomPicks(arr, count) {
|
|
|
1085
1180
|
const available = [...arr];
|
|
1086
1181
|
const result = [];
|
|
1087
1182
|
while (available.length > 0 && count > 0) {
|
|
1088
|
-
const randomIndex =
|
|
1183
|
+
const randomIndex = randomIntegerInInterval(0, available.length - 1);
|
|
1089
1184
|
result.push(available[randomIndex]);
|
|
1090
1185
|
available.splice(randomIndex, 1);
|
|
1091
1186
|
count--;
|
|
@@ -3390,7 +3485,7 @@ const Sorter = {
|
|
|
3390
3485
|
|
|
3391
3486
|
function randomize(unit) {
|
|
3392
3487
|
return (a, b) => {
|
|
3393
|
-
return TimeDuration.fromMs(
|
|
3488
|
+
return TimeDuration.fromMs(randomIntegerInInterval(unit.toMs(a), unit.toMs(b)));
|
|
3394
3489
|
};
|
|
3395
3490
|
}
|
|
3396
3491
|
class RandomTimeDuration {
|
|
@@ -3573,5 +3668,5 @@ function isUpgradable(obj) {
|
|
|
3573
3668
|
return isDefined(obj) && typeof obj === "object" && VERSION_FIELD in obj && isNumber(obj.$version) && isPositiveNumber(obj.$version);
|
|
3574
3669
|
}
|
|
3575
3670
|
|
|
3576
|
-
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, 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 };
|
|
3671
|
+
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 };
|
|
3577
3672
|
//# sourceMappingURL=index.mjs.map
|