暫無描述

camel-case.js 600B

1234567891011121314151617181920212223
  1. var upperCase = require('upper-case')
  2. var sentenceCase = require('sentence-case')
  3. /**
  4. * Camel case a string.
  5. *
  6. * @param {String} string
  7. * @param {String} [locale]
  8. * @return {String}
  9. */
  10. module.exports = function (string, locale, mergeNumbers) {
  11. var result = sentenceCase(string, locale)
  12. // Replace periods between numeric entities with an underscore.
  13. if (!mergeNumbers) {
  14. result = result.replace(/(\d) (?=\d)/g, '$1_')
  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. }