Last active
March 29, 2023 06:46
-
-
Save xuannghia/ad28ad6b42e88fb5facd9a3b11cf2da2 to your computer and use it in GitHub Desktop.
Xóa dấu tiếng Việt để làm slug
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
/** | |
* Slugify a string | |
* @param {string} str | |
* @param {string=} separator | |
* @returns {string} | |
*/ | |
export const slugify = (str, separator = '-') => { | |
return str | |
.normalize('NFD') | |
.replace(/[\u0300-\u036f]/g, '') | |
.toLowerCase() | |
.replace(/đ/g, 'd') | |
.replace(/[^a-z0-9-]/g, '-') | |
.replace(/-+/g, '-') | |
.replace(/^-|-$/g, '') | |
.replace(/-/g, separator); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment