Skip to content

Commit 954533a

Browse files
fix: treeshaking clock tokens (#37)
1 parent 1fb0f03 commit 954533a

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/common.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ export const genitiveTokens = ["MMMM", "MMM", "dddd", "ddd"]
102102
/**
103103
* A map of FormatPattern tuples to their respective token.
104104
*/
105-
export const tokens = new Map(
106-
[...clockAgnostic, ...clock24, ...clock12].map((format) => {
105+
export const tokens = /* @__PURE__ */ new Map(
106+
/* @__PURE__ */ [...clockAgnostic, ...clock24, ...clock12].map((format) => {
107107
return [format[0], format]
108-
}),
108+
})
109109
)
110110

111111
/**
@@ -139,7 +139,7 @@ export const four = (n: number) => String(n).padStart(2, "0")
139139
* @param part - The part to normalize.
140140
*/
141141
export function normStr(
142-
part: Intl.DateTimeFormatPart,
142+
part: Intl.DateTimeFormatPart
143143
): Intl.DateTimeFormatPart {
144144
if (part.type === "literal") {
145145
part.value = part.value.normalize("NFKC")
@@ -160,7 +160,7 @@ export function fill(
160160
parts: Part[],
161161
locale: string,
162162
genitive = false,
163-
offset: string | null = null,
163+
offset: string | null = null
164164
): FilledPart[] {
165165
const partMap = createPartMap(inputDate, parts, locale, genitive)
166166
const d = date(inputDate)
@@ -213,7 +213,7 @@ function createPartMap(
213213
inputDate: DateInput,
214214
parts: Part[],
215215
locale: string,
216-
genitive = false,
216+
genitive = false
217217
): Record<keyof Intl.DateTimeFormatPartTypesRegistry, string> {
218218
const d = date(inputDate)
219219
const hour12 = parts.filter((part) => part.hour12)
@@ -239,7 +239,7 @@ function createPartMap(
239239
)
240240
)
241241
.formatToParts(d)
242-
.map(normStr),
242+
.map(normStr)
243243
)
244244
if (genitive && genitiveParts.length) {
245245
for (const part of genitiveParts) {
@@ -263,7 +263,7 @@ function createPartMap(
263263
break
264264
}
265265
const genitiveFormattedPart = formattedParts.find(
266-
(p) => p.type === part.partName,
266+
(p) => p.type === part.partName
267267
)
268268
const index = valueParts.findIndex((p) => p.type === part.partName)
269269
if (genitiveFormattedPart && index > -1) {
@@ -276,13 +276,10 @@ function createPartMap(
276276
if (hour12.length) addValues(hour12, true)
277277
if (hour24.length) addValues(hour24)
278278

279-
return valueParts.reduce(
280-
(map, part) => {
281-
map[part.type] = part.value
282-
return map
283-
},
284-
{} as Record<keyof Intl.DateTimeFormatPartTypesRegistry, string>,
285-
)
279+
return valueParts.reduce((map, part) => {
280+
map[part.type] = part.value
281+
return map
282+
}, {} as Record<keyof Intl.DateTimeFormatPartTypesRegistry, string>)
286283
}
287284

288285
/**
@@ -293,7 +290,7 @@ function createPartMap(
293290
export function minsToOffset(timeDiffInMins: number): string {
294291
const hours = String(Math.floor(Math.abs(timeDiffInMins / 60))).padStart(
295292
2,
296-
"0",
293+
"0"
297294
)
298295
const mins = String(Math.abs(timeDiffInMins % 60)).padStart(2, "0")
299296
const sign = timeDiffInMins < 0 ? "-" : "+"
@@ -366,7 +363,7 @@ export function validate(parts: Part[]): Part[] | never {
366363
!(isNumeric(lastPart) && part.token.toLowerCase() === "a")
367364
) {
368365
throw new Error(
369-
`Illegal adjacent tokens (${lastPart.token}, ${part.token})`,
366+
`Illegal adjacent tokens (${lastPart.token}, ${part.token})`
370367
)
371368
}
372369
}

0 commit comments

Comments
 (0)