2021-06-08 19:27:45 +00:00
|
|
|
const preFormattedBlockNames = require('./preformatted-block-names.json');
|
2018-04-06 13:51:52 +00:00
|
|
|
|
2018-04-17 14:24:17 +00:00
|
|
|
const noFormatting = ['and', 'for', 'of', 'the', 'up', 'with'];
|
2018-04-06 13:51:52 +00:00
|
|
|
|
|
|
|
exports.blockNameify = function blockNameify(phrase) {
|
|
|
|
const preFormatted = preFormattedBlockNames[phrase] || '';
|
|
|
|
if (preFormatted) {
|
|
|
|
return preFormatted;
|
|
|
|
}
|
2018-04-17 14:24:17 +00:00
|
|
|
return phrase
|
|
|
|
.split('-')
|
|
|
|
.map(word => {
|
2018-04-06 13:51:52 +00:00
|
|
|
if (noFormatting.indexOf(word) !== -1) {
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
if (word === 'javascript') {
|
|
|
|
return 'JavaScript';
|
|
|
|
}
|
|
|
|
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
|
|
})
|
|
|
|
.join(' ');
|
|
|
|
};
|