Created
November 23, 2017 07:37
-
-
Save googlicius/a4c1a0f3fad82dc16df233092dd94dbb to your computer and use it in GitHub Desktop.
Function to remove Vietnamese's diacritic marks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bodauTiengViet = str => { | |
str = str.toLowerCase(); | |
str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, 'a'); | |
str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, 'e'); | |
str = str.replace(/ì|í|ị|ỉ|ĩ/g, 'i'); | |
str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, 'o'); | |
str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, 'u'); | |
str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, 'y'); | |
str = str.replace(/đ/g, 'd'); | |
// 2 lines below to replace spaces to '-', uncomment if you need. | |
// str = str.replace(/\W+/g, ' '); | |
// str = str.replace(/\s/g, '-'); | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment