replaceAccents.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. var toString = require('../lang/toString');
  2. /**
  3. * Replaces all accented chars with regular ones
  4. */
  5. function replaceAccents(str){
  6. str = toString(str);
  7. // verifies if the String has accents and replace them
  8. if (str.search(/[\xC0-\xFF]/g) > -1) {
  9. str = str
  10. .replace(/[\xC0-\xC5]/g, "A")
  11. .replace(/[\xC6]/g, "AE")
  12. .replace(/[\xC7]/g, "C")
  13. .replace(/[\xC8-\xCB]/g, "E")
  14. .replace(/[\xCC-\xCF]/g, "I")
  15. .replace(/[\xD0]/g, "D")
  16. .replace(/[\xD1]/g, "N")
  17. .replace(/[\xD2-\xD6\xD8]/g, "O")
  18. .replace(/[\xD9-\xDC]/g, "U")
  19. .replace(/[\xDD]/g, "Y")
  20. .replace(/[\xDE]/g, "P")
  21. .replace(/[\xE0-\xE5]/g, "a")
  22. .replace(/[\xE6]/g, "ae")
  23. .replace(/[\xE7]/g, "c")
  24. .replace(/[\xE8-\xEB]/g, "e")
  25. .replace(/[\xEC-\xEF]/g, "i")
  26. .replace(/[\xF1]/g, "n")
  27. .replace(/[\xF2-\xF6\xF8]/g, "o")
  28. .replace(/[\xF9-\xFC]/g, "u")
  29. .replace(/[\xFE]/g, "p")
  30. .replace(/[\xFD\xFF]/g, "y");
  31. }
  32. return str;
  33. }
  34. module.exports = replaceAccents;