Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions text/title_case_mapping.json → text/_title_case_mapping.ts
Original file line number Diff line number Diff line change
@@ -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<string, string> = {
"ß": "Ss",
"DŽ": "Dž",
"Dž": "Dž",
Expand Down Expand Up @@ -133,5 +142,5 @@
"ﬔ": "Մե",
"ﬕ": "Մի",
"ﬖ": "Վն",
"ﬗ": "Մխ"
}
"ﬗ": "Մխ",
};
4 changes: 2 additions & 2 deletions text/_title_case_util.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
23 changes: 21 additions & 2 deletions text/_tools/generate_title_case_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
`;

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,
);
Loading