@zelgadis87/utils-core 4.9.0 → 4.11.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/dist/async/_index.d.ts +4 -0
- package/dist/index.d.ts +6 -6
- package/dist/lazy/_index.d.ts +2 -0
- package/dist/sorting/ComparisonChain.d.ts +1 -1
- package/dist/sorting/Sorter.d.ts +1 -1
- package/dist/sorting/_index.d.ts +4 -0
- package/dist/time/TimeDuration.d.ts +2 -2
- package/dist/time/TimeFrequency.d.ts +1 -1
- package/dist/time/TimeInstant.d.ts +15 -1
- package/dist/time/TimeRange.d.ts +1 -1
- package/dist/time/_index.d.ts +7 -0
- package/dist/time/types.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/upgrade/DataUpgrader.d.ts +1 -1
- package/dist/upgrade/_index.d.ts +2 -0
- package/dist/upgrade/getTransitionsPath.d.ts +1 -1
- package/dist/upgrade/types.d.ts +1 -1
- package/{src/utils/index.ts → dist/utils/_index.d.ts} +14 -16
- package/dist/utils/arrays/groupBy.d.ts +1 -1
- package/dist/utils/arrays/indexBy.d.ts +1 -1
- package/dist/utils/arrays.d.ts +1 -1
- package/dist/utils/css.d.ts +12 -6
- package/dist/utils/functions/constant.d.ts +1 -0
- package/dist/utils/functions/iff.d.ts +1 -1
- package/dist/utils/functions/pipedInvokeFromArray.d.ts +2 -0
- package/dist/utils/functions.d.ts +11 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/numbers.d.ts +1 -0
- package/dist/utils/promises.d.ts +1 -0
- package/dist/utils/records/entries.d.ts +1 -1
- package/esbuild/index.cjs +60 -6
- package/esbuild/index.cjs.map +2 -2
- package/esbuild/index.mjs +55 -6
- package/esbuild/index.mjs.map +2 -2
- package/package.json +1 -1
- package/src/Logger.ts +1 -1
- package/src/async/_index.ts +7 -0
- package/src/index.ts +6 -6
- package/src/lazy/Lazy.ts +1 -1
- package/src/sorting/ComparisonChain.ts +1 -1
- package/src/sorting/Sorter.ts +1 -1
- package/src/time/TimeDuration.ts +2 -2
- package/src/time/TimeFrequency.ts +1 -1
- package/src/time/TimeInstant.ts +21 -1
- package/src/time/TimeRange.ts +1 -1
- package/src/time/_index.ts +9 -0
- package/src/time/types.ts +1 -1
- package/src/upgrade/DataUpgrader.ts +1 -2
- package/src/upgrade/getTransitionsPath.ts +1 -1
- package/src/upgrade/types.ts +1 -1
- package/src/utils/_index.ts +16 -0
- package/src/utils/arrays/groupBy.ts +1 -1
- package/src/utils/arrays/indexBy.ts +1 -1
- package/src/utils/arrays.ts +1 -1
- package/src/utils/css.ts +21 -12
- package/src/utils/functions/constant.ts +1 -0
- package/src/utils/functions/iff.ts +1 -1
- package/src/utils/functions.ts +25 -0
- package/src/utils/numbers.ts +3 -0
- package/src/utils/promises.ts +2 -1
- package/src/utils/records/entries.ts +1 -1
- package/src/async/index.ts +0 -7
- package/src/time/index.ts +0 -9
- /package/src/lazy/{index.ts → _index.ts} +0 -0
- /package/src/sorting/{index.ts → _index.ts} +0 -0
- /package/src/upgrade/{index.ts → _index.ts} +0 -0
package/package.json
CHANGED
package/src/Logger.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
export * from './async/
|
|
3
|
-
export * from './lazy/
|
|
2
|
+
export * from './async/_index.js';
|
|
3
|
+
export * from './lazy/_index.js';
|
|
4
4
|
export * from './Logger.js';
|
|
5
5
|
export * from './Optional.js';
|
|
6
|
-
export * from './sorting/
|
|
7
|
-
export * from './time/
|
|
8
|
-
export * from './upgrade/
|
|
9
|
-
export * from './utils/
|
|
6
|
+
export * from './sorting/_index.js';
|
|
7
|
+
export * from './time/_index.js';
|
|
8
|
+
export * from './upgrade/_index.js';
|
|
9
|
+
export * from './utils/_index.js';
|
|
10
10
|
|
package/src/lazy/Lazy.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { TFunction, TKeysOfType, TReadableArray, isDefined, isNullOrUndefined } from "../utils/_index.js";
|
|
1
2
|
import { identity } from "../utils/functions/constant.js";
|
|
2
|
-
import { TFunction, TKeysOfType, TReadableArray, isDefined, isNullOrUndefined } from "../utils/index.js";
|
|
3
3
|
import { TComparisonDirection, TComparisonFunction, TComparisonResult } from "./types.js";
|
|
4
4
|
|
|
5
5
|
type TCompareValueOptions = {
|
package/src/sorting/Sorter.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { TBiFunction, TConditionalParameterOptions, TFunction, TKeysOfType, TPositiveNumber, TReadableArray, isDefined, isNullOrUndefined } from "../utils/_index.js";
|
|
1
2
|
import { identity } from "../utils/functions/constant.js";
|
|
2
|
-
import { TBiFunction, TConditionalParameterOptions, TFunction, TKeysOfType, TPositiveNumber, TReadableArray, isDefined, isNullOrUndefined } from "../utils/index.js";
|
|
3
3
|
import { TComparisonDirection, TComparisonFunction, TComparisonResult, TStrictComparisonResult } from "./types.js";
|
|
4
4
|
|
|
5
5
|
type TCompareValuesOptions = {
|
package/src/time/TimeDuration.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Deferred, { DeferredCanceledError, ICancelable, ICancelablePromise } from "../async/Deferred.js";
|
|
2
|
-
import { TComparisonResult } from "../sorting/
|
|
3
|
-
import { TIntervalHandle, TMaybe, TTimeoutHandle, ensureNonNegativeNumber, ensurePositiveNumber, pad, randomInterval } from "../utils/
|
|
2
|
+
import { TComparisonResult } from "../sorting/_index.js";
|
|
3
|
+
import { TIntervalHandle, TMaybe, TTimeoutHandle, ensureNonNegativeNumber, ensurePositiveNumber, pad, randomInterval } from "../utils/_index.js";
|
|
4
4
|
import TimeBase from "./TimeBase";
|
|
5
5
|
import TimeInstant from "./TimeInstant";
|
|
6
6
|
import TimeUnit from "./TimeUnit";
|
package/src/time/TimeInstant.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { format } from "small-date";
|
|
2
2
|
import { ICancelable, ICancelablePromise } from "../async/Deferred.js";
|
|
3
|
-
import { TComparisonResult } from "../sorting/
|
|
3
|
+
import { TComparisonResult } from "../sorting/_index.js";
|
|
4
4
|
import TimeBase from "./TimeBase";
|
|
5
5
|
import TimeDuration from "./TimeDuration";
|
|
6
6
|
import { TTimeInstantBuilder, TTimeInstantCreationParameters, createTimeInstantFromParameters, timeInstantBuilder } from "./TimeInstantBuilder.js";
|
|
@@ -178,14 +178,34 @@ export class TimeInstant extends TimeBase<TimeInstant> {
|
|
|
178
178
|
return new Date( this.ms + new Date().getTimezoneOffset() * 60 * 1000 );
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
/**
|
|
182
|
+
* @deprecated use {@link TimeInstant#isInThePast2} instead.
|
|
183
|
+
*/
|
|
181
184
|
public get isInThePast(): boolean {
|
|
182
185
|
return this.ms < Date.now();
|
|
183
186
|
}
|
|
184
187
|
|
|
188
|
+
/**
|
|
189
|
+
* @deprecated use {@link TimeInstant#isInTheFuture2} instead.
|
|
190
|
+
*/
|
|
185
191
|
public get isInTheFuture(): boolean {
|
|
186
192
|
return this.ms > Date.now();
|
|
187
193
|
}
|
|
188
194
|
|
|
195
|
+
/**
|
|
196
|
+
* @returns true if the instant is in the past, false otherwise
|
|
197
|
+
*/
|
|
198
|
+
public isInThePast2(): boolean {
|
|
199
|
+
return this.ms < Date.now();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @returns true if the instant is in the future, false otherwise
|
|
204
|
+
*/
|
|
205
|
+
public isInTheFuture2(): boolean {
|
|
206
|
+
return this.ms > Date.now();
|
|
207
|
+
}
|
|
208
|
+
|
|
189
209
|
public isAfter( other: TimeInstant ): boolean {
|
|
190
210
|
return this.ms > other.ms;
|
|
191
211
|
}
|
package/src/time/TimeRange.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
|
|
2
|
+
export { default as RandomTimeDuration } from './RandomTimeDuration.js';
|
|
3
|
+
export { TPredefinedTimeDuration, TValidTimeDuration, TimeDuration, isAllowedTimeDuration } from './TimeDuration.js';
|
|
4
|
+
export { default as TimeFrequency } from './TimeFrequency.js';
|
|
5
|
+
export * from './TimeInstant.js';
|
|
6
|
+
export * from './TimeRange.js';
|
|
7
|
+
export { default as TimeUnit } from './TimeUnit.js';
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
|
package/src/time/types.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { jsonCloneDeep } from "../utils";
|
|
3
|
-
import { isDefined, isNumber, isPositiveNumber, TJsonSerializable } from "../utils/index.js";
|
|
2
|
+
import { isDefined, isNumber, isPositiveNumber, jsonCloneDeep, TJsonSerializable } from "../utils/_index.js";
|
|
4
3
|
import { EmptyUpgradeError, UnavailableUpgradeError } from "./errors";
|
|
5
4
|
import getTransitionsPath from "./getTransitionsPath";
|
|
6
5
|
import { TPossibleFromVersion, TPossibleVersion, TTransitionMatrix, TUpgradable, TUpgradeFunction, TVersionMap } from "./types";
|
package/src/upgrade/types.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
export * from './arrays.js';
|
|
3
|
+
export * from './booleans.js';
|
|
4
|
+
export { TCssDeclarationRulesDictionary, TCssSelectorDeclarationRulesDictionary, cssDeclarationRulesDictionaryToCss } from './css.js';
|
|
5
|
+
export * from './empties.js';
|
|
6
|
+
export * from './errors.js';
|
|
7
|
+
export * from './functions.js';
|
|
8
|
+
export * from './json.js';
|
|
9
|
+
export * from './nulls.js';
|
|
10
|
+
export * from './numbers.js';
|
|
11
|
+
export * from './primitives.js';
|
|
12
|
+
export * from './promises.js';
|
|
13
|
+
export * from './random.js';
|
|
14
|
+
export * from './records.js';
|
|
15
|
+
export * from './strings.js';
|
|
16
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { TFunction, TKeysOfType, TReadableArray } from "
|
|
2
|
+
import { TFunction, TKeysOfType, TReadableArray } from "../_index";
|
|
3
3
|
|
|
4
4
|
export function groupByString<V, K extends TKeysOfType<V, string>>( arr: TReadableArray<V>, field: K ): Record<V[ K ] & string, V[]> {
|
|
5
5
|
return groupByStringWith( arr, t => t[ field ] as string );
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { TFunction, TKeysOfType } from "
|
|
2
|
+
import { TFunction, TKeysOfType } from "../_index";
|
|
3
3
|
|
|
4
4
|
export function indexByString<V, K extends TKeysOfType<V, string>>( arr: V[], field: K ): Record<V[K] & string, V> {
|
|
5
5
|
return indexByStringWith( arr, t => t[ field ] as string );
|
package/src/utils/arrays.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TComparisonFunction } from "../sorting/
|
|
1
|
+
import type { TComparisonFunction } from "../sorting/_index.js";
|
|
2
2
|
import type { TAccumulator, TBiPredicate, TPredicate, TTransformer } from "./functions.js";
|
|
3
3
|
import { isNullOrUndefined, type TMaybe } from "./nulls.js";
|
|
4
4
|
|
package/src/utils/css.ts
CHANGED
|
@@ -1,27 +1,36 @@
|
|
|
1
|
-
import { isFunction, type TProducer } from "./
|
|
1
|
+
import { isFunction, repeat, type TProducer } from "./_index.ts";
|
|
2
2
|
import { type TKeysOfType } from "./records.ts";
|
|
3
3
|
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
6
|
-
export type
|
|
7
|
-
export type
|
|
8
|
-
|
|
4
|
+
export type TCssRuleDeclarationKey = TKeysOfType<CSSStyleDeclaration, string> & string;
|
|
5
|
+
export type TCssVariableDeclarationKey = `--${string}`;
|
|
6
|
+
export type TCssGenericDeclarationKey = TCssRuleDeclarationKey | TCssVariableDeclarationKey;
|
|
7
|
+
export type TCssDeclarationRulesDictionary = Partial<Record<TCssGenericDeclarationKey, string>>;
|
|
8
|
+
export type TCssSelectorDeclarationRulesDictionary = {
|
|
9
|
+
[ selector: string ]: TCssDeclarationRulesDictionary | TCssSelectorDeclarationRulesDictionary;
|
|
10
|
+
}
|
|
11
|
+
|
|
9
12
|
type TProduceable<T> = T | TProducer<T>;
|
|
10
13
|
|
|
11
14
|
const newLine = '\n', tabulation = '\t', colon = ':', semiColon = ';', space = ' ', openBracket = '{', closeBracket = '}';
|
|
12
15
|
|
|
13
|
-
export function cssDeclarationRulesDictionaryToCss(
|
|
16
|
+
export function cssDeclarationRulesDictionaryToCss( syleDeclarationRulesForSelectorsProduceable: TProduceable<TCssSelectorDeclarationRulesDictionary>, indent = 0 ) {
|
|
17
|
+
const syleDeclarationRulesForSelectors = produceableToValue( syleDeclarationRulesForSelectorsProduceable );
|
|
14
18
|
return Object.entries( syleDeclarationRulesForSelectors ).map( ( [ selector, styleDeclarationRules ] ) => {
|
|
15
|
-
const cssRules = cssSelectorDeclarationRulesDictionaryToCss( styleDeclarationRules );
|
|
19
|
+
const cssRules = cssSelectorDeclarationRulesDictionaryToCss( styleDeclarationRules, indent + 1 );
|
|
16
20
|
if ( !cssRules.length ) return null;
|
|
17
|
-
return selector + space + openBracket + newLine + cssRules.
|
|
21
|
+
return repeat( tabulation, indent ) + selector + space + openBracket + newLine + cssRules.join( newLine ) + newLine + closeBracket;
|
|
18
22
|
} ).filter( Boolean ).join( newLine + newLine );
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
/* exported for test purposes only */
|
|
22
|
-
export function cssSelectorDeclarationRulesDictionaryToCss(
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
export function cssSelectorDeclarationRulesDictionaryToCss( styleDeclarationRules: TCssDeclarationRulesDictionary | TCssSelectorDeclarationRulesDictionary, indent = 0 ): string[] {
|
|
27
|
+
return Object.entries( styleDeclarationRules ).map( ( [ key, value ]: [ string, string | TCssSelectorDeclarationRulesDictionary ] ) => {
|
|
28
|
+
if ( typeof value === 'string' ) {
|
|
29
|
+
return repeat( tabulation, indent ) + pascalCaseToKebabCase( key ) + colon + space + value + semiColon;
|
|
30
|
+
} else {
|
|
31
|
+
return repeat( tabulation, indent ) + key + space + openBracket + newLine + cssSelectorDeclarationRulesDictionaryToCss( value, indent + 1 ).join( newLine ) + newLine + repeat( tabulation, indent ) + closeBracket;
|
|
32
|
+
}
|
|
33
|
+
} );
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
function pascalCaseToKebabCase( s: string ) {
|
|
@@ -5,6 +5,7 @@ export default constant;
|
|
|
5
5
|
export const constantNull = constant( null );
|
|
6
6
|
export const constantTrue = constant( true );
|
|
7
7
|
export const constantFalse = constant( false );
|
|
8
|
+
export const constantUndefined = constant( void 0 );
|
|
8
9
|
export const alwaysTrue = constantTrue;
|
|
9
10
|
export const alwaysFalse = constantFalse;
|
|
10
11
|
export const constantZero = constant( 0 );
|
package/src/utils/functions.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { identity } from './_index.js';
|
|
1
2
|
import { constantTrue } from './functions.js';
|
|
2
3
|
|
|
3
4
|
export * from './functions/constant.js';
|
|
@@ -61,4 +62,28 @@ export function xor<T>( a: TPredicate<T>, b: TPredicate<T> ): TPredicate<T> {
|
|
|
61
62
|
return ( t: T ) => a( t ) !== b( t );
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
export function pipedInvoke<T, A>( op1: TFunction<T, A> ): TFunction<T, A>;
|
|
66
|
+
export function pipedInvoke<T, A, B>( op1: TFunction<T, A>, op2: TFunction<A, B> ): TFunction<T, B>;
|
|
67
|
+
export function pipedInvoke<T, A, B, C>( op1: TFunction<T, A>, op2: TFunction<A, B>, op3: TFunction<B, C> ): TFunction<T, C>;
|
|
68
|
+
export function pipedInvoke<T, A, B, C, D>( op1: TFunction<T, A>, op2: TFunction<A, B>, op3: TFunction<B, C>, op4: TFunction<C, D> ): TFunction<T, D>;
|
|
69
|
+
export function pipedInvoke<T, A, B, C, D, E>( op1: TFunction<T, A>, op2: TFunction<A, B>, op3: TFunction<B, C>, op4: TFunction<C, D>, op5: TFunction<D, E> ): TFunction<T, E>;
|
|
70
|
+
export function pipedInvoke<T, A, B, C, D, E, F>( op1: TFunction<T, A>, op2: TFunction<A, B>, op3: TFunction<B, C>, op4: TFunction<C, D>, op5: TFunction<D, E>, op6: TFunction<E, F> ): TFunction<T, F>;
|
|
71
|
+
export function pipedInvoke<T, A, B, C, D, E, F, G>( op1: TFunction<T, A>, op2: TFunction<A, B>, op3: TFunction<B, C>, op4: TFunction<C, D>, op5: TFunction<D, E>, op6: TFunction<E, F>, op7: TFunction<F, G> ): TFunction<T, G>;
|
|
72
|
+
export function pipedInvoke<T, A, B, C, D, E, F, G, H>( op1: TFunction<T, A>, op2: TFunction<A, B>, op3: TFunction<B, C>, op4: TFunction<C, D>, op5: TFunction<D, E>, op6: TFunction<E, F>, op7: TFunction<F, G>, op8: TFunction<G, H> ): TFunction<T, H>;
|
|
73
|
+
export function pipedInvoke<T, A, B, C, D, E, F, G, H, I>( op1: TFunction<T, A>, op2: TFunction<A, B>, op3: TFunction<B, C>, op4: TFunction<C, D>, op5: TFunction<D, E>, op6: TFunction<E, F>, op7: TFunction<F, G>, op8: TFunction<G, H>, op9: TFunction<H, I> ): TFunction<T, I>;
|
|
74
|
+
export function pipedInvoke<T, A, B, C, D, E, F, G, H, I>( op1: TFunction<T, A>, op2: TFunction<A, B>, op3: TFunction<B, C>, op4: TFunction<C, D>, op5: TFunction<D, E>, op6: TFunction<E, F>, op7: TFunction<F, G>, op8: TFunction<G, H>, op9: TFunction<H, I>, ...operations: TFunction<any, any>[] ): TFunction<T, unknown>;
|
|
75
|
+
export function pipedInvoke( ...fns: Array<TFunction<any, any>>): TFunction<any, any> { return pipedInvokeFromArray( fns ) }
|
|
64
76
|
|
|
77
|
+
export function pipedInvokeFromArray<T, R>( fns: Array<TFunction<any, any>>): TFunction<any, any> {
|
|
78
|
+
if ( fns.length === 0 ) {
|
|
79
|
+
return identity as TFunction<any, any>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if ( fns.length === 1 ) {
|
|
83
|
+
return fns[ 0 ];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return function piped( input: T ): R {
|
|
87
|
+
return fns.reduce( ( prev: any, fn: TFunction<T, R> ) => fn( prev ), input as any );
|
|
88
|
+
};
|
|
89
|
+
}
|
package/src/utils/numbers.ts
CHANGED
|
@@ -94,6 +94,9 @@ export function clamp( n: number, min: number, max: number ): number {
|
|
|
94
94
|
return n;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
+
export function clampInt0_100( n: number ) {
|
|
98
|
+
return clamp( Math.round( n ), 0, 100 ) as TNumber0_100;
|
|
99
|
+
}
|
|
97
100
|
|
|
98
101
|
export function tryToParseNumber( numberStr: string ) {
|
|
99
102
|
return withTryCatch( () => {
|
package/src/utils/promises.ts
CHANGED
package/src/async/index.ts
DELETED
package/src/time/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export { default as RandomTimeDuration } from './RandomTimeDuration';
|
|
3
|
-
export { TPredefinedTimeDuration, TValidTimeDuration, TimeDuration, isAllowedTimeDuration } from './TimeDuration';
|
|
4
|
-
export { default as TimeFrequency } from './TimeFrequency';
|
|
5
|
-
export * from './TimeInstant';
|
|
6
|
-
export * from './TimeRange.js';
|
|
7
|
-
export { default as TimeUnit } from './TimeUnit';
|
|
8
|
-
export * from './types';
|
|
9
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|