Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
30 lines (28 sloc)
762 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import words from './words.js' | |
import toString from './toString.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 = (string) => ( | |
words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => ( | |
result + (index ? '-' : '') + word.toLowerCase() | |
), '') | |
) | |
export default kebabCase |