Files
lodash/string/snakeCase.js
John-David Dalton 9b7c4d6761 Bump to v3.0.0.
2015-05-19 22:25:55 -07:00

29 lines
709 B
JavaScript

define(['../internal/createCompounder'], function(createCompounder) {
/**
* Converts `string` to snake case.
* See [Wikipedia](https://en.wikipedia.org/wiki/Snake_case) for more details.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the snake cased string.
* @example
*
* _.snakeCase('Foo Bar');
* // => 'foo_bar'
*
* _.snakeCase('--foo-bar');
* // => 'foo_bar'
*
* _.snakeCase('fooBar');
* // => 'foo_bar'
*/
var snakeCase = createCompounder(function(result, word, index) {
return result + (index ? '_' : '') + word.toLowerCase();
});
return snakeCase;
});