Update toKebabCase.md

This commit is contained in:
David Wu
2017-12-23 16:10:56 +01:00
committed by GitHub
parent 4281d0b8b5
commit 80faa07640

View File

@ -1,8 +1,8 @@
### toKebabCase
Converts a string to snakecase.
Use `replace()` to add spaces before capital letters, convert `toLowerCase()`, then `replace()` and undesrsocres and spaces with hyphens.
Also check if a string starts with hyphen and if yes remove it.
Converts a string to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
Use `replace()` to add spaces before capital letters, convert `toLowerCase()`, then `replace()` underscores and spaces with hyphens.
Also check if a string starts with a hyphen and remove it if yes.
```js
const toKebabCase = str => {
@ -11,7 +11,6 @@ const toKebabCase = str => {
}
// toKebabCase("camelCase") -> 'camel-case'
// toKebabCase("some text") -> 'some-text'
// toKebabCase("some-javascript-property") -> 'some-javascript-property'
// toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens'
// toKebabCase("AllThe-small Things") -> "all-the-small-things"
```