diff --git a/text/title_case_mapping.json b/text/_title_case_mapping.ts similarity index 79% rename from text/title_case_mapping.json rename to text/_title_case_mapping.ts index 114c6793e9bd..b02931163c0f 100644 --- a/text/title_case_mapping.json +++ b/text/_title_case_mapping.ts @@ -1,4 +1,13 @@ -{ +// Copyright 2018-2026 the Deno authors. MIT license. +// This module is browser compatible. + +// This data is generated from the Unicode Character Database. See +// `_tools/generate_title_case_data.ts` for the generation script. The mapping +// is inlined as a TypeScript module rather than imported from JSON so that +// bundlers (notably Vite) that don't handle JSON imports from JSR correctly +// can still consume the module. See https://github.com/denoland/std/issues/7128. + +export const titleCaseMapping: Record = { "ß": "Ss", "DŽ": "Dž", "Dž": "Dž", @@ -133,5 +142,5 @@ "ﬔ": "Մե", "ﬕ": "Մի", "ﬖ": "Վն", - "ﬗ": "Մխ" -} + "ﬗ": "Մխ", +}; diff --git a/text/_title_case_util.ts b/text/_title_case_util.ts index 74960ed6072d..efb1ed862c2b 100644 --- a/text/_title_case_util.ts +++ b/text/_title_case_util.ts @@ -1,7 +1,7 @@ // Copyright 2018-2026 the Deno authors. MIT license. // This module is browser compatible. -import _titleCaseMapping from "./title_case_mapping.json" with { type: "json" }; -const titleCaseMap = new Map(Object.entries(_titleCaseMapping)); +import { titleCaseMapping } from "./_title_case_mapping.ts"; +const titleCaseMap = new Map(Object.entries(titleCaseMapping)); /** The case for the remaining characters in the string */ export type TrailingCase = "lower" | "unchanged"; diff --git a/text/_tools/generate_title_case_data.ts b/text/_tools/generate_title_case_data.ts index dcaa2d9a4048..7c0b620802cd 100755 --- a/text/_tools/generate_title_case_data.ts +++ b/text/_tools/generate_title_case_data.ts @@ -86,7 +86,26 @@ for (let i = 0; i < 0x110000; i++) { } } +const HEADER = `\ +// Copyright 2018-${new Date().getFullYear()} the Deno authors. MIT license. +// This module is browser compatible. + +// This data is generated from the Unicode Character Database. See +// \`_tools/generate_title_case_data.ts\` for the generation script. The mapping +// is inlined as a TypeScript module rather than imported from JSON so that +// bundlers (notably Vite) that don't handle JSON imports from JSR correctly +// can still consume the module. See https://github.com/denoland/std/issues/7128. + +export const titleCaseMapping: Record = { +`; + +const FOOTER = "};\n"; + +const entries = Object.entries(data) + .map(([k, v]) => ` ${JSON.stringify(k)}: ${JSON.stringify(v)},\n`) + .join(""); + await Deno.writeTextFile( - new URL(import.meta.resolve("../title_case_mapping.json")), - JSON.stringify(data, null, 2) + "\n", + new URL(import.meta.resolve("../_title_case_mapping.ts")), + HEADER + entries + FOOTER, );