You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
638 B

4 years ago
  1. var createCompounder = require('./_createCompounder');
  2. /**
  3. * Converts `string` to
  4. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  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 snake cased string.
  12. * @example
  13. *
  14. * _.snakeCase('Foo Bar');
  15. * // => 'foo_bar'
  16. *
  17. * _.snakeCase('fooBar');
  18. * // => 'foo_bar'
  19. *
  20. * _.snakeCase('--FOO-BAR--');
  21. * // => 'foo_bar'
  22. */
  23. var snakeCase = createCompounder(function(result, word, index) {
  24. return result + (index ? '_' : '') + word.toLowerCase();
  25. });
  26. module.exports = snakeCase;