Created
November 26, 2022 16:20
-
-
Save rigwild/0ec9fa6ace5efb5575e807b71d3f2f05 to your computer and use it in GitHub Desktop.
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 any string to kebab-case. | |
* Removes accents, multiples whitespaces and symbols to one "-" and converts to lower case. | |
* Removes any leading and leading "-". | |
* | |
* @param {string} str string to convert | |
* @returns {string} string in kebab-case | |
* @author rigwild <[email protected]> | |
* @see https://gist.github.com/rigwild/3e4d30bd269535b7508926c8beaeef90 | |
*/ | |
const toKebabCase = str => str | |
.normalize('NFD').replace(/[\u0300-\u036f]/g, '') | |
.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/\s+]/gi, '-') | |
.replace(/\-+/g, '-') | |
.replace(/^\-|\-$/g, '') | |
.toLowerCase() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment