Files
freeCodeCamp/utils/block-nameify.js
Oliver Eyton-Williams bd4d46915a feat(curriculum): add project creation tool (#42410)
* refactor: extract help category map as JSON

* refactor: extract block names as json

* feat: add create-project script

* fix: correct case for tsconfig target

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
2021-06-09 00:57:45 +05:30

23 lines
592 B
JavaScript

const preFormattedBlockNames = require('./preformatted-block-names.json');
const noFormatting = ['and', 'for', 'of', 'the', 'up', 'with'];
exports.blockNameify = function blockNameify(phrase) {
const preFormatted = preFormattedBlockNames[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(' ');
};