Last active
July 5, 2023 00:40
-
-
Save ThinhVu/0e229ebb362f0eabe9dab46ef6d4c16d to your computer and use it in GitHub Desktop.
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 dictionary = { | |
a: 'àáảãạăằắẳẵặâầấẩẫậ', e: 'èéẻẽẹêềếểễệ', i: 'ìíỉĩị', o: 'òóỏõọôồốổỗộơờớởỡợ', u: 'ùúủũụưừứửữự', d: 'đ', | |
A: 'ÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬ', E: 'ÈÉẺẼẸÊỀẾỂỄỆ', I: 'ÌÍỈĨỊ', O: 'ÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢ', U: 'UÙÚỦŨỤƯỪỨỬỮỰ', D: 'Đ' | |
} | |
const convertMap = {} | |
for (const key of Object.keys(dictionary)) { | |
for (const char of dictionary[key]) { | |
convertMap[char] = key | |
} | |
} | |
return function (text) { | |
let output = '' | |
for (const char of text) { | |
output += convertMap[char] || char | |
} | |
return output | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment