mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
chore: improve block namify (#49950)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> --------- Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
@@ -6,9 +6,14 @@ describe('blockNameify', () => {
|
||||
expect(result).toBe('Back End Development and APIs');
|
||||
});
|
||||
|
||||
it('should use preformatted words when they exist', () => {
|
||||
const result = blockNameify('html-css-javascript-fcc-freecodecamp');
|
||||
expect(result).toBe('HTML CSS JavaScript fCC freeCodeCamp');
|
||||
});
|
||||
|
||||
it('should not format prepositions', () => {
|
||||
const result = blockNameify('and-for-of-the-up-with');
|
||||
expect(result).toBe('and for of the up with');
|
||||
const result = blockNameify('and-for-of-the-up-with-by-a');
|
||||
expect(result).toBe('and for of the up with by a');
|
||||
});
|
||||
|
||||
it('should format javascript to JavaScript', () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import preFormattedBlockNames from './preformatted-block-names.json';
|
||||
import preFormattedWords from './preformatted-words.json';
|
||||
|
||||
const noFormatting = ['and', 'for', 'of', 'the', 'up', 'with', 'to'];
|
||||
const noFormatting = ['and', 'for', 'of', 'the', 'up', 'with', 'to', 'by', 'a'];
|
||||
|
||||
export function blockNameify(phrase: string): string {
|
||||
const preFormatted =
|
||||
@@ -14,8 +15,8 @@ export function blockNameify(phrase: string): string {
|
||||
if (noFormatting.indexOf(word) !== -1) {
|
||||
return word;
|
||||
}
|
||||
if (word === 'javascript') {
|
||||
return 'JavaScript';
|
||||
if ((preFormattedWords as Record<string, string>)[word]) {
|
||||
return (preFormattedWords as Record<string, string>)[word];
|
||||
}
|
||||
return word.charAt(0).toUpperCase() + word.slice(1);
|
||||
})
|
||||
|
||||
@@ -16,25 +16,9 @@
|
||||
"javascript-spreadsheet": "JavaScript Spreadsheet",
|
||||
"jquery": "jQuery",
|
||||
"json-apis-and-ajax": "JSON APIs and Ajax",
|
||||
"learn-accessibility-by-building-a-quiz": "Learn Accessibility by Building a Quiz",
|
||||
"learn-basic-css-by-building-a-cafe-menu": "Learn Basic CSS by Building a Cafe Menu",
|
||||
"learn-css-animation-by-building-a-ferris-wheel": "Learn CSS Animation by Building a Ferris Wheel",
|
||||
"learn-css-flexbox-by-building-a-photo-gallery": "Learn CSS Flexbox by Building a Photo Gallery",
|
||||
"learn-css-grid-by-building-a-magazine": "Learn CSS Grid by Building a Magazine",
|
||||
"learn-css-transforms-by-building-a-penguin": "Learn CSS Transforms by Building a Penguin",
|
||||
"learn-css-variables-by-building-a-city-skyline": "Learn CSS Variables by Building a City Skyline",
|
||||
"learn-html-by-building-a-cat-photo-app": "Learn HTML by Building a Cat Photo App",
|
||||
"learn-html-forms-by-building-a-registration-form": "Learn HTML Forms by Building a Registration Form",
|
||||
"learn-intermediate-css-by-building-a-picasso-painting": "Learn Intermediate CSS by Building a Picasso Painting",
|
||||
"learn-more-about-css-pseudo-selectors-by-building-a-balance-sheet": "Learn More About CSS Pseudo Selectors By Building A Balance Sheet",
|
||||
"learn-responsive-web-design-by-building-a-piano": "Learn Responsive Web Design by Building a Piano",
|
||||
"learn-the-css-box-model-by-building-a-rothko-painting": "Learn the CSS Box Model by Building a Rothko Painting",
|
||||
"learn-typography-by-building-a-nutrition-label": "Learn Typography by Building a Nutrition Label",
|
||||
"learn-css-colors-by-building-a-set-of-colored-markers": "Learn CSS Colors by Building a Set of Colored Markers",
|
||||
"machine-learning-with-python": "Machine Learning with Python",
|
||||
"mongodb-and-mongoose": "MongoDB and Mongoose",
|
||||
"scientific-computing-with-python": "Scientific Computing with Python",
|
||||
"tensorflow": "TensorFlow",
|
||||
"the-dom": "The DOM",
|
||||
"learn-advanced-array-methods-by-building-a-statistics-calculator": "Learn Advanced Array Methods by Building a Statistics Calculator"
|
||||
"the-dom": "The DOM"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"fcc": "fCC",
|
||||
"freecodecamp": "freeCodeCamp",
|
||||
"html": "HTML",
|
||||
"css": "CSS",
|
||||
"javascript": "JavaScript"
|
||||
}
|
||||
Reference in New Issue
Block a user