capitalize.js 529 B

123456789101112131415161718192021222324
  1. var toString = require('./toString'),
  2. upperFirst = require('./upperFirst');
  3. /**
  4. * Converts the first character of `string` to upper case and the remaining
  5. * to lower case.
  6. *
  7. * @static
  8. * @memberOf _
  9. * @since 3.0.0
  10. * @category String
  11. * @param {string} [string=''] The string to capitalize.
  12. * @returns {string} Returns the capitalized string.
  13. * @example
  14. *
  15. * _.capitalize('FRED');
  16. * // => 'Fred'
  17. */
  18. function capitalize(string) {
  19. return upperFirst(toString(string).toLowerCase());
  20. }
  21. module.exports = capitalize;