Fixed title casing
This commit is contained in:
60
write.ts
60
write.ts
@@ -1,65 +1,7 @@
|
||||
import { VideoDescription } from "./main.ts";
|
||||
import { camelToTitleCase } from "./util_string.ts";
|
||||
|
||||
|
||||
export const SMALL_WORDS = new Set([
|
||||
"a",
|
||||
"an",
|
||||
"and",
|
||||
"as",
|
||||
"at",
|
||||
"because",
|
||||
"but",
|
||||
"by",
|
||||
"en",
|
||||
"for",
|
||||
"if",
|
||||
"in",
|
||||
"neither",
|
||||
"nor",
|
||||
"of",
|
||||
"on",
|
||||
"only",
|
||||
"or",
|
||||
"over",
|
||||
"per",
|
||||
"so",
|
||||
"some",
|
||||
"than",
|
||||
"that",
|
||||
"the",
|
||||
"to",
|
||||
"up",
|
||||
"upon",
|
||||
"v",
|
||||
"versus",
|
||||
"via",
|
||||
"vs",
|
||||
"when",
|
||||
"with",
|
||||
"without",
|
||||
"yet",
|
||||
]);
|
||||
|
||||
function capitalize(word: string): string {
|
||||
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
||||
}
|
||||
|
||||
function camelToTitleCase(camelCaseStr: string): string {
|
||||
// Insert a space before each uppercase letter
|
||||
const titleCaseStr = camelCaseStr.replace(/([A-Z])/g, ' $1');
|
||||
|
||||
// Split the string into words and process each word using map
|
||||
const words = titleCaseStr.split(' ')
|
||||
.map(v => v.toLowerCase())
|
||||
.map(word => {
|
||||
if (SMALL_WORDS.has(word)) {
|
||||
return word;
|
||||
}
|
||||
return capitalize(word)
|
||||
});
|
||||
|
||||
return capitalize(words.join(' '));
|
||||
}
|
||||
|
||||
export function singleVideoDescription(video: VideoDescription): string {
|
||||
const teachersList = video.teachers.map(v => "[[" + v + "]]").join(" & ");
|
||||
|
||||
Reference in New Issue
Block a user