Files
lodash/snakeCase.js
John-David Dalton 7293d39642 Bump to v4.1.0.
2016-01-29 01:14:13 -08:00

28 lines
663 B
JavaScript

define(['./_createCompounder'], function(createCompounder) {
/**
* Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
*
* @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('fooBar');
* // => 'foo_bar'
*
* _.snakeCase('--foo-bar');
* // => 'foo_bar'
*/
var snakeCase = createCompounder(function(result, word, index) {
return result + (index ? '_' : '') + word.toLowerCase();
});
return snakeCase;
});