startCase.js 714 B

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