Skip to content

Instantly share code, notes, and snippets.

@ng-hai
Last active November 27, 2019 09:09
Show Gist options
  • Save ng-hai/226cabac9e635b8e98a9a0743954b0c0 to your computer and use it in GitHub Desktop.
Save ng-hai/226cabac9e635b8e98a9a0743954b0c0 to your computer and use it in GitHub Desktop.
Vietnamese accents removal
const ACCENT_MAP = {
ó: 'o',
ò: 'o',
ỏ: 'o',
õ: 'o',
ọ: 'o',
ơ: 'o',
ớ: 'o',
ờ: 'o',
ở: 'o',
ỡ: 'o',
ợ: 'o',
ô: 'o',
ố: 'o',
ồ: 'o',
ổ: 'o',
ỗ: 'o',
ộ: 'o',
ý: 'y',
ỳ: 'y',
ỷ: 'y',
ỹ: 'y',
ỵ: 'y',
e: 'e',
é: 'e',
è: 'e',
ẻ: 'e',
ẽ: 'e',
ẹ: 'e',
ê: 'e',
ế: 'e',
ề: 'e',
ể: 'e',
ễ: 'e',
ệ: 'e',
ú: 'u',
ù: 'u',
ủ: 'u',
ũ: 'u',
ụ: 'u',
ư: 'u',
ứ: 'u',
ừ: 'u',
ử: 'u',
ữ: 'u',
ự: 'u',
á: 'a',
à: 'a',
ả: 'a',
ã: 'a',
ạ: 'a',
â: 'a',
ấ: 'a',
ầ: 'a',
ẩ: 'a',
ẫ: 'a',
ậ: 'a',
ă: 'a',
ắ: 'a',
ằ: 'a',
ẳ: 'a',
ẵ: 'a',
ặ: 'a',
í: 'i',
ì: 'i',
ỉ: 'i',
ĩ: 'i',
ị: 'i',
đ: 'd',
};
export default function accentFold(value) {
if (!value) {
return '';
}
return [...String(value).toLocaleLowerCase()]
.map(character => ACCENT_MAP[character] || character)
.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment