@zelgadis87/utils-core 4.4.4 → 4.6.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.
- package/esbuild/index.cjs +207 -270
- package/esbuild/{index.mjs → index.js} +197 -282
- package/esbuild/package.json +39 -0
- package/package.json +14 -102
- package/src/async/Semaphore.ts +8 -6
- package/src/time/TimeDuration.ts +22 -11
- package/src/time/TimeInstant.ts +38 -21
- package/src/utils/arrays/groupBy.ts +11 -11
- package/src/utils/arrays.ts +9 -3
- package/src/utils/functions/constant.ts +2 -0
- package/src/utils/functions.ts +23 -0
- package/src/utils/random.ts +9 -3
- package/src/utils/records.ts +12 -0
- package/dist/Logger.d.ts +0 -21
- package/dist/Optional.d.ts +0 -70
- package/dist/async/CancelableDeferred.d.ts +0 -17
- package/dist/async/Deferred.d.ts +0 -34
- package/dist/async/RateThrottler.d.ts +0 -13
- package/dist/async/Semaphore.d.ts +0 -14
- package/dist/async/index.d.ts +0 -4
- package/dist/index.d.ts +0 -8
- package/dist/lazy/Lazy.d.ts +0 -22
- package/dist/lazy/LazyAsync.d.ts +0 -24
- package/dist/lazy/index.d.ts +0 -2
- package/dist/sorting/ComparisonChain.d.ts +0 -57
- package/dist/sorting/Sorter.d.ts +0 -100
- package/dist/sorting/index.d.ts +0 -4
- package/dist/sorting/types.d.ts +0 -5
- package/dist/time/RandomTimeDuration.d.ts +0 -9
- package/dist/time/TimeBase.d.ts +0 -38
- package/dist/time/TimeDuration.d.ts +0 -79
- package/dist/time/TimeFrequency.d.ts +0 -10
- package/dist/time/TimeInstant.d.ts +0 -171
- package/dist/time/TimeInstantBuilder.d.ts +0 -77
- package/dist/time/TimeRange.d.ts +0 -11
- package/dist/time/TimeUnit.d.ts +0 -17
- package/dist/time/index.d.ts +0 -7
- package/dist/time/types.d.ts +0 -26
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/upgrade/DataUpgrader.d.ts +0 -22
- package/dist/upgrade/errors.d.ts +0 -12
- package/dist/upgrade/getTransitionsPath.d.ts +0 -3
- package/dist/upgrade/index.d.ts +0 -2
- package/dist/upgrade/types.d.ts +0 -31
- package/dist/utils/arrays/groupBy.d.ts +0 -9
- package/dist/utils/arrays/indexBy.d.ts +0 -7
- package/dist/utils/arrays/statistics.d.ts +0 -8
- package/dist/utils/arrays/uniqBy.d.ts +0 -4
- package/dist/utils/arrays.d.ts +0 -56
- package/dist/utils/booleans.d.ts +0 -2
- package/dist/utils/empties.d.ts +0 -17
- package/dist/utils/errors/withTryCatch.d.ts +0 -3
- package/dist/utils/errors.d.ts +0 -3
- package/dist/utils/functions/constant.d.ts +0 -8
- package/dist/utils/functions/iff.d.ts +0 -8
- package/dist/utils/functions.d.ts +0 -27
- package/dist/utils/index.d.ts +0 -13
- package/dist/utils/json.d.ts +0 -11
- package/dist/utils/nulls.d.ts +0 -8
- package/dist/utils/numbers/round.d.ts +0 -8
- package/dist/utils/numbers.d.ts +0 -34
- package/dist/utils/primitives.d.ts +0 -3
- package/dist/utils/promises.d.ts +0 -6
- package/dist/utils/random.d.ts +0 -2
- package/dist/utils/records/entries.d.ts +0 -4
- package/dist/utils/records.d.ts +0 -21
- package/dist/utils/strings/StringParts.d.ts +0 -32
- package/dist/utils/strings.d.ts +0 -17
package/dist/async/Deferred.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export interface ICancelable {
|
|
2
|
-
cancel(): void;
|
|
3
|
-
}
|
|
4
|
-
export interface ICancelablePromise<T> extends Promise<T>, ICancelable {
|
|
5
|
-
}
|
|
6
|
-
export declare class DeferredCanceledError extends Error {
|
|
7
|
-
constructor();
|
|
8
|
-
}
|
|
9
|
-
export declare class Deferred<T = void> implements ICancelablePromise<T> {
|
|
10
|
-
private _pending;
|
|
11
|
-
private readonly _internals;
|
|
12
|
-
get pending(): boolean;
|
|
13
|
-
/** @deprecated: Use resolve, then and catch directly; use asPromise to return a promise type. */
|
|
14
|
-
get promise(): Promise<T>;
|
|
15
|
-
constructor();
|
|
16
|
-
resolve(val: T): void;
|
|
17
|
-
reject(reason: Error): void;
|
|
18
|
-
cancel(): void;
|
|
19
|
-
resolveIfPending(val: T): void;
|
|
20
|
-
rejectIfPending(reason: Error): void;
|
|
21
|
-
cancelIfPending(): void;
|
|
22
|
-
then<R = T, S = T>(onFulfilled: ((value: T) => R | PromiseLike<R>) | null | undefined, onRejected?: ((reason: Error) => S | PromiseLike<S>) | null | undefined): Promise<R | S>;
|
|
23
|
-
catch<R = T>(onRejected: ((reason: Error) => R | PromiseLike<R>) | null | undefined): Promise<T | R>;
|
|
24
|
-
finally(onfinally: (() => void) | null | undefined): Promise<T>;
|
|
25
|
-
asPromise(): Promise<T>;
|
|
26
|
-
asCancelablePromise(): ICancelablePromise<T>;
|
|
27
|
-
protected createInternals(): {
|
|
28
|
-
promise: Promise<T>;
|
|
29
|
-
resolve: (value: T) => void;
|
|
30
|
-
reject: (reason: Error) => void;
|
|
31
|
-
};
|
|
32
|
-
get [Symbol.toStringTag](): string;
|
|
33
|
-
}
|
|
34
|
-
export default Deferred;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { TFunction, TPromisable } from "..";
|
|
2
|
-
import TimeFrequency from "../time/TimeFrequency";
|
|
3
|
-
type TPromiseFactory<T, R> = TFunction<T, Promise<R>>;
|
|
4
|
-
export declare class RateThrottler {
|
|
5
|
-
private readonly _frequency;
|
|
6
|
-
private readonly _availableSlots;
|
|
7
|
-
private readonly _waitingRequests;
|
|
8
|
-
constructor(_frequency: TimeFrequency);
|
|
9
|
-
get cooldown(): import("..").TimeDuration;
|
|
10
|
-
execute<T>(fn: TPromiseFactory<void, T>): Promise<T>;
|
|
11
|
-
}
|
|
12
|
-
export default RateThrottler;
|
|
13
|
-
export declare function throttle<TParams extends unknown[], R>(fn: (...params: TParams) => TPromisable<R>, frequence: TimeFrequency): (...params: TParams) => Promise<R>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { TAsyncProducer, TProducer, TimeDuration } from "..";
|
|
2
|
-
export declare class Semaphore {
|
|
3
|
-
private _availableSlots;
|
|
4
|
-
private readonly _queuedRequests;
|
|
5
|
-
private _inProgress;
|
|
6
|
-
constructor(_availableSlots?: number);
|
|
7
|
-
private _awaitSlot;
|
|
8
|
-
private _releaseSlot;
|
|
9
|
-
execute<T>(fn: TAsyncProducer<T> | TProducer<T>, cooldown?: TimeDuration): Promise<T>;
|
|
10
|
-
get availableSlots(): number;
|
|
11
|
-
get queueSize(): number;
|
|
12
|
-
get inProgressSize(): number;
|
|
13
|
-
}
|
|
14
|
-
export default Semaphore;
|
package/dist/async/index.d.ts
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './async/index.js';
|
|
2
|
-
export * from './lazy/index.js';
|
|
3
|
-
export * from './Logger.js';
|
|
4
|
-
export * from './Optional.js';
|
|
5
|
-
export * from './sorting/index.js';
|
|
6
|
-
export * from './time/index.js';
|
|
7
|
-
export * from './upgrade/index.js';
|
|
8
|
-
export * from './utils/index.js';
|
package/dist/lazy/Lazy.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Class that stores a value that is computationally/memory intensive to initialize.
|
|
3
|
-
* The initialization of the value is done once and only if required (lazy initialization).
|
|
4
|
-
* @author gtomberli
|
|
5
|
-
*/
|
|
6
|
-
export declare class Lazy<T> {
|
|
7
|
-
private _value;
|
|
8
|
-
private _initialized;
|
|
9
|
-
private _generator;
|
|
10
|
-
private constructor();
|
|
11
|
-
get value(): T | undefined;
|
|
12
|
-
getOrCreate(): T;
|
|
13
|
-
getOrThrow(errorMessage?: "Value not initialized"): T;
|
|
14
|
-
or(t: T): T;
|
|
15
|
-
isPresent(): boolean;
|
|
16
|
-
isEmpty(): boolean;
|
|
17
|
-
ifPresent(fn: (t: T) => void): void;
|
|
18
|
-
ifEmpty(fn: () => void): void;
|
|
19
|
-
apply(fnPresent: (t: T) => void, fnEmpty: () => void): void;
|
|
20
|
-
static of<T>(generator: () => T): Lazy<T>;
|
|
21
|
-
}
|
|
22
|
-
export default Lazy;
|
package/dist/lazy/LazyAsync.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare class LazyAsync<T> {
|
|
2
|
-
private _promise;
|
|
3
|
-
private _pending;
|
|
4
|
-
private _resolvedValue;
|
|
5
|
-
private _error;
|
|
6
|
-
private _generator;
|
|
7
|
-
private constructor();
|
|
8
|
-
getOrCreate(): Promise<T>;
|
|
9
|
-
isPresent(): boolean;
|
|
10
|
-
isEmpty(): boolean;
|
|
11
|
-
isPending(): boolean;
|
|
12
|
-
isReady(): boolean;
|
|
13
|
-
isResolved(): boolean;
|
|
14
|
-
isError(): boolean;
|
|
15
|
-
ifPresent(fn: (t: Promise<T>) => void): void;
|
|
16
|
-
ifEmpty(fn: () => void): void;
|
|
17
|
-
ifPending(fn: (t: Promise<T>) => void): void;
|
|
18
|
-
ifReady(fn: (t: Promise<T>) => void): void;
|
|
19
|
-
ifResolved(fn: (t: T) => void): void;
|
|
20
|
-
ifError(fn: (err: Error) => void): void;
|
|
21
|
-
getOrThrow(errorMessage?: "Value not initialized"): Promise<T> | never;
|
|
22
|
-
static of<T>(generator: () => Promise<T>): LazyAsync<T>;
|
|
23
|
-
}
|
|
24
|
-
export default LazyAsync;
|
package/dist/lazy/index.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { TFunction, TKeysOfType, TReadableArray } from "../utils/index.js";
|
|
2
|
-
import { TComparisonDirection, TComparisonFunction, TComparisonResult } from "./types.js";
|
|
3
|
-
type TCompareValueOptions = {
|
|
4
|
-
nullsFirst: boolean;
|
|
5
|
-
direction: TComparisonDirection;
|
|
6
|
-
};
|
|
7
|
-
type TLooseCompareValueOptions = Partial<TCompareValueOptions> | TComparisonDirection;
|
|
8
|
-
declare function compareStrings(options?: TLooseCompareValueOptions & {
|
|
9
|
-
ignoreCase?: boolean;
|
|
10
|
-
}): TComparisonFunction<string>;
|
|
11
|
-
declare function compareBooleans(options: Partial<TCompareValueOptions> & {
|
|
12
|
-
truesFirst: boolean;
|
|
13
|
-
}): TComparisonFunction<boolean>;
|
|
14
|
-
/**
|
|
15
|
-
* Creates a ComparisonChain V1.
|
|
16
|
-
* Usage: ComparisonChain.createWith<number>( c => c.compareUsingNumbers() ).sort( [ 100, 1, 10, 5 ] );
|
|
17
|
-
* @deprecated[2023-10-22]: Use createSorterFor instead.
|
|
18
|
-
**/
|
|
19
|
-
export declare class ComparisonChain<T> {
|
|
20
|
-
private readonly _fns;
|
|
21
|
-
private readonly _reversed;
|
|
22
|
-
private constructor();
|
|
23
|
-
compare: (a: T, b: T) => TComparisonResult;
|
|
24
|
-
sort: <A extends TReadableArray<T>>(arr: A) => A extends Array<T> ? Array<T> : ReadonlyArray<T>;
|
|
25
|
-
then(getFn: (compare: TChain<T>) => TComparisonFunction<T>): ComparisonChain<T>;
|
|
26
|
-
thenBy(cmp: ComparisonChain<T> | TComparisonFunction<T>): ComparisonChain<T>;
|
|
27
|
-
thenChain<R>(transform: TFunction<T, R>, getFn: (compare: TChain<R>) => TComparisonFunction<R>): ComparisonChain<T>;
|
|
28
|
-
thenChainBy<R>(transform: TFunction<T, R>, cmp: ComparisonChain<R> | TComparisonFunction<R>): ComparisonChain<T>;
|
|
29
|
-
reversed(): ComparisonChain<T>;
|
|
30
|
-
private doCompare;
|
|
31
|
-
static create<T>(): {
|
|
32
|
-
using: (getFn: (chainable: TChain<T>) => TComparisonFunction<T>) => ComparisonChain<T>;
|
|
33
|
-
usingTransformation: <R>(transform: TFunction<T, R>, getFn: (chainable: TChain<R>) => TComparisonFunction<R>) => ComparisonChain<T>;
|
|
34
|
-
};
|
|
35
|
-
static createWith<T>(getFn: (chainable: TChain<T>) => TComparisonFunction<T>): ComparisonChain<T>;
|
|
36
|
-
static createWithTransformation<T, R>(transform: TFunction<T, R>, getFn: (chainable: TChain<R>) => TComparisonFunction<R>): ComparisonChain<T>;
|
|
37
|
-
}
|
|
38
|
-
export default ComparisonChain;
|
|
39
|
-
declare function createCompare<T>(): {
|
|
40
|
-
compareUsingGetter: {
|
|
41
|
-
(getter: TFunction<T, string>, options?: TLooseCompareValueOptions): TComparisonFunction<T>;
|
|
42
|
-
(getter: TFunction<T, number>, options?: TLooseCompareValueOptions): TComparisonFunction<T>;
|
|
43
|
-
(getter: TFunction<T, Date>, options?: TLooseCompareValueOptions): TComparisonFunction<T>;
|
|
44
|
-
};
|
|
45
|
-
compareUsingField: (field: keyof T & TKeysOfType<T, string | number | Date>, options?: TLooseCompareValueOptions) => TComparisonFunction<T>;
|
|
46
|
-
compareUsingStrings: typeof compareStrings;
|
|
47
|
-
compareUsingStringsIgnoringCase: (options?: TLooseCompareValueOptions) => TComparisonFunction<string>;
|
|
48
|
-
compareUsingBooleans: typeof compareBooleans;
|
|
49
|
-
compareUsingNumbers: (options?: TLooseCompareValueOptions) => TComparisonFunction<number>;
|
|
50
|
-
compareUsingDates: (options?: TLooseCompareValueOptions) => TComparisonFunction<Date>;
|
|
51
|
-
compareUsingFunction: (fn: TComparisonFunction<T>) => TComparisonFunction<T>;
|
|
52
|
-
placeFirst: (arr: Array<T>) => TComparisonFunction<T>;
|
|
53
|
-
placeFirstInOrder: (arr: Array<T>) => TComparisonFunction<T>;
|
|
54
|
-
placeLast: (arr: Array<T>) => TComparisonFunction<T>;
|
|
55
|
-
placeLastInOrder: (arr: Array<T>) => TComparisonFunction<T>;
|
|
56
|
-
};
|
|
57
|
-
type TChain<T> = ReturnType<typeof createCompare<T>>;
|
package/dist/sorting/Sorter.d.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { TConditionalParameterOptions, TFunction, TKeysOfType, TPositiveNumber, TReadableArray } from "../utils/index.js";
|
|
2
|
-
import { TComparisonFunction } from "./types.js";
|
|
3
|
-
type TComparable<T> = {
|
|
4
|
-
compare: TComparisonFunction<T>;
|
|
5
|
-
};
|
|
6
|
-
export type TSorter<T> = {
|
|
7
|
-
get then(): TSorterStep<T, TSorter<T>>;
|
|
8
|
-
reversed: () => TSorter<T>;
|
|
9
|
-
compare: TComparisonFunction<T>;
|
|
10
|
-
sort: (arr: TReadableArray<T>) => Array<T>;
|
|
11
|
-
top: (arr: TReadableArray<T>, n: TPositiveNumber) => Array<T>;
|
|
12
|
-
bottom: (arr: TReadableArray<T>, n: TPositiveNumber) => Array<T>;
|
|
13
|
-
first: (arr: TReadableArray<T>) => T | null;
|
|
14
|
-
last: (arr: TReadableArray<T>) => T | null;
|
|
15
|
-
};
|
|
16
|
-
type TSorterStepForRecords<T, Ret> = {
|
|
17
|
-
usingStrings: (field: TKeysOfType<T, string>) => TSorterStep<string, Ret>;
|
|
18
|
-
usingNumbers: (field: TKeysOfType<T, number>) => TSorterStep<number, Ret>;
|
|
19
|
-
usingBooleans: (field: TKeysOfType<T, boolean>) => TSorterStep<boolean, Ret>;
|
|
20
|
-
usingDates: (field: TKeysOfType<T, Date>) => TSorterStep<Date, Ret>;
|
|
21
|
-
};
|
|
22
|
-
type TSorterStepForNumbers<_T, Ret> = {
|
|
23
|
-
inAscendingOrder(opts?: {
|
|
24
|
-
nullsFirst?: boolean;
|
|
25
|
-
}): Ret;
|
|
26
|
-
inDescendingOrder(opts?: {
|
|
27
|
-
nullsFirst?: boolean;
|
|
28
|
-
}): Ret;
|
|
29
|
-
};
|
|
30
|
-
type TSorterStepForStrings<_T, Ret> = {
|
|
31
|
-
inLexographicalOrder(opts?: {
|
|
32
|
-
nullsFirst?: boolean;
|
|
33
|
-
}): Ret;
|
|
34
|
-
inLexographicalOrderIgnoringCase(opts?: {
|
|
35
|
-
nullsFirst?: boolean;
|
|
36
|
-
}): Ret;
|
|
37
|
-
inReverseLexographicalOrder(opts?: {
|
|
38
|
-
nullsFirst?: boolean;
|
|
39
|
-
}): Ret;
|
|
40
|
-
inReverseLexographicalOrderIgnoringCase(opts?: {
|
|
41
|
-
nullsFirst?: boolean;
|
|
42
|
-
}): Ret;
|
|
43
|
-
};
|
|
44
|
-
type TSorterStepForBooleans<_T, Ret> = {
|
|
45
|
-
truesFirst(opts?: {
|
|
46
|
-
nullsFirst?: boolean;
|
|
47
|
-
}): Ret;
|
|
48
|
-
falsesFirst(opts?: {
|
|
49
|
-
nullsFirst?: boolean;
|
|
50
|
-
}): Ret;
|
|
51
|
-
};
|
|
52
|
-
type TSorterStepForDates<_T, Ret> = {
|
|
53
|
-
mostAncientFirst(opts?: {
|
|
54
|
-
nullsFirst?: boolean;
|
|
55
|
-
}): Ret;
|
|
56
|
-
mostRecentFirst(opts?: {
|
|
57
|
-
nullsFirst?: boolean;
|
|
58
|
-
}): Ret;
|
|
59
|
-
};
|
|
60
|
-
type TSorterStepForChainables<T, Ret> = {
|
|
61
|
-
chain: (chain: TComparable<T>) => Ret;
|
|
62
|
-
};
|
|
63
|
-
type TSorterStepForUsing<T, Ret> = {
|
|
64
|
-
using: <X>(transform: TFunction<T, X>) => TSorterStep<X, Ret>;
|
|
65
|
-
};
|
|
66
|
-
type TSorterStepForPrioritizable<T extends string | number, Ret> = {
|
|
67
|
-
prioritizing(arr: T[], options?: TConditionalParameterOptions<TPrioritizeOptions, typeof defaultPrioritizeOptions>): Ret;
|
|
68
|
-
deprioritizing(arr: Array<T>, options?: TConditionalParameterOptions<TPrioritizeOptions, typeof defaultPrioritizeOptions>): Ret;
|
|
69
|
-
prioritizingWithEqualWeight(arr: T[], options?: TConditionalParameterOptions<TPrioritizeOptions, typeof defaultPrioritizeOptions>): Ret;
|
|
70
|
-
deprioritizingWithEqualWeight(arr: Array<T>, options?: TConditionalParameterOptions<TPrioritizeOptions, typeof defaultPrioritizeOptions>): Ret;
|
|
71
|
-
};
|
|
72
|
-
type TSorterStep<T, Ret> = {} & (T extends Record<string | number | symbol, unknown> ? TSorterStepForRecords<T, Ret> : {}) & (T extends number ? TSorterStepForNumbers<T, Ret> : {}) & (T extends string ? TSorterStepForStrings<T, Ret> : {}) & (T extends boolean ? TSorterStepForBooleans<T, Ret> : {}) & (T extends Date ? TSorterStepForDates<T, Ret> : {}) & (T extends string ? TSorterStepForPrioritizable<string, Ret> : {}) & (T extends number ? TSorterStepForPrioritizable<number, Ret> : {}) & TSorterStepForChainables<T, Ret> & TSorterStepForUsing<T, Ret>;
|
|
73
|
-
type TSorterStarter<T> = TSorterStep<T, TSorter<T>>;
|
|
74
|
-
export type TSorterBuilder<T> = (builder: TSorterStarter<T>) => TSorter<T>;
|
|
75
|
-
type TPrioritizeOptions = {};
|
|
76
|
-
declare const defaultPrioritizeOptions: {};
|
|
77
|
-
/**
|
|
78
|
-
* @deprecated[2023-10-19]: Use {@link Sorter.createFor} instead.
|
|
79
|
-
**/
|
|
80
|
-
export declare function createSorterFor<T>(): TSorterStarter<T>;
|
|
81
|
-
export declare const Sorter: {
|
|
82
|
-
createFor: <T>() => TSorterStarter<T>;
|
|
83
|
-
sort: <T>(arr: TReadableArray<T>, builder: TSorterBuilder<T>) => T[];
|
|
84
|
-
top: <T>(arr: TReadableArray<T>, n: TPositiveNumber, builder: TSorterBuilder<T>) => T[];
|
|
85
|
-
bottom: <T>(arr: TReadableArray<T>, n: TPositiveNumber, builder: TSorterBuilder<T>) => T[];
|
|
86
|
-
first: <T>(arr: TReadableArray<T>, builder: TSorterBuilder<T>) => T | null;
|
|
87
|
-
last: <T>(arr: TReadableArray<T>, builder: TSorterBuilder<T>) => T | null;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* @deprecated[2023-11-01]: Use {@link Sorter} instead.
|
|
91
|
-
**/
|
|
92
|
-
export declare const Sorting: {
|
|
93
|
-
createFor: <T>() => TSorterStarter<T>;
|
|
94
|
-
sort: <T>(arr: TReadableArray<T>, builder: TSorterBuilder<T>) => T[];
|
|
95
|
-
top: <T>(arr: TReadableArray<T>, n: TPositiveNumber, builder: TSorterBuilder<T>) => T[];
|
|
96
|
-
bottom: <T>(arr: TReadableArray<T>, n: TPositiveNumber, builder: TSorterBuilder<T>) => T[];
|
|
97
|
-
first: <T>(arr: TReadableArray<T>, builder: TSorterBuilder<T>) => T | null;
|
|
98
|
-
last: <T>(arr: TReadableArray<T>, builder: TSorterBuilder<T>) => T | null;
|
|
99
|
-
};
|
|
100
|
-
export default Sorter;
|
package/dist/sorting/index.d.ts
DELETED
package/dist/sorting/types.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { TBiFunction } from "../utils/functions.js";
|
|
2
|
-
export type TComparisonResult = -1 | 0 | 1;
|
|
3
|
-
export type TStrictComparisonResult = -1 | 1;
|
|
4
|
-
export type TComparisonFunction<T> = TBiFunction<T, T, TComparisonResult>;
|
|
5
|
-
export type TComparisonDirection = 'ASC' | 'DESC';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import TimeDuration from "./TimeDuration.js";
|
|
2
|
-
export default class RandomTimeDuration {
|
|
3
|
-
private constructor();
|
|
4
|
-
static ms: (a: number, b: number) => TimeDuration;
|
|
5
|
-
static seconds: (a: number, b: number) => TimeDuration;
|
|
6
|
-
static minutes: (a: number, b: number) => TimeDuration;
|
|
7
|
-
static hours: (a: number, b: number) => TimeDuration;
|
|
8
|
-
static days: (a: number, b: number) => TimeDuration;
|
|
9
|
-
}
|
package/dist/time/TimeBase.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import TimeUnit from "./TimeUnit";
|
|
2
|
-
export default abstract class TimeBase<T> {
|
|
3
|
-
private readonly _ms;
|
|
4
|
-
protected constructor(value: number, unit: TimeUnit);
|
|
5
|
-
protected abstract create(value: number, unit: TimeUnit): T;
|
|
6
|
-
get ms(): number;
|
|
7
|
-
get seconds(): number;
|
|
8
|
-
get minutes(): number;
|
|
9
|
-
get hours(): number;
|
|
10
|
-
get days(): number;
|
|
11
|
-
addMs(milliseconds: number): T;
|
|
12
|
-
addSeconds(seconds: number): T;
|
|
13
|
-
addMinutes(minutes: number): T;
|
|
14
|
-
addHours(hours: number): T;
|
|
15
|
-
addDays(days: number): T;
|
|
16
|
-
removeDays(days: number): T;
|
|
17
|
-
addUnits(n: number, unit: TimeUnit): T;
|
|
18
|
-
removeMs(milliseconds: number): T;
|
|
19
|
-
removeSeconds(seconds: number): T;
|
|
20
|
-
removeMinutes(minutes: number): T;
|
|
21
|
-
removeHours(hours: number): T;
|
|
22
|
-
removeUnits(n: number, unit: TimeUnit): T;
|
|
23
|
-
getUnit(unit: TimeUnit): number;
|
|
24
|
-
protected toUnits(): {
|
|
25
|
-
days: number;
|
|
26
|
-
hours: number;
|
|
27
|
-
minutes: number;
|
|
28
|
-
seconds: number;
|
|
29
|
-
};
|
|
30
|
-
protected static toMs(units: {
|
|
31
|
-
days?: number;
|
|
32
|
-
hours?: number;
|
|
33
|
-
minutes?: number;
|
|
34
|
-
seconds?: number;
|
|
35
|
-
ms?: number;
|
|
36
|
-
}): number;
|
|
37
|
-
toJSON(): number;
|
|
38
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { ICancelable, ICancelablePromise } from "../async/Deferred.js";
|
|
2
|
-
import { TComparisonResult } from "../sorting/index.js";
|
|
3
|
-
import { TIntervalHandle, TTimeoutHandle } from "../utils/index.js";
|
|
4
|
-
import TimeBase from "./TimeBase";
|
|
5
|
-
import TimeInstant from "./TimeInstant";
|
|
6
|
-
import TimeUnit from "./TimeUnit";
|
|
7
|
-
export declare class TimeDuration extends TimeBase<TimeDuration> {
|
|
8
|
-
protected constructor(value: number, unit: TimeUnit);
|
|
9
|
-
protected create(value: number, unit: TimeUnit): TimeDuration;
|
|
10
|
-
addDuration(duration: TimeDuration): TimeDuration;
|
|
11
|
-
removeDuration(duration: TimeDuration): TimeDuration;
|
|
12
|
-
removeUnits(n: number, unit: TimeUnit): TimeDuration;
|
|
13
|
-
/** @deprecated: Use multiplyBy instead **/
|
|
14
|
-
multiply(times: number): TimeDuration;
|
|
15
|
-
multiplyBy(times: number): TimeDuration;
|
|
16
|
-
divideBy(times: number): TimeDuration;
|
|
17
|
-
/**
|
|
18
|
-
* Returns the current duration in a human readable format, prioritizing the most significant unit of time and excluding the rest.
|
|
19
|
-
* @todo[2023-06] Should allow more customization options
|
|
20
|
-
* @todo[2023-06] By default should show the secondary unit only when actually needed (eg, 1h 20m & 3h, instead of 1h 20m & 3h 28m)
|
|
21
|
-
* @todo[2023-06] Should not allow negative durations, as this is a duration and not an instant.
|
|
22
|
-
* @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
|
|
23
|
-
*/
|
|
24
|
-
get formatted(): string;
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated[2023-06] this method makes no sense, as durations are positive by default.
|
|
27
|
-
*/
|
|
28
|
-
absolute(): TimeDuration;
|
|
29
|
-
interval(cb: () => unknown): TIntervalHandle;
|
|
30
|
-
timeout(cb: () => unknown): TTimeoutHandle;
|
|
31
|
-
promise(): ICancelablePromise<void>;
|
|
32
|
-
delay(cb: () => unknown): ICancelable;
|
|
33
|
-
debounce<T>(fn: (t: T) => void): (t: T) => void;
|
|
34
|
-
toDigitalClock(): string;
|
|
35
|
-
get asSeconds(): string;
|
|
36
|
-
fromNow(): TimeInstant;
|
|
37
|
-
differenceFrom(other: TimeDuration): TimeDuration;
|
|
38
|
-
/** @deprecated: Use fromNow instead **/
|
|
39
|
-
addCurrentTime(): TimeInstant;
|
|
40
|
-
isGreaterThan(other: TimeDuration): boolean;
|
|
41
|
-
isLessThan(other: TimeDuration): boolean;
|
|
42
|
-
compareTo(other: TimeDuration): TComparisonResult;
|
|
43
|
-
atLeast(other: TimeDuration): TimeDuration;
|
|
44
|
-
atMost(other: TimeDuration): TimeDuration;
|
|
45
|
-
isEmpty(): boolean;
|
|
46
|
-
isNotEmpty(): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* This method is used to provide a better DX when inspecting a TimeInstant object in DevTools.
|
|
49
|
-
*/
|
|
50
|
-
protected get _duration(): string;
|
|
51
|
-
toString(): string;
|
|
52
|
-
static parseHumanTime(humanTime: string): TimeDuration;
|
|
53
|
-
static compare(a: TimeDuration, b: TimeDuration): TComparisonResult;
|
|
54
|
-
static ms: IDurationConstructor;
|
|
55
|
-
static seconds: IDurationConstructor;
|
|
56
|
-
static minutes: IDurationConstructor;
|
|
57
|
-
static hours: IDurationConstructor;
|
|
58
|
-
static days: IDurationConstructor;
|
|
59
|
-
static shamefulUnref: (ms: TAllowedTimeDuration) => number;
|
|
60
|
-
static shamefulRef: (ms: TAllowedTimeDuration) => TimeDuration;
|
|
61
|
-
static unref: (ms: TValidTimeDuration) => TPredefinedTimeDuration;
|
|
62
|
-
static ref: (ms: TValidTimeDuration) => TimeDuration;
|
|
63
|
-
static fromMs(ms: number): TimeDuration;
|
|
64
|
-
static distanceFromNow(instant: TimeInstant): TimeDuration;
|
|
65
|
-
static distance(instant1: TimeInstant, instant2: TimeInstant): TimeDuration;
|
|
66
|
-
static greatest(duration1: TimeDuration, duration2: TimeDuration): TimeDuration;
|
|
67
|
-
static lowest(duration1: TimeDuration, duration2: TimeDuration): TimeDuration;
|
|
68
|
-
static ZERO: TimeDuration;
|
|
69
|
-
static fromJSON(ms: number): TimeDuration;
|
|
70
|
-
}
|
|
71
|
-
interface IDurationConstructor {
|
|
72
|
-
(a: number): TimeDuration;
|
|
73
|
-
/** @deprecated[2023-06] Use RandomTimeDuration instead */ (a: number, b?: number): TimeDuration;
|
|
74
|
-
}
|
|
75
|
-
export type TPredefinedTimeDuration = 0 | 50 | 100 | 150 | 200 | 250 | 300 | 500 | 1000 | 1500 | 2000 | 2500 | 5000;
|
|
76
|
-
export type TValidTimeDuration = TimeDuration | TPredefinedTimeDuration;
|
|
77
|
-
type TAllowedTimeDuration = TValidTimeDuration | number;
|
|
78
|
-
export declare function isAllowedTimeDuration(t: unknown): t is TAllowedTimeDuration;
|
|
79
|
-
export default TimeDuration;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TPositiveNumber } from "../utils";
|
|
2
|
-
import TimeDuration from "./TimeDuration";
|
|
3
|
-
export default class TimeFrequency {
|
|
4
|
-
readonly times: TPositiveNumber;
|
|
5
|
-
readonly period: TimeDuration;
|
|
6
|
-
constructor(times: TPositiveNumber, period: TimeDuration);
|
|
7
|
-
get frequency(): TimeDuration;
|
|
8
|
-
static onceEvery(period: TimeDuration): TimeFrequency;
|
|
9
|
-
static twiceEvery(period: TimeDuration): TimeFrequency;
|
|
10
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { ICancelable, ICancelablePromise } from "../async/Deferred.js";
|
|
2
|
-
import { TComparisonResult } from "../sorting/index.js";
|
|
3
|
-
import TimeBase from "./TimeBase";
|
|
4
|
-
import TimeDuration from "./TimeDuration";
|
|
5
|
-
import { TTimeInstantBuilder, TTimeInstantCreationParameters } from "./TimeInstantBuilder.js";
|
|
6
|
-
import TimeUnit from "./TimeUnit";
|
|
7
|
-
import { TDayOfMonth, TDayOfWeek, TIso8601DateString, TIso8601DateUtcString, TMonth, TWeekNumber } from "./types";
|
|
8
|
-
export declare class TimeInstant extends TimeBase<TimeInstant> {
|
|
9
|
-
protected constructor(number: number, unit: TimeUnit);
|
|
10
|
-
protected create(value: number, unit: TimeUnit): TimeInstant;
|
|
11
|
-
addDuration(duration: TimeDuration): TimeInstant;
|
|
12
|
-
removeDuration(duration: TimeDuration): TimeInstant;
|
|
13
|
-
distanceFrom(instant: TimeInstant): TimeDuration;
|
|
14
|
-
distanceFromNow(): TimeDuration;
|
|
15
|
-
distanceFromStartOfDay(): TimeDuration;
|
|
16
|
-
atStartOfDay(): TimeInstant;
|
|
17
|
-
distanceFromEndOfDay(): TimeDuration;
|
|
18
|
-
atEndOfDay(): TimeInstant;
|
|
19
|
-
promise(): ICancelablePromise<void>;
|
|
20
|
-
delay(cb: () => unknown): ICancelable;
|
|
21
|
-
ensureInTheFuture(): void;
|
|
22
|
-
ensureInThePast(): void;
|
|
23
|
-
isToday(): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* @returns the time as HH:mm:ss
|
|
26
|
-
* @deprecated [2024-12-11] this method is too ambigous and should be removed.
|
|
27
|
-
*/
|
|
28
|
-
asTimeString(): string;
|
|
29
|
-
/**
|
|
30
|
-
* @returns the date as dd/MM/yyyy
|
|
31
|
-
* @deprecated [2024-12-11] this method is too ambigous and should be removed.
|
|
32
|
-
*/
|
|
33
|
-
asDateString(): string;
|
|
34
|
-
/**
|
|
35
|
-
* Formats this instant using the given pattern. The pattern can contain the following tokens:
|
|
36
|
-
*
|
|
37
|
-
* | Token | Description | Example |
|
|
38
|
-
* |:------|:--------------------------------|:------------------------------|
|
|
39
|
-
* | D | Weekday, 1 letter | W |
|
|
40
|
-
* | DD | Weekday, 3 letters | Wed |
|
|
41
|
-
* | DDD | Weekday, long | Wednesday |
|
|
42
|
-
* | d | Day of the month, no padding | 3 |
|
|
43
|
-
* | dd | Day of the month, padded to 2 | 03 |
|
|
44
|
-
* | M | Month, numeric | 3 |
|
|
45
|
-
* | MM | Month, 2 digits | 03 |
|
|
46
|
-
* | MMM | Month, 3 letters | Mar |
|
|
47
|
-
* | MMMM | Month, long | March |
|
|
48
|
-
* | y | Year, numeric | 2021 |
|
|
49
|
-
* | yy | Year, 2 digits | 21 |
|
|
50
|
-
* | yyyy | Year, numeric | 2021 |
|
|
51
|
-
* | h | Hours, no padding | 6 |
|
|
52
|
-
* | hh | Hours, padded to 2 | 06 |
|
|
53
|
-
* | H | Hours in 24-format, no padding | 18 |
|
|
54
|
-
* | HH | Hours in 24-format, padded to 2 | 18 |
|
|
55
|
-
* | m | Minutes, no padding | 7 |
|
|
56
|
-
* | m | Minutes, padded to 2 | 07 |
|
|
57
|
-
* | s | Seconds, no padding | 8 |
|
|
58
|
-
* | ss | Seconds, padded to 2 | 08 |
|
|
59
|
-
* | S | Milliseconds, no padding | 9 |
|
|
60
|
-
* | SS | Milliseconds, padded to 2 | 09 |
|
|
61
|
-
* | SSS | Milliseconds, padded to 3 | 009 |
|
|
62
|
-
* | G | Era, narrow | A |
|
|
63
|
-
* | GG | Era, short | AD |
|
|
64
|
-
* | GGG | Era, long | Anno Domino |
|
|
65
|
-
* | Z | Time zone, short | GMT+1 |
|
|
66
|
-
* | ZZ | Time short, long C | entral European Standard Time |
|
|
67
|
-
* | P | Period of the day, narrow | in the morning |
|
|
68
|
-
* | PP | Period of the day, short | in the morning |
|
|
69
|
-
* | PPP | Period of the day, long | in the morning |
|
|
70
|
-
* | a | Meridiem | pm |
|
|
71
|
-
* @param pattern The pattern to use. Refer to the token table above for details.
|
|
72
|
-
* @param config An optional locale and timeZone definition to use during the format.
|
|
73
|
-
* @returns a string, formatted using the given pattern, at the given timeZone with the given locale.
|
|
74
|
-
*/
|
|
75
|
-
format(pattern: string, config?: {
|
|
76
|
-
locale?: string;
|
|
77
|
-
timeZone?: string;
|
|
78
|
-
}): string;
|
|
79
|
-
/**
|
|
80
|
-
* @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024Z). The format is meant to always be realiable.
|
|
81
|
-
*/
|
|
82
|
-
asIso8601(): TIso8601DateUtcString;
|
|
83
|
-
/**
|
|
84
|
-
* @returns this instant, in a human readable format. The format COULD change in the future, do NOT use this method for consistent outputs.
|
|
85
|
-
* @deprecated [2024-12-11] this method is too broad and ambigous and should be removed.
|
|
86
|
-
*/
|
|
87
|
-
asHumanTimestamp(): string;
|
|
88
|
-
toUnixTimestamp(): number;
|
|
89
|
-
toDate(): Date;
|
|
90
|
-
toDateUTC(): Date;
|
|
91
|
-
get isInThePast(): boolean;
|
|
92
|
-
get isInTheFuture(): boolean;
|
|
93
|
-
isAfter(other: TimeInstant): boolean;
|
|
94
|
-
isBefore(other: TimeInstant): boolean;
|
|
95
|
-
compareTo(other: TimeInstant): TComparisonResult;
|
|
96
|
-
/**
|
|
97
|
-
* @deprecated[04/07/2023]: Use distanceFromNow instead
|
|
98
|
-
*/
|
|
99
|
-
fromNow(): TimeDuration;
|
|
100
|
-
/**
|
|
101
|
-
* @deprecated[04/07/2023]: Use distanceFrom instead
|
|
102
|
-
*/
|
|
103
|
-
from(instant: TimeInstant): TimeDuration;
|
|
104
|
-
/**
|
|
105
|
-
* @deprecated[04/07/2023]: Use distanceFromUnixTimestamp instead
|
|
106
|
-
*/
|
|
107
|
-
fromTimestamp(timestamp: number): TimeDuration;
|
|
108
|
-
distanceFromUnixTimestamp(timestamp: number): TimeDuration;
|
|
109
|
-
atTime(parameters: Partial<TTimeInstantCreationParameters & {
|
|
110
|
-
year: never;
|
|
111
|
-
month: never;
|
|
112
|
-
date: never;
|
|
113
|
-
}>): TimeInstant;
|
|
114
|
-
atDate(parameters: Partial<TTimeInstantCreationParameters & {
|
|
115
|
-
hours: never;
|
|
116
|
-
minutes: never;
|
|
117
|
-
seconds: never;
|
|
118
|
-
milliseconds: never;
|
|
119
|
-
}>): TimeInstant;
|
|
120
|
-
at(parameters: Partial<TTimeInstantCreationParameters>): TimeInstant;
|
|
121
|
-
isBetween(start: TimeInstant, end: TimeInstant): boolean;
|
|
122
|
-
static fromDate(date: Date): TimeInstant;
|
|
123
|
-
static fromUnixTimestamp(unixTimestamp: number): TimeInstant;
|
|
124
|
-
static fromUnixSeconds(unixSeconds: number): TimeInstant;
|
|
125
|
-
static fromParameters(parameters: Partial<TTimeInstantCreationParameters>, referenceDate?: Date | TimeInstant): TimeInstant;
|
|
126
|
-
static highest(instant1: TimeInstant, instant2: TimeInstant): TimeInstant;
|
|
127
|
-
static lowest(instant1: TimeInstant, instant2: TimeInstant): TimeInstant;
|
|
128
|
-
static builder(): TTimeInstantBuilder;
|
|
129
|
-
/**
|
|
130
|
-
* @deprecated[19/07/2023] Use {@link fromParameters} instead.
|
|
131
|
-
*/
|
|
132
|
-
static fromUnits({ date, month, year, hours, minutes, seconds }: {
|
|
133
|
-
date: number;
|
|
134
|
-
month: number;
|
|
135
|
-
year: number;
|
|
136
|
-
hours?: number;
|
|
137
|
-
minutes?: number;
|
|
138
|
-
seconds?: number;
|
|
139
|
-
}): TimeInstant;
|
|
140
|
-
static fromIso8601(str: TIso8601DateString): TimeInstant;
|
|
141
|
-
static tryFromIso8601(str: string): TimeInstant;
|
|
142
|
-
static now(): TimeInstant;
|
|
143
|
-
static get currentTimeStamp(): number;
|
|
144
|
-
static compare(a: TimeInstant, b: TimeInstant): TComparisonResult;
|
|
145
|
-
roundedToStartOf(unit: TimeUnit): TimeInstant;
|
|
146
|
-
roundedToEndOf(unit: TimeUnit): TimeInstant;
|
|
147
|
-
roundedToNext(unit: TimeUnit, factor?: number): TimeInstant;
|
|
148
|
-
roundedToPrevious(unit: TimeUnit, factor?: number): TimeInstant;
|
|
149
|
-
roundedTo(unit: TimeUnit, factor?: number): TimeInstant;
|
|
150
|
-
get dayOfMonth(): TDayOfMonth;
|
|
151
|
-
get dayOfWeek(): TDayOfWeek;
|
|
152
|
-
get month(): TMonth;
|
|
153
|
-
get year(): number;
|
|
154
|
-
/**
|
|
155
|
-
* Returns the week number represented by this instant, according to the ISO 8601 standard.
|
|
156
|
-
* Please note that the instant and the week number could be of two different years, eg the friday 1st january is actually part of week 52 of the previous year.
|
|
157
|
-
*/
|
|
158
|
-
get weekNumber(): {
|
|
159
|
-
weekNumber: TWeekNumber;
|
|
160
|
-
year: number;
|
|
161
|
-
};
|
|
162
|
-
/**
|
|
163
|
-
* This method is used to provide a better DX when inspecting a TimeInstant object in DevTools.
|
|
164
|
-
*/
|
|
165
|
-
protected get _time(): string;
|
|
166
|
-
toString(): string;
|
|
167
|
-
static ZERO: TimeInstant;
|
|
168
|
-
static fromJSON(ms: number): TimeInstant;
|
|
169
|
-
}
|
|
170
|
-
export declare function isTimeInstant(x: unknown): x is TimeInstant;
|
|
171
|
-
export default TimeInstant;
|