Last active
April 19, 2021 09:37
-
-
Save anhtran/65f15495afbd123698d242f10866dc9d to your computer and use it in GitHub Desktop.
How to remove all accents in Vietnamese string | Xóa dấu trong tiếng Việt làm slug hoặc để tìm kiếm
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 removeAccents = (function () { | |
const letters1 = 'ÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚĂĐĨŨƠàáâãèéêìíòóôõùúăđĩũơƯĂẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼỀỀỂưăạảấầẩẫậắằẳẵặẹẻẽềềểếỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪễệỉịọỏốồổỗộớờởỡợụủứừỬỮỰỲỴÝỶỸửữựỳỵỷỹý' | |
const letters2 = 'AAAAEEEIIOOOOUUADIUOaaaaeeeiioooouuadiuoUAAAAAAAAAAAAAEEEEEEuaaaaaaaaaaaaaeeeeeeeEEIIOOOOOOOOOOOOUUUUeeiioooooooooooouuuuUUUYYYYYuuuyyyyy' | |
const patternLetters = new RegExp('[' + letters1 + ']', 'g') | |
const lookupLetters = {} | |
letters1.split('').forEach(function (letter, i) { | |
lookupLetters[letter] = letters2[i] | |
}) | |
const letterTranslator = function (match) { | |
return lookupLetters[match] || match | |
} | |
return function removeAccents (input) { | |
return input.replace(patternLetters, letterTranslator) | |
} | |
})() |
lemihthien
commented
Apr 19, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment