camelCase.js 764 B

1234567891011121314151617181920
  1. var toString = require('../lang/toString');
  2. var replaceAccents = require('./replaceAccents');
  3. var removeNonWord = require('./removeNonWord');
  4. var upperCase = require('./upperCase');
  5. var lowerCase = require('./lowerCase');
  6. /**
  7. * Convert string to camelCase text.
  8. */
  9. function camelCase(str){
  10. str = toString(str);
  11. str = replaceAccents(str);
  12. str = removeNonWord(str)
  13. .replace(/[\-_]/g, ' ') //convert all hyphens and underscores to spaces
  14. .replace(/\s[a-z]/g, upperCase) //convert first char of each word to UPPERCASE
  15. .replace(/\s+/g, '') //remove spaces
  16. .replace(/^[A-Z]/g, lowerCase); //convert first char to lowercase
  17. return str;
  18. }
  19. module.exports = camelCase;