@zag-js/i18n-utils 1.35.2 → 1.35.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/format-time.d.mts +3 -6
- package/dist/format-time.d.ts +3 -6
- package/dist/format-time.js +7 -3
- package/dist/format-time.mjs +7 -3
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +2 -2
package/dist/format-time.d.mts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
type TimeFormat = "12h" | "24h";
|
|
2
|
-
interface AmPmLabels {
|
|
3
|
-
am: string;
|
|
4
|
-
pm: string;
|
|
5
|
-
}
|
|
6
2
|
interface FormatTimeOptions {
|
|
7
3
|
format?: TimeFormat;
|
|
8
|
-
|
|
4
|
+
amLabel?: string;
|
|
5
|
+
pmLabel?: string;
|
|
9
6
|
withSeconds?: boolean;
|
|
10
7
|
}
|
|
11
8
|
declare function formatTime(value: string | Date, locale: string, options?: FormatTimeOptions): string | null;
|
|
12
9
|
|
|
13
|
-
export { type
|
|
10
|
+
export { type FormatTimeOptions, type TimeFormat, formatTime };
|
package/dist/format-time.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
type TimeFormat = "12h" | "24h";
|
|
2
|
-
interface AmPmLabels {
|
|
3
|
-
am: string;
|
|
4
|
-
pm: string;
|
|
5
|
-
}
|
|
6
2
|
interface FormatTimeOptions {
|
|
7
3
|
format?: TimeFormat;
|
|
8
|
-
|
|
4
|
+
amLabel?: string;
|
|
5
|
+
pmLabel?: string;
|
|
9
6
|
withSeconds?: boolean;
|
|
10
7
|
}
|
|
11
8
|
declare function formatTime(value: string | Date, locale: string, options?: FormatTimeOptions): string | null;
|
|
12
9
|
|
|
13
|
-
export { type
|
|
10
|
+
export { type FormatTimeOptions, type TimeFormat, formatTime };
|
package/dist/format-time.js
CHANGED
|
@@ -55,7 +55,7 @@ function getTimeParts(value) {
|
|
|
55
55
|
return { date, hours, minutes, seconds: seconds ?? 0 };
|
|
56
56
|
}
|
|
57
57
|
function formatTime(value, locale, options = {}) {
|
|
58
|
-
const { format = "24h",
|
|
58
|
+
const { format = "24h", amLabel, pmLabel, withSeconds = false } = options;
|
|
59
59
|
const parts = getTimeParts(value);
|
|
60
60
|
if (!parts) return null;
|
|
61
61
|
const formatter = getTimeFormatter(locale, {
|
|
@@ -64,12 +64,16 @@ function formatTime(value, locale, options = {}) {
|
|
|
64
64
|
second: withSeconds ? "2-digit" : void 0,
|
|
65
65
|
hour12: format === "12h"
|
|
66
66
|
});
|
|
67
|
-
if (format !== "12h"
|
|
67
|
+
if (format !== "12h") {
|
|
68
68
|
return formatter.format(parts.date);
|
|
69
69
|
}
|
|
70
70
|
const isPm = parts.hours >= 12;
|
|
71
71
|
const tokens = formatter.formatToParts(parts.date);
|
|
72
|
-
return tokens.map((token) =>
|
|
72
|
+
return tokens.map((token) => {
|
|
73
|
+
if (token.type !== "dayPeriod") return token.value;
|
|
74
|
+
if (isPm) return pmLabel ?? token.value;
|
|
75
|
+
return amLabel ?? token.value;
|
|
76
|
+
}).join("");
|
|
73
77
|
}
|
|
74
78
|
// Annotate the CommonJS export names for ESM import in node:
|
|
75
79
|
0 && (module.exports = {
|
package/dist/format-time.mjs
CHANGED
|
@@ -31,7 +31,7 @@ function getTimeParts(value) {
|
|
|
31
31
|
return { date, hours, minutes, seconds: seconds ?? 0 };
|
|
32
32
|
}
|
|
33
33
|
function formatTime(value, locale, options = {}) {
|
|
34
|
-
const { format = "24h",
|
|
34
|
+
const { format = "24h", amLabel, pmLabel, withSeconds = false } = options;
|
|
35
35
|
const parts = getTimeParts(value);
|
|
36
36
|
if (!parts) return null;
|
|
37
37
|
const formatter = getTimeFormatter(locale, {
|
|
@@ -40,12 +40,16 @@ function formatTime(value, locale, options = {}) {
|
|
|
40
40
|
second: withSeconds ? "2-digit" : void 0,
|
|
41
41
|
hour12: format === "12h"
|
|
42
42
|
});
|
|
43
|
-
if (format !== "12h"
|
|
43
|
+
if (format !== "12h") {
|
|
44
44
|
return formatter.format(parts.date);
|
|
45
45
|
}
|
|
46
46
|
const isPm = parts.hours >= 12;
|
|
47
47
|
const tokens = formatter.formatToParts(parts.date);
|
|
48
|
-
return tokens.map((token) =>
|
|
48
|
+
return tokens.map((token) => {
|
|
49
|
+
if (token.type !== "dayPeriod") return token.value;
|
|
50
|
+
if (isPm) return pmLabel ?? token.value;
|
|
51
|
+
return amLabel ?? token.value;
|
|
52
|
+
}).join("");
|
|
49
53
|
}
|
|
50
54
|
export {
|
|
51
55
|
formatTime
|
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ export { formatDate } from './format-date.mjs';
|
|
|
5
5
|
export { formatList } from './format-list.mjs';
|
|
6
6
|
export { formatNumber } from './format-number.mjs';
|
|
7
7
|
export { formatRelativeTime } from './format-relative-time.mjs';
|
|
8
|
-
export {
|
|
8
|
+
export { FormatTimeOptions, TimeFormat, formatTime } from './format-time.mjs';
|
|
9
9
|
export { getLocaleDir, isRTL } from './is-rtl.mjs';
|
|
10
10
|
export { Locale, getDefaultLocale } from './locale.mjs';
|
|
11
11
|
export { LocaleOptions, trackLocale } from './track-locale.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { formatDate } from './format-date.js';
|
|
|
5
5
|
export { formatList } from './format-list.js';
|
|
6
6
|
export { formatNumber } from './format-number.js';
|
|
7
7
|
export { formatRelativeTime } from './format-relative-time.js';
|
|
8
|
-
export {
|
|
8
|
+
export { FormatTimeOptions, TimeFormat, formatTime } from './format-time.js';
|
|
9
9
|
export { getLocaleDir, isRTL } from './is-rtl.js';
|
|
10
10
|
export { Locale, getDefaultLocale } from './locale.js';
|
|
11
11
|
export { LocaleOptions, trackLocale } from './track-locale.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/i18n-utils",
|
|
3
|
-
"version": "1.35.
|
|
3
|
+
"version": "1.35.3",
|
|
4
4
|
"description": "Interationalization utilities for Zag.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"clean-package": "../../../clean-package.config.json",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@zag-js/dom-query": "1.35.
|
|
27
|
+
"@zag-js/dom-query": "1.35.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"clean-package": "2.2.0",
|