camel-case.js 573 B

1234567891011121314151617181920212223
  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. }