camelCase.js 701 B

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