startCase.js 690 B

1234567891011121314151617181920212223242526
  1. var createCompounder = require('../internal/createCompounder');
  2. /**
  3. * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  4. *
  5. * @static
  6. * @memberOf _
  7. * @category String
  8. * @param {string} [string=''] The string to convert.
  9. * @returns {string} Returns the start cased string.
  10. * @example
  11. *
  12. * _.startCase('--foo-bar');
  13. * // => 'Foo Bar'
  14. *
  15. * _.startCase('fooBar');
  16. * // => 'Foo Bar'
  17. *
  18. * _.startCase('__foo_bar__');
  19. * // => 'Foo Bar'
  20. */
  21. var startCase = createCompounder(function(result, word, index) {
  22. return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
  23. });
  24. module.exports = startCase;