rockandrollwithemberjs / rarwe-issues

Errata and updates for the Rock and Roll with Ember.js book
https://rockandrollwithemberjs.com
43 stars 4 forks source link

Clarification needed for Ember.js string's capitalize function #523

Closed waihon closed 3 years ago

waihon commented 3 years ago

On page 272, it's mentioned:

We only call capitalize on the first character of each word because we want to allow songs that are in all caps, like MFC from Pearl Jam. If we called capitalize on each full word, users would not be able to create such a song title.

The Ember.js documentation at https://api.emberjs.com/ember/3.28/classes/String/methods/capitalize?anchor=capitalize give an example that illustrate only the first character of a string will be converted to uppercase while the remaining will be status quo:

capitalize('innerHTML') // 'InnerHTML'

If that's the case, do we still need to explicitly call the capitalize function only on the first character?

balinterdi commented 3 years ago

That's a great point, thank you! I'll simplify this for the next release.

The helper is now just:

import { helper } from '@ember/component/helper';
import { capitalize as emberCapitalize } from '@ember/string';

export function capitalize(input) {
  return input[0].split(/\s+/).map(emberCapitalize).join(' ');
}

export default helper(capitalize);