Skip to content

Instantly share code, notes, and snippets.

@duynhm
Created November 28, 2023 04:06
Show Gist options
  • Save duynhm/75f6ede23e304db464e2e0e0b978eeda to your computer and use it in GitHub Desktop.
Save duynhm/75f6ede23e304db464e2e0e0b978eeda to your computer and use it in GitHub Desktop.
Convert sign character to unsign character, such as: Nguyễn to nguyen
function convert(str){
str = str.replace(/[^A-Za-z0-9\-_]/g, function(ch) {
// Character that look a bit like 'a'
if ("áàãạảâấầẩẫậăắằẳặẵ".indexOf(ch) >= 0) { // There are a lot more than this
return 'a';
}
if ("ÁÀÃẠẢÂẤẦẨẪẬĂẮẰẲẶẴ".indexOf(ch) >= 0) { // There are a lot more than this
return 'a';
}
if ("đ".indexOf(ch) >= 0) { // There are a lot more than this
return 'd';
}
if ("Đ".indexOf(ch) >= 0) { // There are a lot more than this
return 'd';
}
if ("eéèẻẽẹêếềểễệ".indexOf(ch) >= 0) { // There are a lot more than this
return 'e';
}
if ("EÉÈẺẼẸÊẾỀỂỄỆ".indexOf(ch) >= 0) { // There are a lot more than this
return 'e';
}
if ("iíìỉĩị".indexOf(ch) >= 0) { // There are a lot more than this
return 'i';
}
if ("IÍÌỈĨỊ".indexOf(ch) >= 0) { // There are a lot more than this
return 'i';
}
if ("oóòỏõọôốồổỗộơớờởỡợ".indexOf(ch) >= 0) { // There are a lot more than this
return 'o';
}
if ("OÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢ".indexOf(ch) >= 0) { // There are a lot more than this
return 'o';
}
// u
if ("uúùủũụưứừửữự".indexOf(ch) >= 0) { // There are a lot more than this
return 'u';
}
if ("UÚÙỦŨỤƯỨỪỬỮỰ".indexOf(ch) >= 0) { // There are a lot more than this
return 'u';
}
/* ...long list of others...*/
// Default
return '';
});
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment