Created
June 26, 2023 14:30
-
-
Save smitroshin/a8d008562cbe68f09429525d5ed9fee9 to your computer and use it in GitHub Desktop.
Convert a text to kebab-case format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert a text to kebab-case format | |
*/ | |
export const toKebabCase = (text: string) => | |
text | |
.trim() | |
.replace(/([a-z])([A-Z])/g, "$1-$2") // insert dash between lowercase and uppercase letters | |
.replace(/\s+/g, "-") // replace spaces with dashes | |
.toLowerCase(); // convert all characters to lowercase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment