You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
573 B

4 years ago
  1. var upperCase = require('upper-case')
  2. var noCase = require('no-case')
  3. /**
  4. * Camel case a string.
  5. *
  6. * @param {string} value
  7. * @param {string} [locale]
  8. * @return {string}
  9. */
  10. module.exports = function (value, locale, mergeNumbers) {
  11. var result = noCase(value, locale)
  12. // Replace periods between numeric entities with an underscore.
  13. if (!mergeNumbers) {
  14. result = result.replace(/ (?=\d)/g, '_')
  15. }
  16. // Replace spaces between words with an upper cased character.
  17. return result.replace(/ (.)/g, function (m, $1) {
  18. return upperCase($1, locale)
  19. })
  20. }