diff --git a/snippets/toKebabCase.md b/snippets/toKebabCase.md index 78294e993..bfee82b01 100644 --- a/snippets/toKebabCase.md +++ b/snippets/toKebabCase.md @@ -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'