Merge pull request #344 from atomiks/patch-4
[FIX] kebabCase styling + remove global variable + handle empty string
This commit is contained in:
@ -12,12 +12,11 @@ A word is defined as following:-
|
||||
For more detailed explanation of this Regex [Visit this Site](https://regex101.com/r/bMCgAB/1)
|
||||
|
||||
```js
|
||||
const toKebabCase = str => {
|
||||
let regex = rx = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;
|
||||
return str.match(regex).map(x =>{
|
||||
return x.toLowerCase();
|
||||
}).join('-');
|
||||
}
|
||||
const toKebabCase = str =>
|
||||
str && str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
||||
.map(x => x.toLowerCase())
|
||||
.join('-');
|
||||
|
||||
// toKebabCase("camelCase") -> 'camel-case'
|
||||
// toKebabCase("some text") -> 'some-text'
|
||||
// toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens'
|
||||
|
||||
Reference in New Issue
Block a user