Skip to content

Instantly share code, notes, and snippets.

@tsprates
Last active March 17, 2022 21:13
Show Gist options
  • Save tsprates/a699480e9bb22699dffb to your computer and use it in GitHub Desktop.
Save tsprates/a699480e9bb22699dffb to your computer and use it in GitHub Desktop.
Correspondent ASCII characters.
/**
* To ASCII.
*
* @param {string} text
* @returns {string}
*/
function toAscii(text) {
var noAscii = 'áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ';
var ascii = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC';
var resultText = '';
for (var i = 0; i < text.length; i++) {
resultText += (noAscii.indexOf(text.charAt(i)) !== -1)
? ascii.substr(noAscii.search(text.substr(i, 1)), 1)
: text.substr(i, 1);
}
return resultText;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment