Update toKebabCase.md
This commit is contained in:
@ -1,8 +1,8 @@
|
|||||||
### toKebabCase
|
### toKebabCase
|
||||||
|
|
||||||
Converts a string to snakecase.
|
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()` and undesrsocres and spaces with hyphens.
|
Use `replace()` to add spaces before capital letters, convert `toLowerCase()`, then `replace()` underscores and spaces with hyphens.
|
||||||
Also check if a string starts with hyphen and if yes remove it.
|
Also check if a string starts with a hyphen and remove it if yes.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const toKebabCase = str => {
|
const toKebabCase = str => {
|
||||||
@ -11,7 +11,6 @@ const toKebabCase = str => {
|
|||||||
}
|
}
|
||||||
// toKebabCase("camelCase") -> 'camel-case'
|
// toKebabCase("camelCase") -> 'camel-case'
|
||||||
// toKebabCase("some text") -> 'some-text'
|
// 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("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens'
|
||||||
// toKebabCase("AllThe-small Things") -> "all-the-small-things"
|
// toKebabCase("AllThe-small Things") -> "all-the-small-things"
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user