Skip to content

Instantly share code, notes, and snippets.

@lean8086
Created May 11, 2012 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lean8086/2660669 to your computer and use it in GitHub Desktop.
Save lean8086/2660669 to your computer and use it in GitHub Desktop.
Convert a normal string into a friendly string
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