Skip to content

Commit

Permalink
guh
Browse files Browse the repository at this point in the history
  • Loading branch information
katsaii committed Mar 18, 2024
1 parent f4ad41a commit 5523cd7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 0 additions & 1 deletion case-convert.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<i>typical</i>
<button onclick="toLower()">lower case</button>
<button onclick="toUpper()">UPPER CASE</button>
<button onclick="toSentence()">Sentence case</button>
<button onclick="toTitle()">Title Case</button>
<button onclick="toCapitalised()">Capitalised Case</button>
<hr>
Expand Down
20 changes: 19 additions & 1 deletion case-convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ const toLower = caseConverter({
visit : (_, value) => value.toLowerCase(),
});

const titleArticles = { "the" : "the", "a" : "a", "an" : "an" };
const toTitle = () => {
let isFirst = true;
return (caseConverter({
visit : (_, value) => {
let valueArticle = titleArticles[value.toLowerCase()];
value = valueArticle ?? value;
let capitalise = isFirst || valueArticle == undefined;
isFirst = false;
if (capitalise) {
return value[0].toUpperCase() + value.slice(1);
} else {
return value;
}
},
}))();
};

const toCapitalised = caseConverter({
visit : (_, value) => value[0].toUpperCase() + value.slice(1),
});
Expand Down Expand Up @@ -117,7 +135,7 @@ const leetDigits = {
"e" : "3", "a" : "4", "s" : "5",
// nothing for the number 6
"t" : "7", "b" : "8", "g" : "9",
}
};
const toBasic1337 = caseConverter({
visit : (_, value) => sobStringToChars(value)
.map((chr) => leetDigits[chr.toLowerCase()] ?? chr)
Expand Down

0 comments on commit 5523cd7

Please sign in to comment.