mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
28 lines
688 B
JavaScript
28 lines
688 B
JavaScript
import createCompounder from './.internal/createCompounder.js'
|
|
|
|
/**
|
|
* Converts `string` to
|
|
* [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
|
|
*
|
|
* @since 3.0.0
|
|
* @category String
|
|
* @param {string} [string=''] The string to convert.
|
|
* @returns {string} Returns the kebab cased string.
|
|
* @see camelCase, lowerCase, snakeCase, startCase, upperCase, upperFirst
|
|
* @example
|
|
*
|
|
* kebabCase('Foo Bar')
|
|
* // => 'foo-bar'
|
|
*
|
|
* kebabCase('fooBar')
|
|
* // => 'foo-bar'
|
|
*
|
|
* kebabCase('__FOO_BAR__')
|
|
* // => 'foo-bar'
|
|
*/
|
|
const kebabCase = createCompounder((result, word, index) =>
|
|
result + (index ? '-' : '') + word.toLowerCase()
|
|
)
|
|
|
|
export default kebabCase
|