cleanDiacritics.js 595 B

12345678910111213141516171819202122
  1. var makeString = require('./helper/makeString');
  2. var from = "ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșşšŝťțţŭùúüűûñÿýçżźž",
  3. to = "aaaaaaaaaccceeeeeghiiiijllnnoooooooossssstttuuuuuunyyczzz";
  4. from += from.toUpperCase();
  5. to += to.toUpperCase();
  6. to = to.split("");
  7. // for tokens requireing multitoken output
  8. from += "ß";
  9. to.push('ss');
  10. module.exports = function cleanDiacritics(str) {
  11. return makeString(str).replace(/.{1}/g, function(c){
  12. var index = from.indexOf(c);
  13. return index === -1 ? c : to[index];
  14. });
  15. };