mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-02-03 09:04:13 -05:00
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>
24 lines
624 B
TypeScript
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(' ');
|
|
}
|