mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-10-24 12:13:31 +08:00
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> --------- Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
25 lines
763 B
TypeScript
25 lines
763 B
TypeScript
import preFormattedBlockNames from './preformatted-block-names.json';
|
|
import preFormattedWords from './preformatted-words.json';
|
|
|
|
const noFormatting = ['and', 'for', 'of', 'the', 'up', 'with', 'to', 'by', 'a'];
|
|
|
|
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 ((preFormattedWords as Record<string, string>)[word]) {
|
|
return (preFormattedWords as Record<string, string>)[word];
|
|
}
|
|
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
})
|
|
.join(' ');
|
|
}
|