Created
May 11, 2012 16:07
-
-
Save lean8086/2660669 to your computer and use it in GitHub Desktop.
Convert a normal string into a friendly string
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
function friendly(str) { | |
"use strict"; | |
// Turn string into lower cases | |
str = str.toLowerCase(); | |
// Normalize vocals | |
str = str.replace(/\á|\à|\ä|\â|\ã|\ª/g, "a"); | |
str = str.replace(/\é|\è|\ë|\ê/g, "e"); | |
str = str.replace(/\í|\ì|\ï|\î/g, "i"); | |
str = str.replace(/\ó|\ò|\ö|\ô|\õ|\º/g, "o"); | |
str = str.replace(/\ú|\ù|\ü|\û/g, "u"); | |
// Normalize special characters | |
str = str.replace(/\ñ|\&/g, "n"); | |
str = str.replace(/\ç/g, "c"); | |
// Normalize words concatenations | |
str = str.replace(/\t+|\s+|\n+|\r+|\++|\-+/g, "-"); | |
// Delete delete delete | |
str = str.replace(/\(|\)|\{|\}|\[|\]|\.|\,|\;|\:|\?|\!|\'|\"|\´/g, ""); | |
return str.trim(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment