Created
November 4, 2019 17:36
-
-
Save leo-bianchi/9a5f4323b390964fda530269f20db0d2 to your computer and use it in GitHub Desktop.
Javascript function to remove accents, broken characters, special characters and blank spaces.
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
/** | |
* Normalize strings to a custom pattern, tempplate | |
* | |
* @param {string} myStr - String to be normalized | |
* @returns {string} Normalized string | |
*/ | |
function fixStr(myStr) { | |
return myStr.normalize('NFD') | |
.replace(/\uFFFD/g, '') | |
.replace(/[\u0300-\u036f]/g, '') | |
.replace(/[^A-Za-z0-9+ ]/g, '') | |
.replace(/\s+/g, '-') | |
.toLowerCase(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment