Last active
August 29, 2015 14:06
-
-
Save franklinjavier/2e6f56453b4736905bfd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* | |
| * Remove acentos | |
| * | |
| * @param {string} str - String a ser alterada | |
| * @example removeAccent('São Paulo'); // Sao Paulo | |
| */ | |
| function removeAccent() { | |
| var st = arguments[0].toLowerCase(); | |
| st = st.replace(/[\u00C0-\u00C5]/ig, 'a') | |
| .replace(/[\u00C8-\u00CB]/ig, 'e') | |
| .replace(/[\u00CC-\u00CF]/ig, 'i') | |
| .replace(/[\u00D2-\u00D6]/ig, 'o') | |
| .replace(/[\u00D9-\u00DC]/ig, 'u') | |
| .replace(/[\-]{2}/g, ''); | |
| return ( st.replace(/[^a-z\- ]*/gi, '') ); | |
| } |
This file contains hidden or 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
| /* | |
| * Remove acentos e substitui espacos por hifen | |
| * | |
| * @param {string} str - String a ser alterada | |
| * @example slugify('São Paulo'); // sao-paulo | |
| */ | |
| function slugify( str ) { | |
| str = str | |
| .toLowerCase() | |
| .replace(/^\s+|\s+$/g, '') | |
| .replace(/[\u00C0-\u00C5]/ig, 'a') | |
| .replace(/[\u00C8-\u00CB]/ig, 'e') | |
| .replace(/[\u00CC-\u00CF]/ig, 'i') | |
| .replace(/[\u00D2-\u00D6]/ig, 'o') | |
| .replace(/[\u00D9-\u00DC]/ig, 'u') | |
| .replace(/[\u00D1]/ig, 'n') | |
| .replace(/[^a-z0-9 ]+/gi, '') | |
| .replace(/ /g, '-') | |
| .replace(/[\-]{2}/g, '-') | |
| .replace(/[^a-z0-9\- ]*/gi, '') | |
| return str; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment