@zelgadis87/utils-core 4.13.0 → 4.13.2

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.0",
4
+ "version": "4.13.2",
5
5
  "author": "Zelgadis87",
6
6
  "license": "ISC",
7
7
  "private": false,
@@ -76,11 +76,11 @@ const compareDates = <T, R extends Date>( fns: ReadonlyArray<TComparisonFunction
76
76
  return chain( fns, compareFunction( transform, naturalOrderComparison, { nullsFirst, direction } ) );
77
77
  };
78
78
  const compareTimeInstants = <T, R extends TimeInstant>( fns: ReadonlyArray<TComparisonFunction<T>>, transform: TFunction<T, R>, options: TConditionalParameterOptions<TTimeInstantComparisonOptions, typeof defaultTimeInstantComparisonOptions> = {} ) => {
79
- const { nullsFirst, direction } = { ...defaultDateComparisonOptions, ...options };
79
+ const { nullsFirst, direction } = { ...defaultTimeInstantComparisonOptions, ...options };
80
80
  return chain( fns, compareFunction( transform, ( a, b ) => a.isBefore( b ) ? -1 : 1, { nullsFirst, direction } ) );
81
81
  };
82
82
  const compareTimeDurations = <T, R extends TimeDuration>( fns: ReadonlyArray<TComparisonFunction<T>>, transform: TFunction<T, R>, options: TConditionalParameterOptions<TTimeDurationComparisonOptions, typeof defaultTimeDurationComparisonOptions> = {} ) => {
83
- const { nullsFirst, direction } = { ...defaultDateComparisonOptions, ...options };
83
+ const { nullsFirst, direction } = { ...defaultTimeDurationComparisonOptions, ...options };
84
84
  return chain( fns, compareFunction( transform, ( a, b ) => a.isLessThan( b ) ? -1 : 1, { nullsFirst, direction } ) );
85
85
  };
