mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +00:00
27 lines
599 B
JavaScript
27 lines
599 B
JavaScript
import createCompounder from './.internal/createCompounder.js';
|
|
|
|
/**
|
|
* Converts `string` to
|
|
* [snake case](https://en.wikipedia.org/wiki/Snake_case).
|
|
*
|
|
* @since 3.0.0
|
|
* @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'
|
|
*/
|
|
const snakeCase = createCompounder((result, word, index) =>
|
|
result + (index ? '_' : '') + word.toLowerCase()
|
|
);
|
|
|
|
export default snakeCase;
|