camelCase.js 680 B

123456789101112131415161718192021222324252627
  1. var createCompounder = require('../internal/createCompounder');
  2. /**
  3. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  4. *
  5. * @static
  6. * @memberOf _
  7. * @category String
  8. * @param {string} [string=''] The string to convert.
  9. * @returns {string} Returns the camel cased string.
  10. * @example
  11. *
  12. * _.camelCase('Foo Bar');
  13. * // => 'fooBar'
  14. *
  15. * _.camelCase('--foo-bar');
  16. * // => 'fooBar'
  17. *
  18. * _.camelCase('__foo_bar__');
  19. * // => 'fooBar'
  20. */
  21. var camelCase = createCompounder(function(result, word, index) {
  22. word = word.toLowerCase();
  23. return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
  24. });
  25. module.exports = camelCase;