@nr1e/commons 0.4.1 → 0.4.3
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/lang/datetime.d.mts +18 -1
- package/dist/lang/datetime.d.mts.map +1 -1
- package/dist/lang/datetime.mjs +40 -2
- package/dist/lang/datetime.mjs.map +1 -1
- package/dist/lang/string.d.mts +59 -0
- package/dist/lang/string.d.mts.map +1 -1
- package/dist/lang/string.mjs +100 -0
- package/dist/lang/string.mjs.map +1 -1
- package/package.json +3 -3
package/dist/lang/datetime.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare function isoDateToFormattedUtc(isoDate: string): string;
|
|
2
|
-
export declare function formatDate(date: Date): string;
|
|
2
|
+
export declare function formatDate(date: Date, timeZone?: string, locale?: string): string;
|
|
3
3
|
/**
|
|
4
4
|
* Formats a date and time to a human-readable string with time zone.
|
|
5
5
|
* @param date - Date string or Date object to format.
|
|
@@ -7,6 +7,14 @@ export declare function formatDate(date: Date): string;
|
|
|
7
7
|
* @returns Formatted date string (e.g., "June 14, 2023 12:00 PM MST").
|
|
8
8
|
*/
|
|
9
9
|
export declare function formatDateTimeReadable(date: string | Date, locale?: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Formats a date and time to a human-readable string with time zone.
|
|
12
|
+
* @param date - Date string or Date object to format.
|
|
13
|
+
* @param timeZone - The time zone to use (e.g., 'America/Los_Angeles') - defaults to the local time zone.
|
|
14
|
+
* @param locale - The locale to use (e.g., 'en-US', 'fr-FR') - defaults to 'en-US'
|
|
15
|
+
* @returns Formatted date string (e.g., "June 14, 2023 12:00 PM MST").
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatTimeZoneDateTimeReadable(date: string | Date, timeZone?: string, locale?: string): string;
|
|
10
18
|
/**
|
|
11
19
|
* Formats a date to "Jun 30, 2025" style using the local time zone.
|
|
12
20
|
* Accepts a Date object or a string parseable by Date.
|
|
@@ -15,6 +23,15 @@ export declare function formatDateTimeReadable(date: string | Date, locale?: str
|
|
|
15
23
|
* @returns Formatted date string like "Jun 30, 2025".
|
|
16
24
|
*/
|
|
17
25
|
export declare function formatDateShort(date: string | Date, locale?: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Formats a date to "Jun 30, 2025" style using the local time zone.
|
|
28
|
+
* Accepts a Date object or a string parseable by Date.
|
|
29
|
+
* @param date - Date string or Date object to format.
|
|
30
|
+
* @param timeZone - The time zone to use (e.g., 'America/Los_Angeles') - defaults to the local time zone.
|
|
31
|
+
* @param locale - The locale to use (e.g., 'en-US', 'fr-FR') - defaults to 'en-US'
|
|
32
|
+
* @returns Formatted date string like "Jun 30, 2025".
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatTimeZoneDateShort(date: string | Date, timeZone?: string, locale?: string): string;
|
|
18
35
|
/**
|
|
19
36
|
* Calculates the number of days between a given date and the current date.
|
|
20
37
|
* @param date - The date to calculate from.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datetime.d.mts","sourceRoot":"","sources":["../../src/lang/datetime.mts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA2B7D;AAED,wBAAgB,UAAU,
|
|
1
|
+
{"version":3,"file":"datetime.d.mts","sourceRoot":"","sources":["../../src/lang/datetime.mts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA2B7D;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,IAAI,EACV,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAQR;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAWR;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAYR;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAO5E;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAQR;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAKxD"}
|
package/dist/lang/datetime.mjs
CHANGED
|
@@ -24,13 +24,14 @@ export function isoDateToFormattedUtc(isoDate) {
|
|
|
24
24
|
const minutesStr = minutes.toString().padStart(2, '0');
|
|
25
25
|
return `${month} ${day}, ${year} ${hours}:${minutesStr} ${ampm} UTC`;
|
|
26
26
|
}
|
|
27
|
-
export function formatDate(date) {
|
|
27
|
+
export function formatDate(date, timeZone, locale) {
|
|
28
28
|
const options = {
|
|
29
|
+
timeZone,
|
|
29
30
|
month: 'short', // “Jan”, “Feb”, etc.
|
|
30
31
|
day: 'numeric', // “1”, “2”, etc.
|
|
31
32
|
year: 'numeric', // “2020”
|
|
32
33
|
};
|
|
33
|
-
return new Intl.DateTimeFormat('en-US', options).format(date);
|
|
34
|
+
return new Intl.DateTimeFormat(locale ?? 'en-US', options).format(date);
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
37
|
* Formats a date and time to a human-readable string with time zone.
|
|
@@ -50,6 +51,26 @@ export function formatDateTimeReadable(date, locale) {
|
|
|
50
51
|
timeZoneName: 'short',
|
|
51
52
|
}).format(dateObj);
|
|
52
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Formats a date and time to a human-readable string with time zone.
|
|
56
|
+
* @param date - Date string or Date object to format.
|
|
57
|
+
* @param timeZone - The time zone to use (e.g., 'America/Los_Angeles') - defaults to the local time zone.
|
|
58
|
+
* @param locale - The locale to use (e.g., 'en-US', 'fr-FR') - defaults to 'en-US'
|
|
59
|
+
* @returns Formatted date string (e.g., "June 14, 2023 12:00 PM MST").
|
|
60
|
+
*/
|
|
61
|
+
export function formatTimeZoneDateTimeReadable(date, timeZone, locale) {
|
|
62
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
63
|
+
return new Intl.DateTimeFormat(locale ?? 'en-US', {
|
|
64
|
+
timeZone,
|
|
65
|
+
year: 'numeric',
|
|
66
|
+
month: 'long',
|
|
67
|
+
day: 'numeric',
|
|
68
|
+
hour: 'numeric',
|
|
69
|
+
minute: '2-digit',
|
|
70
|
+
hour12: true,
|
|
71
|
+
timeZoneName: 'short',
|
|
72
|
+
}).format(dateObj);
|
|
73
|
+
}
|
|
53
74
|
/**
|
|
54
75
|
* Formats a date to "Jun 30, 2025" style using the local time zone.
|
|
55
76
|
* Accepts a Date object or a string parseable by Date.
|
|
@@ -65,6 +86,23 @@ export function formatDateShort(date, locale) {
|
|
|
65
86
|
day: 'numeric',
|
|
66
87
|
}).format(dateObj);
|
|
67
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Formats a date to "Jun 30, 2025" style using the local time zone.
|
|
91
|
+
* Accepts a Date object or a string parseable by Date.
|
|
92
|
+
* @param date - Date string or Date object to format.
|
|
93
|
+
* @param timeZone - The time zone to use (e.g., 'America/Los_Angeles') - defaults to the local time zone.
|
|
94
|
+
* @param locale - The locale to use (e.g., 'en-US', 'fr-FR') - defaults to 'en-US'
|
|
95
|
+
* @returns Formatted date string like "Jun 30, 2025".
|
|
96
|
+
*/
|
|
97
|
+
export function formatTimeZoneDateShort(date, timeZone, locale) {
|
|
98
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
99
|
+
return new Intl.DateTimeFormat(locale ?? 'en-US', {
|
|
100
|
+
timeZone,
|
|
101
|
+
year: 'numeric',
|
|
102
|
+
month: 'short',
|
|
103
|
+
day: 'numeric',
|
|
104
|
+
}).format(dateObj);
|
|
105
|
+
}
|
|
68
106
|
/**
|
|
69
107
|
* Calculates the number of days between a given date and the current date.
|
|
70
108
|
* @param date - The date to calculate from.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datetime.mjs","sourceRoot":"","sources":["../../src/lang/datetime.mts"],"names":[],"mappings":"AAAA,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,MAAM,UAAU,GAAG;QACjB,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;KACN,CAAC;IACF,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;IAEnC,IAAI,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACvC,KAAK,GAAG,KAAK,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,mCAAmC;IAC7D,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAEvD,OAAO,GAAG,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,IAAI,UAAU,IAAI,IAAI,MAAM,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,UAAU,
|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of a string
|
|
3
|
+
*
|
|
4
|
+
* @param input - The string to capitalize
|
|
5
|
+
*/
|
|
1
6
|
export declare function capitalizeFirstLetter(input: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Returns null if the input string is empty or only whitespace. Otherwise, returns the input string.
|
|
9
|
+
*
|
|
10
|
+
* @param input - The string to check
|
|
11
|
+
*/
|
|
12
|
+
export declare function emptyToNull(input?: string | null): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Tests if a string is lower case alphanumeric
|
|
15
|
+
*
|
|
16
|
+
* @param str the string to check
|
|
17
|
+
*/
|
|
18
|
+
export declare function isLowerAlphanumeric(str?: string | null): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Tests if a string is upper case alphanumeric.
|
|
21
|
+
*
|
|
22
|
+
* @param str the string to check
|
|
23
|
+
*/
|
|
24
|
+
export declare function isUpperAlphanumeric(str?: string | null): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Tests if a string is PascalCase.
|
|
27
|
+
*
|
|
28
|
+
* @param str the string to test
|
|
29
|
+
*/
|
|
30
|
+
export declare function isPascalCase(str?: string | null): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Tests if a string is camelCase.
|
|
33
|
+
*
|
|
34
|
+
* @param str the string to test
|
|
35
|
+
*/
|
|
36
|
+
export declare function isCamelCase(str?: string | null): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Converts a string to snake_case
|
|
39
|
+
*
|
|
40
|
+
* @param str the string to convert
|
|
41
|
+
*/
|
|
42
|
+
export declare function toSnakeCase(str: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Converts a string to kebab-case
|
|
45
|
+
*
|
|
46
|
+
* @param str the string to convert
|
|
47
|
+
*/
|
|
48
|
+
export declare function toKebabCase(str: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Converts a string to camelCase.
|
|
51
|
+
*
|
|
52
|
+
* @param str the string to convert
|
|
53
|
+
*/
|
|
54
|
+
export declare function toCamelCase(str: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Converts a string to PascalCase.
|
|
57
|
+
*
|
|
58
|
+
* @param str the string to convert
|
|
59
|
+
*/
|
|
60
|
+
export declare function toPascalCase(str: string): string;
|
|
2
61
|
//# sourceMappingURL=string.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.mts","sourceRoot":"","sources":["../../src/lang/string.mts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3D"}
|
|
1
|
+
{"version":3,"file":"string.d.mts","sourceRoot":"","sources":["../../src/lang/string.mts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAIhE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAKhE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAKhE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,WAK/C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,WAK9C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ/C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ/C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD"}
|
package/dist/lang/string.mjs
CHANGED
|
@@ -1,4 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capitalizes the first letter of a string
|
|
3
|
+
*
|
|
4
|
+
* @param input - The string to capitalize
|
|
5
|
+
*/
|
|
1
6
|
export function capitalizeFirstLetter(input) {
|
|
2
7
|
return input.charAt(0).toUpperCase() + input.slice(1);
|
|
3
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Returns null if the input string is empty or only whitespace. Otherwise, returns the input string.
|
|
11
|
+
*
|
|
12
|
+
* @param input - The string to check
|
|
13
|
+
*/
|
|
14
|
+
export function emptyToNull(input) {
|
|
15
|
+
if (!input)
|
|
16
|
+
return null;
|
|
17
|
+
if (input.trim().length === 0)
|
|
18
|
+
return null;
|
|
19
|
+
return input;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Tests if a string is lower case alphanumeric
|
|
23
|
+
*
|
|
24
|
+
* @param str the string to check
|
|
25
|
+
*/
|
|
26
|
+
export function isLowerAlphanumeric(str) {
|
|
27
|
+
if (str) {
|
|
28
|
+
return /^[a-z0-9]+$/.test(str);
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Tests if a string is upper case alphanumeric.
|
|
34
|
+
*
|
|
35
|
+
* @param str the string to check
|
|
36
|
+
*/
|
|
37
|
+
export function isUpperAlphanumeric(str) {
|
|
38
|
+
if (str) {
|
|
39
|
+
return /^[A-Z0-9]+$/.test(str);
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Tests if a string is PascalCase.
|
|
45
|
+
*
|
|
46
|
+
* @param str the string to test
|
|
47
|
+
*/
|
|
48
|
+
export function isPascalCase(str) {
|
|
49
|
+
if (str) {
|
|
50
|
+
return /^[A-Z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$/.test(str);
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Tests if a string is camelCase.
|
|
56
|
+
*
|
|
57
|
+
* @param str the string to test
|
|
58
|
+
*/
|
|
59
|
+
export function isCamelCase(str) {
|
|
60
|
+
if (str) {
|
|
61
|
+
return /^[a-z][a-z0-9]*([A-Z][a-z0-9]*)*$/.test(str);
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Converts a string to snake_case
|
|
67
|
+
*
|
|
68
|
+
* @param str the string to convert
|
|
69
|
+
*/
|
|
70
|
+
export function toSnakeCase(str) {
|
|
71
|
+
return (str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) || [])
|
|
72
|
+
.map((x) => x.toLowerCase())
|
|
73
|
+
.join('_');
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Converts a string to kebab-case
|
|
77
|
+
*
|
|
78
|
+
* @param str the string to convert
|
|
79
|
+
*/
|
|
80
|
+
export function toKebabCase(str) {
|
|
81
|
+
return (str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) || [])
|
|
82
|
+
.map((x) => x.toLowerCase())
|
|
83
|
+
.join('-');
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Converts a string to camelCase.
|
|
87
|
+
*
|
|
88
|
+
* @param str the string to convert
|
|
89
|
+
*/
|
|
90
|
+
export function toCamelCase(str) {
|
|
91
|
+
str = toPascalCase(str);
|
|
92
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Converts a string to PascalCase.
|
|
96
|
+
*
|
|
97
|
+
* @param str the string to convert
|
|
98
|
+
*/
|
|
99
|
+
export function toPascalCase(str) {
|
|
100
|
+
return (str.match(/[a-zA-Z0-9]+/g) || [])
|
|
101
|
+
.map((x) => `${x.charAt(0).toUpperCase()}${x.slice(1)}`)
|
|
102
|
+
.join('');
|
|
103
|
+
}
|
|
4
104
|
//# sourceMappingURL=string.mjs.map
|
package/dist/lang/string.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.mjs","sourceRoot":"","sources":["../../src/lang/string.mts"],"names":[],"mappings":"AAAA,MAAM,UAAU,qBAAqB,CAAC,KAAa;IACjD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
1
|
+
{"version":3,"file":"string.mjs","sourceRoot":"","sources":["../../src/lang/string.mts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAa;IACjD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAqB;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAmB;IACrD,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAmB;IACrD,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,aAAa,CAAC,IAAI,CAAC,G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C,eAAe,CAAC,IAAI,EAAE,CAAC;SACtC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;SACvD,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nr1e/commons",
|
|
3
3
|
"description": "Common utilities for TypeScript projects",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "NR1E, Inc.",
|
|
7
7
|
"publishConfig": {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@eslint/js": "^9.39.
|
|
19
|
+
"@eslint/js": "^9.39.3",
|
|
20
20
|
"@types/node": "^24.10.13",
|
|
21
|
-
"eslint": "9.39.
|
|
21
|
+
"eslint": "9.39.3",
|
|
22
22
|
"prettier": "3.8.1",
|
|
23
23
|
"typescript": "5.9.3",
|
|
24
24
|
"typescript-eslint": "8.56.0",
|