@zelgadis87/utils-core 4.13.9 → 5.0.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@zelgadis87/utils-core",
4
- "version": "4.13.9",
4
+ "version": "5.0.0",
5
5
  "author": "Zelgadis87",
6
6
  "license": "ISC",
7
7
  "private": false,
@@ -26,7 +26,7 @@
26
26
  "@vitest/ui": "3.0.8",
27
27
  "esbuild": "0.19.2",
28
28
  "eslint": "9.22.0",
29
- "nx": "20.6.0",
29
+ "nx": "21.1.2",
30
30
  "rimraf": "6.0.1",
31
31
  "typescript": "5.8.2",
32
32
  "typescript-eslint": "8.26.1",
package/src/Logger.ts CHANGED
@@ -4,7 +4,7 @@ import { noop, padRight } from "./utils/_index.js";
4
4
  const LEVELS = [ "log", "debug", "info", "warn", "error" ] as const;
5
5
  type TLogLevel = keyof Console & typeof LEVELS[ number ]
6
6
 
7
- const timestamp = () => TimeInstant.now().asTimeString();
7
+ const timestamp = () => TimeInstant.now().format( 'HH:mm:ss' );
8
8
 
9
9
  export type TLoggerOpts = {
10
10
  console: Console;
@@ -24,9 +24,6 @@ export class Deferred<T = void> implements ICancelablePromise<T> {
24
24
 
25
25
  public get pending(): boolean { return this._pending; }
26
26
 
27
- /** @deprecated: Use resolve, then and catch directly; use asPromise to return a promise type. */
28
- public get promise(): Promise<T> { return this._internals.promise; }
29
-
30
27
  constructor() {
31
28
  this._pending = true;
32
29
  this._internals = this.createInternals();
@@ -1,5 +1,4 @@
1
1
 
2
- export * from './CancelableDeferred.ts';
3
2
  export * from './Deferred.ts';
4
3
  export * from './RateThrottler.ts';
5
4
  export * from './Semaphore.ts';
@@ -408,8 +408,4 @@ export const Sorter = {
408
408
  first: <T>( arr: TReadableArray<T>, builder: TSorterBuilder<T> ) => builder( doCreateEmpty() ).first( arr ),
409
409
  last: <T>( arr: TReadableArray<T>, builder: TSorterBuilder<T> ) => builder( doCreateEmpty() ).last( arr ),
410
410
  };
411
- /**
412
- * @deprecated[2023-11-01]: Use {@link Sorter} instead.
413
- **/
414
- export const Sorting = Sorter;
415
411
  export default Sorter;
@@ -1,5 +1,4 @@
1
1
 
2
- export * from './types.js';
3
- export { default as ComparisonChain } from './ComparisonChain.js';
4
2
  export * from './Sorter.js';
5
3
  export * from './types.js';
4
+
@@ -1,10 +1,10 @@
1
- import { randomInterval } from "../utils/random.js";
1
+ import { randomNumberInInterval } from "../utils/random.js";
2
2
  import TimeDuration from "./TimeDuration.js";
3
3
  import TimeUnit from "./TimeUnit.js";
4
4
 
5
5
  function randomize( unit: TimeUnit ) {
6
6
  return ( a: number, b: number ) => {
7
- return TimeDuration.fromMs( randomInterval( unit.toMs( a ), unit.toMs( b ) ) );
7
+ return TimeDuration.fromMs( randomNumberInInterval( unit.toMs( a ), unit.toMs( b ) ) );
8
8
  }
9
9
  }
10
10
 
@@ -1,6 +1,6 @@
1
1
  import Deferred, { DeferredCanceledError, ICancelable, ICancelablePromise } from "../async/Deferred.js";
2
2
  import { TComparisonResult } from "../sorting/_index.js";
3
- import { TIntervalHandle, TMaybe, TTimeoutHandle, ensureNonNegativeNumber, ensurePositiveNumber, pad, randomInterval } from "../utils/_index.js";
3
+ import { TIntervalHandle, TMaybe, TTimeoutHandle, ensureNonNegativeNumber, ensurePositiveNumber, pad } from "../utils/_index.js";
4
4
  import TimeBase from "./TimeBase";
5
5
  import TimeInstant from "./TimeInstant";
6
6
  import TimeUnit from "./TimeUnit";
@@ -30,11 +30,6 @@ export class TimeDuration extends TimeBase<TimeDuration> {
30
30
  return super.removeUnits( nn, unit );
31
31
  }
32
32
 
33
- /** @deprecated: Use multiplyBy instead **/
34
- public multiply( times: number ) {
35
- return this.multiplyBy( times );
36
- }
37
-
38
33
  public multiplyBy( times: number ): TimeDuration {
39
34
  ensureNonNegativeNumber( times, "times" );
40
35
  return TimeDuration.ms( this.ms * times );
@@ -69,13 +64,6 @@ export class TimeDuration extends TimeBase<TimeDuration> {
69
64
  return 'Some time ago';
70
65
  }
71
66
 
72
- /**
73
- * @deprecated[2023-06] this method makes no sense, as durations are positive by default.
74
- */
75
- public absolute(): TimeDuration {
76
- return this.ms < 0 ? new TimeDuration( -this.ms, TimeUnit.MILLISECONDS ) : this;
77
- }
78
-
79
67
  public interval( cb: () => unknown ): TIntervalHandle {
80
68
  return setInterval( cb, this.ms );
81
69
  }
@@ -153,11 +141,6 @@ export class TimeDuration extends TimeBase<TimeDuration> {
153
141
  return new TimeDuration( Math.abs( this.ms - other.ms ), TimeUnit.MILLISECONDS );
154
142
  }
155
143
 
156
- /** @deprecated: Use fromNow instead **/
157
- public addCurrentTime() {
158
- return this.fromNow();
159
- }
160
-
161
144
  public isGreaterThan( other: TimeDuration ): boolean {
162
145
  return this.ms > other.ms;
163
146
  }
@@ -224,11 +207,11 @@ export class TimeDuration extends TimeBase<TimeDuration> {
224
207
  return a.compareTo( b );
225
208
  }
226
209
 
227
- public static ms = durationConstructor( TimeUnit.MILLISECONDS );
228
- public static seconds = durationConstructor( TimeUnit.SECONDS );
229
- public static minutes = durationConstructor( TimeUnit.MINUTES );
230
- public static hours = durationConstructor( TimeUnit.HOURS );
231
- public static days = durationConstructor( TimeUnit.DAYS );
210
+ public static ms = ( value: number ) => new TimeDuration( value, TimeUnit.MILLISECONDS );
211
+ public static seconds = ( value: number ) => new TimeDuration( value, TimeUnit.SECONDS );
212
+ public static minutes = ( value: number ) => new TimeDuration( value, TimeUnit.MINUTES );
213
+ public static hours = ( value: number ) => new TimeDuration( value, TimeUnit.HOURS );
214
+ public static days = ( value: number ) => new TimeDuration( value, TimeUnit.DAYS );
232
215
 
233
216
  public static shamefulUnref = ( ms: TAllowedTimeDuration ): number => {
234
217
  if ( ms instanceof TimeDuration ) {
@@ -282,20 +265,6 @@ export class TimeDuration extends TimeBase<TimeDuration> {
282
265
 
283
266
  }
284
267
 
285
- interface IDurationConstructor {
286
- ( a: number ): TimeDuration
287
- /** @deprecated[2023-06] Use RandomTimeDuration instead */( a: number, b?: number ): TimeDuration
288
- }
289
-
290
- /** @deprecated[2023-06] Use RandomTimeDuration instead */
291
- function durationConstructor( unit: TimeUnit ): IDurationConstructor {
292
- return ( a: number, b?: number ) => {
293
- const aMs = unit.toMs( a );
294
- const bMs = b ? unit.toMs( b ) : aMs;
295
- return TimeDuration.fromMs( randomInterval( aMs, bMs ) );
296
- }
297
- }
298
-
299
268
  export type TPredefinedTimeDuration = 0 | 50 | 100 | 150 | 200 | 250 | 300 | 500 | 1000 | 1500 | 2000 | 2500 | 5000;
300
269
  export type TValidTimeDuration = TimeDuration | TPredefinedTimeDuration;
301
270
  type TAllowedTimeDuration = TValidTimeDuration | number; // eslint-disable-line @typescript-eslint/no-redundant-type-constituents
@@ -32,6 +32,10 @@ export class TimeInstant extends TimeBase<TimeInstant> {
32
32
  public distanceFromNow(): TimeDuration {
33
33
  return TimeDuration.fromMs( Math.abs( this.ms - Date.now() ) );
34
34
  }
35
+
36
+ public distanceFromUnixTimestamp( timestamp: number ): TimeDuration {
37
+ return TimeDuration.ms( this.ms - timestamp );
38
+ }
35
39
 
36
40
  public timeLeftFrom( instant: TimeInstant ): TimeDuration {
37
41
  const distance = this.ms - instant.ms;
@@ -76,35 +80,19 @@ export class TimeInstant extends TimeBase<TimeInstant> {
76
80
  }
77
81
 
78
82
  public ensureInTheFuture() {
79
- if ( !this.isInTheFuture )
80
- throw new Error( 'Instant is in the past' );
83
+ if ( !this.isInTheFuture() )
84
+ throw new Error( 'Instant is not in the future' );
81
85
  }
82
86
 
83
87
  public ensureInThePast() {
84
- if ( !this.isInThePast )
85
- throw new Error( 'Instant is in the future' );
88
+ if ( !this.isInThePast() )
89
+ throw new Error( 'Instant is not in the past' );
86
90
  }
87
91
 
88
92
  public isToday(): boolean {
89
93
  return Math.floor( this.days ) === Math.floor( TimeInstant.now().days );
90
94
  }
91
95
 
92
- /**
93
- * @returns the time as HH:mm:ss
94
- * @deprecated [2024-12-11] this method is too ambigous and should be removed.
95
- */
96
- public asTimeString(): string {
97
- return this.format( 'HH:mm:ss' );
98
- }
99
-
100
- /**
101
- * @returns the date as dd/MM/yyyy
102
- * @deprecated [2024-12-11] this method is too ambigous and should be removed.
103
- */
104
- public asDateString(): string {
105
- return this.format( 'dd/MM/yyyy' );
106
- }
107
-
108
96
  /**
109
97
  * Formats this instant using the given pattern. The pattern can contain the following tokens:
110
98
  *
@@ -158,8 +146,7 @@ export class TimeInstant extends TimeBase<TimeInstant> {
158
146
  }
159
147
 
160
148
  /**
161
- * @returns this instant, in a human readable format. The format COULD change in the future, do NOT use this method for consistent outputs.
162
- * @deprecated [2024-12-11] this method is too broad and ambigous and should be removed.
149
+ * @returns this instant, in a human readable format, containing both the date and the time. The format COULD change in the future, do NOT use this method for consistent outputs.
163
150
  */
164
151
  public asHumanTimestamp(): string {
165
152
  return this.format( 'yyyy-MM-dd HH:mm:ss' )
@@ -178,31 +165,17 @@ export class TimeInstant extends TimeBase<TimeInstant> {
178
165
  return new Date( this.ms + new Date().getTimezoneOffset() * 60 * 1000 );
179
166
  }
180
167
 
181
- /**
182
- * @deprecated use {@link TimeInstant#isInThePast2} instead.
183
- */
184
- public get isInThePast(): boolean {
185
- return this.ms < Date.now();
186
- }
187
-
188
- /**
189
- * @deprecated use {@link TimeInstant#isInTheFuture2} instead.
190
- */
191
- public get isInTheFuture(): boolean {
192
- return this.ms > Date.now();
193
- }
194
-
195
168
  /**
196
169
  * @returns true if the instant is in the past, false otherwise
197
170
  */
198
- public isInThePast2(): boolean {
171
+ public isInThePast(): boolean {
199
172
  return this.ms < Date.now();
200
173
  }
201
174
 
202
175
  /**
203
176
  * @returns true if the instant is in the future, false otherwise
204
177
  */
205
- public isInTheFuture2(): boolean {
178
+ public isInTheFuture(): boolean {
206
179
  return this.ms > Date.now();
207
180
  }
208
181
 
@@ -224,34 +197,6 @@ export class TimeInstant extends TimeBase<TimeInstant> {
224
197
  }
225
198
  }
226
199
 
227
- /**
228
- * @deprecated: Use {@link distanceFromNow} instead
229
- */
230
- // TODO[2023-07-04, Deprecated]: Remove this method in a future version
231
- public fromNow(): TimeDuration {
232
- return TimeDuration.ms( this.ms - Date.now() );
233
- }
234
-
235
- /**
236
- * @deprecated: Use {@link distanceFrom} instead
237
- */
238
- // TODO[2023-07-04, Deprecated]: Remove this method in a future version
239
- public from( instant: TimeInstant ): TimeDuration {
240
- return TimeDuration.ms( this.ms - instant.ms );
241
- }
242
-
243
- /**
244
- * @deprecated: Use {@link distanceFromUnixTimestamp} instead
245
- */
246
- // TODO[2023-07-04, Deprecated]: Remove this method in a future version
247
- public fromTimestamp( timestamp: number ): TimeDuration {
248
- return TimeDuration.ms( this.ms - timestamp );
249
- }
250
-
251
- public distanceFromUnixTimestamp( timestamp: number ): TimeDuration {
252
- return TimeDuration.ms( this.ms - timestamp );
253
- }
254
-
255
200
  public atTime( parameters: Partial<TTimeInstantCreationParameters & { year: never; month: never; date: never; }> ) {
256
201
  return TimeInstant.fromParameters( parameters, this );
257
202
  }
@@ -296,16 +241,6 @@ export class TimeInstant extends TimeBase<TimeInstant> {
296
241
  return timeInstantBuilder();
297
242
  }
298
243
 
299
- /**
300
- * @deprecated[19/07/2023] Use {@link fromParameters} instead.
301
- */
302
- public static fromUnits( { date, month, year, hours, minutes, seconds }: { date: number, month: number, year: number, hours?: number, minutes?: number, seconds?: number } ): TimeInstant {
303
- const dt = Date.UTC( year, month - 1, date, hours ?? 0, minutes ?? 0, seconds ?? 0 );
304
- if ( isNaN( dt ) )
305
- throw new Error( `Unparseable date: ${date}, ${month}, ${year}, ${hours ?? '-'}, ${minutes ?? '-'}, ${seconds ?? '-'}` )
306
- return TimeInstant.fromUnixTimestamp( dt );
307
- }
308
-
309
244
  public static fromIso8601( str: TIso8601DateString ) {
310
245
  return TimeInstant.fromUnixTimestamp( new Date( str ).getTime() );
311
246
  }
@@ -320,10 +255,6 @@ export class TimeInstant extends TimeBase<TimeInstant> {
320
255
  return TimeInstant.fromUnixTimestamp( Date.now() );
321
256
  }
322
257
 
323
- public static get currentTimeStamp(): number {
324
- return Date.now();
325
- }
326
-
327
258
  public static compare( a: TimeInstant, b: TimeInstant ): TComparisonResult {
328
259
  return a.compareTo( b );
329
260
  }
package/src/utils/css.ts CHANGED
@@ -24,7 +24,11 @@ export function cssDeclarationRulesDictionaryToCss( syleDeclarationRulesForSelec
24
24
  export function cssSelectorDeclarationRulesDictionaryToCss( styleDeclarationRules: TCssDeclarationRulesDictionary | TCssSelectorDeclarationRulesDictionary, indent = 0 ): string[] {
25
25
  return Object.entries( styleDeclarationRules ).map( ( [ key, value ]: [ string, string | TCssSelectorDeclarationRulesDictionary ] ) => {
26
26
  if ( typeof value === 'string' ) {
27
- return repeat( tabulation, indent ) + pascalCaseToKebabCase( key ) + colon + space + value + semiColon;
27
+ if ( key.startsWith( '--' ) ) {
28
+ return repeat( tabulation, indent ) + key + colon + space + value + semiColon;
29
+ } else {
30
+ return repeat( tabulation, indent ) + pascalCaseToKebabCase( key ) + colon + space + value + semiColon;
31
+ }
28
32
  } else {
29
33
  return repeat( tabulation, indent ) + key + space + openBracket + newLine + cssSelectorDeclarationRulesDictionaryToCss( value, indent + 1 ).join( newLine ) + newLine + repeat( tabulation, indent ) + closeBracket;
30
34
  }
package/src/utils/json.ts CHANGED
@@ -45,5 +45,3 @@ export function omitFromJsonObject<T extends TJsonObject, K extends keyof T>( o:
45
45
  return obj;
46
46
  }, { ...o } );
47
47
  }
48
- /** @deprecated[2024-12-23]: Use {@link omitFromJsonObject} instead. */
49
- export const omit = omitFromJsonObject;
@@ -1,11 +1,5 @@
1
1
  import { TPositiveNumber } from "./numbers.ts";
2
2
 
3
- /** @deprecated[2025-01-14]: Use {@link randomNumberInInterval} instead. */
4
- export const randomInterval = ( min: number, max: number ): number => randomNumberInInterval( min, max );
5
-
6
- /** @deprecated[2025-01-14]: Use {@link randomNumberInInterval} / 100 instead. */
7
- export const randomPercentage = ( min: number, max: number ): number => randomNumberInInterval( min, max ) / 100;
8
-
9
3
  export function randomNumberInInterval( min: number, max: number ): number {
10
4
  return Math.floor( Math.random() * ( max - min + 1 ) + min );
11
5
  }
@@ -85,7 +85,4 @@ export function wrapWithString( str: string, delimiter: string ): string {
85
85
  return delimiter + str + delimiter;
86
86
  }
87
87
 
88
- /** @deprecated[2024-12-23]: Use {@link wrapWithString} instead. */
89
- export const wrap = wrapWithString;
90
-
91
88