86
86
  const compareBooleans = <T, R extends boolean>( fns: ReadonlyArray<TComparisonFunction<T>>, transform: TFunction<T, R>, options: TConditionalParameterOptions<TBooleanComparisonOptions, typeof defaultBooleanComparisonOptions> ) => {
@@ -134,6 +134,8 @@ const next = <T, R>( fns: ReadonlyArray<TComparisonFunction<T>>, transform: TFun
134
134
  usingNumbers: field => using( t => t[ field ] ),
135
135
  usingBooleans: field => using( t => t[ field ] ),
136
136
  usingDates: field => using( t => t[ field ] ),
137
+ usingTimeInstant: field => using( t => t[ field ] ),
138
+ usingTimeDuration: field => using( t => t[ field ] ),
137
139
  } as const satisfies TSorterStepForRecords<R, TSorter<T>>;
138
140
  const retForNumbers = {
139
141
  ...retAsUsing,
@@ -293,10 +295,12 @@ export type TSorter<T> = {
293
295
  }
294
296
 
295
297
  type TSorterStepForRecords<T, Ret> = {
296
- usingStrings: ( field: TKeysOfType<T, string> ) => TSorterStep<string, Ret>;
297
- usingNumbers: ( field: TKeysOfType<T, number> ) => TSorterStep<number, Ret>;
298
- usingBooleans: ( field: TKeysOfType<T, boolean> ) => TSorterStep<boolean, Ret>;
299
- usingDates: ( field: TKeysOfType<T, Date> ) => TSorterStep<Date, Ret>;
298
+ usingStrings: ( field: TKeysOfType<T, string> ) => TSorterStepUsing<string, Ret>;
299
+ usingNumbers: ( field: TKeysOfType<T, number> ) => TSorterStepUsing<number, Ret>;
300
+ usingBooleans: ( field: TKeysOfType<T, boolean> ) => TSorterStepUsing<boolean, Ret>;
301
+ usingDates: ( field: TKeysOfType<T, Date> ) => TSorterStepUsing<Date, Ret>;
302
+ usingTimeInstant: ( field: TKeysOfType<T, TimeInstant> ) => TSorterStepUsing<TimeInstant, Ret>;
303
+ usingTimeDuration: ( field: TKeysOfType<T, TimeDuration> ) => TSorterStepUsing<TimeDuration, Ret>;
300
304
  };
301
305
  type TSorterStepForNumbers<_T, Ret> = {
302
306
  inAscendingOrder( opts?: { nullsFirst?: boolean } ): Ret;
@@ -328,7 +332,7 @@ type TSorterStepForChainables<T, Ret> = {
328
332
  chain: ( chain: TComparable<T> ) => Ret;
329
333
  };
330
334
  type TSorterStepForUsing<T, Ret> = {
331
- using: <X>( transform: TFunction<T, X> ) => TSorterStep<X, Ret>;
335
+ using: <X>( transform: TFunction<T, X> ) => TSorterStepUsing<X, Ret>;
332
336
  };
333
337
  type TSorterStepForPrioritizable<T extends string | number, Ret> = {
334
338
  prioritizing( arr: T[], options?: TConditionalParameterOptions<TPrioritizeOptions, typeof defaultPrioritizeOptions> ): Ret;
@@ -336,7 +340,7 @@ type TSorterStepForPrioritizable<T extends string | number, Ret> = {
336
340
  prioritizingWithEqualWeight( arr: T[], options?: TConditionalParameterOptions<TPrioritizeOptions, typeof defaultPrioritizeOptions> ): Ret;
337
341
  deprioritizingWithEqualWeight( arr: Array<T>, options?: TConditionalParameterOptions<TPrioritizeOptions, typeof defaultPrioritizeOptions> ): Ret;
338
342
  };
339
- type TSorterStep<T, Ret> = {}
343
+ type TSorterStepUsing<T, Ret> = {}
340
344
  & ( T extends Record<string | number | symbol, unknown> ? TSorterStepForRecords<T, Ret> : {} )
341
345
  & ( T extends number ? TSorterStepForNumbers<T, Ret> : {} )
342
346
  & ( T extends string ? TSorterStepForStrings<T, Ret> : {} )
@@ -346,6 +350,8 @@ type TSorterStep<T, Ret> = {}
346
350
  & ( T extends TimeDuration ? TSorterStepForTimeDuration<T, Ret> : {} )
347
351
  & ( T extends string ? TSorterStepForPrioritizable<string, Ret> : {} ) // Allowing all types of strings here is needed because literal types extending strings create compilation problems with method signatures (T[] where T = 'A' | 'B' becomes 'A'[] & 'B'[])
348
352
  & ( T extends number ? TSorterStepForPrioritizable<number, Ret> : {} ) // Allowing all types of numbers here is needed because literal types extending numbers create compilation problems with method signatures (T[] where T = 1 | 2 becomes 1[] & 2[])
353
+ ;
354
+ type TSorterStep<T, Ret> = TSorterStepUsing<T, Ret>
349
355
  & TSorterStepForChainables<T, Ret>
350
356
  & TSorterStepForUsing<T, Ret>
351
357
  ;
@@ -359,7 +365,7 @@ type TSorterStepFull<T, Ret> = TSorterStepForRecords<T, Ret>
359
365
  & TSorterStepForChainables<T, Ret>
360
366
  & TSorterStepForUsing<T, Ret>
361
367
  ;
362
- type TSorterStarter<T> = TSorterStep<T, TSorter<T>>;
368
+ type TSorterStarter<T> = TSorterStepUsing<T, TSorter<T>>;
363
369
  export type TSorterBuilder<T> = ( builder: TSorterStarter<T> ) => TSorter<T>;
364
370
 
365
371
  type TStringComparisonOptions = TCompareFunctionOptions & { ignoreCase: boolean };
@@ -383,13 +389,6 @@ const defaultBooleanComparisonOptions = { ...defaultCompareValuesOptions } as co
383
389
  type TPrioritizeOptions = {};
384
390
  const defaultPrioritizeOptions = {} as const satisfies Partial<TPrioritizeOptions>;
385
391
 
386
- /**
387
- * @deprecated[2023-10-19]: Use {@link Sorter.createFor} instead.
388
- **/
389
- export function createSorterFor<T>() {
390
- return doCreateEmpty<T>();
391
- }
392
-
393
392
  export const Sorter = {
394
393
  createFor: <T>() => doCreateEmpty<T>(),
395
394
  sort: <T>( arr: TReadableArray<T>, builder: TSorterBuilder<T> ) => builder( doCreateEmpty() ).sort( arr ),