Skip to content

Instantly share code, notes, and snippets.

@leo-bianchi
Created November 4, 2019 17:36
Show Gist options
  • Save leo-bianchi/9a5f4323b390964fda530269f20db0d2 to your computer and use it in GitHub Desktop.
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.
/**
* 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