-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertViToEn.js
More file actions
19 lines (19 loc) · 1.09 KB
/
convertViToEn.js
File metadata and controls
19 lines (19 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Based on sample-code/ConvertVietnameseCharacter.php
const convertViToEn = (text: string) => {
text = text.replace(/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/g, 'a');
text = text.replace(/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/g, 'e');
text = text.replace(/(ì|í|ị|ỉ|ĩ)/g, 'i');
text = text.replace(/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/g, 'o');
text = text.replace(/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/g, 'u');
text = text.replace(/(ỳ|ý|ỵ|ỷ|ỹ)/g, 'y');
text = text.replace(/(đ)/g, 'd');
text = text.replace(/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/g, 'A');
text = text.replace(/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/g, 'E');
text = text.replace(/(Ì|Í|Ị|Ỉ|Ĩ)/g, 'I');
text = text.replace(/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/g, 'O');
text = text.replace(/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/g, 'U');
text = text.replace(/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/g, 'Y');
text = text.replace(/(Đ)/g, 'D');
text = text.replace(/ /g, '-');
return text;
}