您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

snakeCase.js 638B

12345678910111213141516171819202122232425262728
  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;