Skip to content

Commit 017e141

Browse files
essential-randomnessMs Boba
authored andcommitted
Clean up capitalize titles
1 parent 9ffed2b commit 017e141

5 files changed

Lines changed: 471 additions & 352 deletions

File tree

remark-capitalize-titles/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ export default defineConfig({
3535
});
3636
```
3737

38+
## Title-casing a string directly
39+
40+
To title-case a string outside a Markdown tree, use the exported
41+
`capitalizeTitle` function:
42+
43+
```ts
44+
import { capitalizeTitle } from "@fujocoded/remark-capitalize-titles";
45+
46+
capitalizeTitle("merging with github via npm");
47+
// => "Merging with GitHub via NPM"
48+
49+
// Override the capitalization exceptions:
50+
capitalizeTitle("my title", { special: ["MyBrand"] });
51+
```
52+
53+
The default exception list is exported as `DEFAULT_CAPITALIZATIONS`.
54+
3855
### TODOs:
3956

4057
- [ ] Fix issue where a title in a heading that has a previous sibling will be capitalized as if the first
Lines changed: 108 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,113 @@
1-
export const DEFAULT_CAPITALIZATIONS = [
1+
// Brand and product names with non-standard internal casing.
2+
const FUJOCODED = ["FujoCoded", "FujoWebDev", "FujoGuide"];
3+
4+
const PROGRAMMING = [
25
"GitHub",
3-
"FujoCoded",
4-
"LLC",
5-
"FujoWebDev",
6-
"FujoGuide",
7-
"NPM",
86
"NodeJS",
7+
"JavaScript",
98
"SHA",
109
"SHAs",
11-
"Next Up",
12-
"Mean To",
13-
"About",
14-
"Through",
15-
"Along",
16-
"TL;DR",
10+
"NPM",
11+
"HTML",
12+
"CSS",
13+
];
14+
15+
// Acronyms and initialisms that should stay fully uppercase.
16+
const ACRONYMS = ["LLC", "TL;DR"];
17+
18+
// Small words and phrases FujoCoded force-caps even though AP-style rules would
19+
// normally lowercase them mid-title.
20+
const FORCED_PHRASES = ["Next Up", "Mean To", "About", "Through", "Along"];
21+
22+
// FORCED exact casing. Applied as a post-pass where every occurrence is
23+
// rewritten to this exact string, regardless of position.
24+
export const DEFAULT_CAPITALIZATIONS = [
25+
...FUJOCODED,
26+
...PROGRAMMING,
27+
...ACRONYMS,
28+
...FORCED_PHRASES,
1729
];
30+
31+
// STAY lowercase mid-title only. Articles, conjunctions, and prepositions that
32+
// the casing pass keeps lowercase *except* when first word, last word, or after
33+
// hard-cap punctuation.
34+
// Sourced from the same set as `vercel/title`.
35+
export const SMALL_WORDS = new Set([
36+
"a",
37+
"an",
38+
"the",
39+
"aboard",
40+
"about",
41+
"above",
42+
"across",
43+
"after",
44+
"against",
45+
"along",
46+
"amid",
47+
"among",
48+
"anti",
49+
"around",
50+
"as",
51+
"at",
52+
"before",
53+
"behind",
54+
"and",
55+
"but",
56+
"or",
57+
"nor",
58+
"for",
59+
"yet",
60+
"so",
61+
"below",
62+
"beneath",
63+
"beside",
64+
"besides",
65+
"between",
66+
"beyond",
67+
"by",
68+
"concerning",
69+
"considering",
70+
"despite",
71+
"down",
72+
"during",
73+
"except",
74+
"excepting",
75+
"excluding",
76+
"following",
77+
"from",
78+
"in",
79+
"inside",
80+
"into",
81+
"like",
82+
"minus",
83+
"near",
84+
"of",
85+
"off",
86+
"on",
87+
"onto",
88+
"opposite",
89+
"over",
90+
"past",
91+
"per",
92+
"plus",
93+
"regarding",
94+
"round",
95+
"save",
96+
"since",
97+
"than",
98+
"through",
99+
"to",
100+
"toward",
101+
"towards",
102+
"under",
103+
"underneath",
104+
"unlike",
105+
"until",
106+
"up",
107+
"upon",
108+
"versus",
109+
"via",
110+
"with",
111+
"within",
112+
"without",
113+
]);

0 commit comments

Comments
 (0)