title-case.js 343 B

123456789101112131415
  1. var upperCase = require('upper-case')
  2. var sentenceCase = require('sentence-case')
  3. /**
  4. * Title case a string.
  5. *
  6. * @param {String} string
  7. * @param {String} [locale]
  8. * @return {String}
  9. */
  10. module.exports = function (str, locale) {
  11. return sentenceCase(str, locale).replace(/^.| ./g, function (m) {
  12. return upperCase(m, locale)
  13. })
  14. }