@nr1e/commons 0.3.0 → 0.3.1
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/currency.d.mts +10 -0
- package/dist/lang/currency.d.mts.map +1 -0
- package/dist/lang/currency.mjs +16 -0
- package/dist/lang/currency.mjs.map +1 -0
- package/dist/lang/datetime.d.mts +21 -0
- package/dist/lang/datetime.d.mts.map +1 -1
- package/dist/lang/datetime.mjs +44 -0
- package/dist/lang/datetime.mjs.map +1 -1
- package/dist/lang/index.d.mts +1 -0
- package/dist/lang/index.d.mts.map +1 -1
- package/dist/lang/index.mjs +1 -0
- package/dist/lang/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a currency amount using the Intl.NumberFormat API
|
|
3
|
+
*
|
|
4
|
+
* @param amount - The amount in cents (e.g., 1000 for $10.00) as number or string
|
|
5
|
+
* @param currency - The currency code (e.g., 'USD', 'EUR')
|
|
6
|
+
* @param locale - The locale to use (e.g., 'en-US', 'fr-FR') - defaults to 'en-US'
|
|
7
|
+
* @returns Formatted currency string
|
|
8
|
+
*/
|
|
9
|
+
export declare const formatCurrency: (amount: number | string, currency: string, locale?: string) => string;
|
|
10
|
+
//# sourceMappingURL=currency.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.d.mts","sourceRoot":"","sources":["../../src/lang/currency.mts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,WACjB,MAAM,GAAG,MAAM,YACb,MAAM,WACP,MAAM,KACd,MAOF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a currency amount using the Intl.NumberFormat API
|
|
3
|
+
*
|
|
4
|
+
* @param amount - The amount in cents (e.g., 1000 for $10.00) as number or string
|
|
5
|
+
* @param currency - The currency code (e.g., 'USD', 'EUR')
|
|
6
|
+
* @param locale - The locale to use (e.g., 'en-US', 'fr-FR') - defaults to 'en-US'
|
|
7
|
+
* @returns Formatted currency string
|
|
8
|
+
*/
|
|
9
|
+
export const formatCurrency = (amount, currency, locale) => {
|
|
10
|
+
const numericAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
|
|
11
|
+
return new Intl.NumberFormat(locale ?? 'en-US', {
|
|
12
|
+
style: 'currency',
|
|
13
|
+
currency: currency.toUpperCase(),
|
|
14
|
+
}).format(numericAmount);
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=currency.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.mjs","sourceRoot":"","sources":["../../src/lang/currency.mts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,MAAuB,EACvB,QAAgB,EAChB,MAAe,EACP,EAAE;IACV,MAAM,aAAa,GACjB,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC3D,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,IAAI,OAAO,EAAE;QAC9C,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,QAAQ,CAAC,WAAW,EAAE;KACjC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AAC3B,CAAC,CAAC"}
|
package/dist/lang/datetime.d.mts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
1
|
export declare function isoDateToFormattedUtc(isoDate: string): string;
|
|
2
2
|
export declare function formatDate(date: Date): string;
|
|
3
|
+
/**
|
|
4
|
+
* Formats a date and time to a human-readable string with time zone.
|
|
5
|
+
* @param date - Date string or Date object to format.
|
|
6
|
+
* @param locale - The locale to use (e.g., 'en-US', 'fr-FR') - defaults to 'en-US'
|
|
7
|
+
* @returns Formatted date string (e.g., "June 14, 2023 12:00 PM MST").
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatDateTimeReadable(date: string | Date, locale?: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Formats a date to "Jun 30, 2025" style using the local time zone.
|
|
12
|
+
* Accepts a Date object or a string parseable by Date.
|
|
13
|
+
* @param date - Date string or Date object to format.
|
|
14
|
+
* @param locale - The locale to use (e.g., 'en-US', 'fr-FR') - defaults to 'en-US'
|
|
15
|
+
* @returns Formatted date string like "Jun 30, 2025".
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatDateShort(date: string | Date, locale?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Calculates the number of days between a given date and the current date.
|
|
20
|
+
* @param date - The date to calculate from.
|
|
21
|
+
* @returns The number of days that have passed since the given date.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDaysSince(date: string | Date): number;
|
|
3
24
|
//# sourceMappingURL=datetime.d.mts.map
|
|
@@ -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,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAO7C"}
|
|
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,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAO7C;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAWR;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAO5E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAKxD"}
|
package/dist/lang/datetime.mjs
CHANGED
|
@@ -32,4 +32,48 @@ export function formatDate(date) {
|
|
|
32
32
|
};
|
|
33
33
|
return new Intl.DateTimeFormat('en-US', options).format(date);
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Formats a date and time to a human-readable string with time zone.
|
|
37
|
+
* @param date - Date string or Date object to format.
|
|
38
|
+
* @param locale - The locale to use (e.g., 'en-US', 'fr-FR') - defaults to 'en-US'
|
|
39
|
+
* @returns Formatted date string (e.g., "June 14, 2023 12:00 PM MST").
|
|
40
|
+
*/
|
|
41
|
+
export function formatDateTimeReadable(date, locale) {
|
|
42
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
43
|
+
return new Intl.DateTimeFormat(locale ?? 'en-US', {
|
|
44
|
+
year: 'numeric',
|
|
45
|
+
month: 'long',
|
|
46
|
+
day: 'numeric',
|
|
47
|
+
hour: 'numeric',
|
|
48
|
+
minute: '2-digit',
|
|
49
|
+
hour12: true,
|
|
50
|
+
timeZoneName: 'short',
|
|
51
|
+
}).format(dateObj);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Formats a date to "Jun 30, 2025" style using the local time zone.
|
|
55
|
+
* Accepts a Date object or a string parseable by Date.
|
|
56
|
+
* @param date - Date string or Date object to format.
|
|
57
|
+
* @param locale - The locale to use (e.g., 'en-US', 'fr-FR') - defaults to 'en-US'
|
|
58
|
+
* @returns Formatted date string like "Jun 30, 2025".
|
|
59
|
+
*/
|
|
60
|
+
export function formatDateShort(date, locale) {
|
|
61
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
62
|
+
return new Intl.DateTimeFormat(locale ?? 'en-US', {
|
|
63
|
+
year: 'numeric',
|
|
64
|
+
month: 'short',
|
|
65
|
+
day: 'numeric',
|
|
66
|
+
}).format(dateObj);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Calculates the number of days between a given date and the current date.
|
|
70
|
+
* @param date - The date to calculate from.
|
|
71
|
+
* @returns The number of days that have passed since the given date.
|
|
72
|
+
*/
|
|
73
|
+
export function getDaysSince(date) {
|
|
74
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
75
|
+
const now = new Date();
|
|
76
|
+
const diffTime = now.getTime() - dateObj.getTime();
|
|
77
|
+
return Math.floor(diffTime / (1000 * 60 * 60 * 24));
|
|
78
|
+
}
|
|
35
79
|
//# sourceMappingURL=datetime.mjs.map
|
|
@@ -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,UA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AAC,CAAC,IAAI,CAAC;IACjE,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,IAAI,OAAO,EAAE;QAChD,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,OAAO;QACd,GAAG,EAAE,SAAS;KACf,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACrB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAmB;IAC9C,MAAM,OAAO,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IACnD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;AACtD,CAAC"}
|
package/dist/lang/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/lang/index.mts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/lang/index.mts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
|
package/dist/lang/index.mjs
CHANGED
package/dist/lang/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/lang/index.mts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/lang/index.mts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
|