Skip to content

Commit d84b0ed

Browse files
fix(text): inline title case mapping to avoid JSON import attribute (#7129)
1 parent 92d3075 commit d84b0ed

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
{
1+
// Copyright 2018-2026 the Deno authors. MIT license.
2+
// This module is browser compatible.
3+
4+
// This data is generated from the Unicode Character Database. See
5+
// `_tools/generate_title_case_data.ts` for the generation script. The mapping
6+
// is inlined as a TypeScript module rather than imported from JSON so that
7+
// bundlers (notably Vite) that don't handle JSON imports from JSR correctly
8+
// can still consume the module. See https://github.com/denoland/std/issues/7128.
9+
10+
export const titleCaseMapping: Record<string, string> = {
211
"ß": "Ss",
312
"DŽ": "Dž",
413
"Dž": "Dž",
@@ -133,5 +142,5 @@
133142
"ﬔ": "Մե",
134143
"ﬕ": "Մի",
135144
"ﬖ": "Վն",
136-
"ﬗ": "Մխ"
137-
}
145+
"ﬗ": "Մխ",
146+
};

text/_title_case_util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
22
// This module is browser compatible.
3-
import _titleCaseMapping from "./title_case_mapping.json" with { type: "json" };
4-
const titleCaseMap = new Map(Object.entries(_titleCaseMapping));
3+
import { titleCaseMapping } from "./_title_case_mapping.ts";
4+
const titleCaseMap = new Map(Object.entries(titleCaseMapping));
55

66
/** The case for the remaining characters in the string */
77
export type TrailingCase = "lower" | "unchanged";

text/_tools/generate_title_case_data.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,26 @@ for (let i = 0; i < 0x110000; i++) {
8686
}
8787
}
8888

89+
const HEADER = `\
90+
// Copyright 2018-${new Date().getFullYear()} the Deno authors. MIT license.
91+
// This module is browser compatible.
92+
93+
// This data is generated from the Unicode Character Database. See
94+
// \`_tools/generate_title_case_data.ts\` for the generation script. The mapping
95+
// is inlined as a TypeScript module rather than imported from JSON so that
96+
// bundlers (notably Vite) that don't handle JSON imports from JSR correctly
97+
// can still consume the module. See https://github.com/denoland/std/issues/7128.
98+
99+
export const titleCaseMapping: Record<string, string> = {
100+
`;
101+
102+
const FOOTER = "};\n";
103+
104+
const entries = Object.entries(data)
105+
.map(([k, v]) => ` ${JSON.stringify(k)}: ${JSON.stringify(v)},\n`)
106+
.join("");
107+
89108
await Deno.writeTextFile(
90-
new URL(import.meta.resolve("../title_case_mapping.json")),
91-
JSON.stringify(data, null, 2) + "\n",
109+
new URL(import.meta.resolve("../_title_case_mapping.ts")),
110+
HEADER + entries + FOOTER,
92111
);

0 commit comments

Comments
 (0)