Files
freeCodeCamp/utils/block-nameify.ts
Sem Bauke 87d9ade1a7 fix(curriculum,client): move the Euler Project to its own superBlock (#49294)
Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com>
Co-authored-by: moT01 <20648924+moT01@users.noreply.github.com>
2023-03-23 21:29:13 +05:30

24 lines
624 B
TypeScript

import preFormattedBlockNames from './preformatted-block-names.json';
const noFormatting = ['and', 'for', 'of', 'the', 'up', 'with', 'to'];
export function blockNameify(phrase: string): string {
const preFormatted =
(preFormattedBlockNames as Record<string, string>)[phrase] || '';
if (preFormatted) {
return preFormatted;
}
return phrase
.split('-')
.map(word => {
if (noFormatting.indexOf(word) !== -1) {
return word;
}
if (word === 'javascript') {
return 'JavaScript';
}
return word.charAt(0).toUpperCase() + word.slice(1);
})
.join(' ');
}