Skip to content

Instantly share code, notes, and snippets.

@ThinhVu
Last active July 5, 2023 00:40
Show Gist options
  • Save ThinhVu/0e229ebb362f0eabe9dab46ef6d4c16d to your computer and use it in GitHub Desktop.
Save ThinhVu/0e229ebb362f0eabe9dab46ef6d4c16d to your computer and use it in GitHub Desktop.
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