Skip to content

Instantly share code, notes, and snippets.

@cuonghuynh
Created September 17, 2018 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuonghuynh/99f6e45545ec81f1aeab31120eba12f8 to your computer and use it in GitHub Desktop.
Save cuonghuynh/99f6e45545ec81f1aeab31120eba12f8 to your computer and use it in GitHub Desktop.
slugify title for vietnamese
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');
str = str.replace(/([^0-9a-z-\s])/g, '');
str = str.replace(/(\s+)/g, '-');
str = str.replace(/^-+/g, '');
str = str.replace(/-+$/g, '');
return str;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment