@zelgadis87/utils-core 4.13.2 → 4.13.4

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.2",
4
+ "version": "4.13.4",
5
5
  "author": "Zelgadis87",
6
6
  "license": "ISC",
7
7
  "private": false,
@@ -365,7 +365,7 @@ type TSorterStepFull<T, Ret> = TSorterStepForRecords<T, Ret>
365
365
  & TSorterStepForChainables<T, Ret>
366
366
  & TSorterStepForUsing<T, Ret>
367
367
  ;
368
- type TSorterStarter<T> = TSorterStepUsing<T, TSorter<T>>;
368
+ type TSorterStarter<T> = TSorterStepUsing<T, TSorter<T>> & TSorterStepForUsing<T, TSorter<T>>;
369
369
  export type TSorterBuilder<T> = ( builder: TSorterStarter<T> ) => TSorter<T>;
370
370
 
371
371
  type TStringComparisonOptions = TCompareFunctionOptions & { ignoreCase: boolean };
@@ -390,7 +390,7 @@ type TPrioritizeOptions = {};
390
390
  const defaultPrioritizeOptions = {} as const satisfies Partial<TPrioritizeOptions>;
391
391
 
392
392
  export const Sorter = {
393
- createFor: <T>() => doCreateEmpty<T>(),
393
+ createFor: <T>( _template?: T ) => doCreateEmpty<T>(),
394
394
  sort: <T>( arr: TReadableArray<T>, builder: TSorterBuilder<T> ) => builder( doCreateEmpty() ).sort( arr ),
395
395
  top: <T>( arr: TReadableArray<T>, n: TPositiveNumber, builder: TSorterBuilder<T> ) => builder( doCreateEmpty() ).top( arr, n ),
396
396
  bottom: <T>( arr: TReadableArray<T>, n: TPositiveNumber, builder: TSorterBuilder<T> ) => builder( doCreateEmpty() ).bottom( arr, n ),
@@ -1,15 +1,17 @@
1
1
 
2
2
  import { TFunction } from "../utils/functions.js";
3
3
  import { ensureDefined } from "../utils/nulls.js";
4
+ import { monthNames } from "./constants.js";
4
5
  import { TimeInstant, isTimeInstant } from "./TimeInstant.js";
5
- import { TDayOfMonth, THourOfDay, TMillisecondOfSecond, TMinuteOfHour, TMonth, TSecondOfMinute, TUpToTwoDigits } from "./types.js";
6
+ import { TDayOfMonth, THourOfDay, TMillisecondOfSecond, TMinuteOfHour, TMonth, TSecondOfMinute, TUpToTwoDigits, type TMonthName } from "./types.js";
6
7
 
7
8
  type TRelativeSignum = '+' | '-';
8
9
  type TRelativeNumber = `${TRelativeSignum}${TUpToTwoDigits}`;
9
10
  const isRelativeNumber = ( x: string ): x is TRelativeNumber => x !== undefined && x.length > 0 && ( x[ 0 ] === '+' || x[ 0 ] === '-' );
11
+
10
12
  export type TTimeInstantCreationParameters = {
11
13
  year: number | { absolute: number } | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
12
- month: TMonth | { absolute: TMonth } | keyof typeof monthNames | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
14
+ month: TMonth | { absolute: TMonth } | TMonthName | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
13
15
  date: TDayOfMonth | { absolute: TDayOfMonth } | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
14
16
  hours: THourOfDay | { absolute: THourOfDay } | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
15
17
  minutes: TMinuteOfHour | { absolute: TMinuteOfHour } | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
@@ -31,22 +33,9 @@ const timeInstantCreationRelativeAliases = {
31
33
  last: -1,
32
34
  next: +1,
33
35
  } as const satisfies Record<string, number>;
34
- const monthNames = {
35
- january: 1,
36
- february: 2,
37
- march: 3,
38
- april: 4,
39
- may: 5,
40
- june: 6,
41
- july: 7,
42
- august: 8,
43
- september: 9,
44
- october: 10,
45
- november: 11,
46
- december: 12,
47
- } as const satisfies Record<string, number>;
36
+
48
37
  type TAllowedTimeInstantCreationAlias = keyof typeof timeInstantCreationRelativeAliases;
49
- type TAllowedTimeInstantCreationParameter = { absolute: number } | { relative: number, relativeTo?: TimeInstant | 'now' } | TAllowedTimeInstantCreationAlias | TRelativeNumber | keyof typeof monthNames | number | undefined;
38
+ type TAllowedTimeInstantCreationParameter = { absolute: number } | { relative: number, relativeTo?: TimeInstant | 'now' } | TAllowedTimeInstantCreationAlias | TRelativeNumber | TMonthName | number | undefined;
50
39
  const timeInstantResolveValue = ( getFromDate: TFunction<Date, number>, referenceDate: Date, x: TAllowedTimeInstantCreationParameter ): number => {
51
40
  if ( x === undefined ) {
52
41
  return getFromDate( referenceDate );
@@ -0,0 +1,15 @@
1
+
2
+ export const monthNames = {
3
+ january: 1,
4
+ february: 2,
5
+ march: 3,
6
+ april: 4,
7
+ may: 5,
8
+ june: 6,
9
+ july: 7,
10
+ august: 8,
11
+ september: 9,
12
+ october: 10,
13
+ november: 11,
14
+ december: 12,
15
+ } as const satisfies Record<string, number>;
package/src/time/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { TDigit, TDigit1_9, TNumber0_1000, TParseableInt } from "../utils/_index";
2
+ import type { monthNames } from "./constants.ts";
2
3
 
3
4
  export type TOneDigit = `${TDigit}`;
4
5
  export type TTwoDigits = `${TDigit}${TDigit}`;
@@ -19,6 +20,7 @@ export type TFourDigitsYear = TFourDigits;
19
20
  export type TFourDigitsMillisecond = `${'+' | '-'}${TThreeDigits}`;
20
21
 
21
22
  export type TMonth = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
23
+ export type TMonthName = keyof typeof monthNames;
22
24
 
23
25
  export type TDayOfMonth = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
24
26
  | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19
package/src/utils/css.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { isFunction, repeat, type TProducer } from "./_index.ts";
1
+ import { isDefined, isFunction, repeat, type TProducer } from "./_index.ts";
2
2
  import { type TKeysOfType } from "./records.ts";
3
3
 
4
4
  export type TCssRuleDeclarationKey = TKeysOfType<CSSStyleDeclaration, string> & string;
@@ -9,8 +9,6 @@ export type TCssSelectorDeclarationRulesDictionary = {
9
9
  [ selector: string ]: TCssDeclarationRulesDictionary | TCssSelectorDeclarationRulesDictionary;
10
10
  }
11
11
 
12
- type TProduceable<T> = T | TProducer<T>;
13
-
14
12
  const newLine = '\n', tabulation = '\t', colon = ':', semiColon = ';', space = ' ', openBracket = '{', closeBracket = '}';
15
13
 
16
14
  export function cssDeclarationRulesDictionaryToCss( syleDeclarationRulesForSelectorsProduceable: TProduceable<TCssSelectorDeclarationRulesDictionary>, indent = 0 ) {
@@ -33,10 +31,29 @@ export function cssSelectorDeclarationRulesDictionaryToCss( styleDeclarationRule
33
31
  } );
34
32
  }
35
33
 
34
+ export function transformCssDictionary(
35
+ dict: TCssSelectorDeclarationRulesDictionary | Partial<Record<TCssGenericDeclarationKey, string>>,
36
+ transformer: ( key: TCssGenericDeclarationKey, value: string ) => string,
37
+ ): TCssSelectorDeclarationRulesDictionary | Partial<Record<TCssGenericDeclarationKey, string>> {
38
+ const newDict: TCssSelectorDeclarationRulesDictionary | Partial<Record<TCssGenericDeclarationKey, string>> = {};
39
+ for ( const [ key, value ] of Object.entries( dict ) ) {
40
+ if ( typeof value === 'string' ) {
41
+ const newValue = transformer( key as TCssGenericDeclarationKey, value );
42
+ if ( isDefined( newValue ) ) {
43
+ newDict[ key ] = newValue;
44
+ }
45
+ } else {
46
+ newDict[ key ] = transformCssDictionary( value, transformer );
47
+ }
48
+ }
49
+ return newDict;
50
+ }
51
+
36
52
  function pascalCaseToKebabCase( s: string ) {
37
53
  return s.split( /([A-Z][a-z]*)/ ).filter( Boolean ).map( n => n.toLowerCase() ).join( '-' );
38
54
  }
39
55
 
56
+ type TProduceable<T> = T | TProducer<T>;
40
57
  function produceableToValue<T>( t: TProduceable<T> ): T {
41
58
  return isFunction( t ) ? t() : t;
42
59
  }