Merge branch 'master' of https://github.com/kriadmin/30-seconds-of-code
This commit is contained in:
@ -14,15 +14,13 @@ For more detailed explanation of this Regex [Visit this Site](https://regex101.c
|
|||||||
```js
|
```js
|
||||||
const toKebabCase = str => {
|
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;
|
let regex = rx = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;
|
||||||
let arr = str.match(regex);
|
return str.match(regex).map(x =>{
|
||||||
arr = arr.forEach(x =>{
|
return x.toLowerCase();
|
||||||
return s.toLowerCase();
|
}).join('-');
|
||||||
});
|
|
||||||
return arr.join('-')
|
|
||||||
}
|
}
|
||||||
// toKebabCase("camelCase") -> 'camel-case'
|
// toKebabCase("camelCase") -> 'camel-case'
|
||||||
// toKebabCase("some text") -> 'some-text'
|
// toKebabCase("some text") -> 'some-text'
|
||||||
// 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"
|
||||||
// toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLandHTML') -> "i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-xml-and-html"
|
// toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') -> "i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-xml-and-html"
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user