Skip to content

Instantly share code, notes, and snippets.

@bluzky
Last active August 12, 2024 15:30
Show Gist options
  • Save bluzky/b8c205c98ff3318907b30c3e0da4bf3f to your computer and use it in GitHub Desktop.
Save bluzky/b8c205c98ff3318907b30c3e0da4bf3f to your computer and use it in GitHub Desktop.
Remove vietnamese accent javascript / Bỏ dấu tiếng Việt
function stringToSlug(str) {
// remove accents
var from = "àáãảạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệđùúủũụưừứửữựòóỏõọôồốổỗộơờớởỡợìíỉĩịäëïîöüûñçýỳỹỵỷ",
to = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeduuuuuuuuuuuoooooooooooooooooiiiiiaeiiouuncyyyyy";
for (var i=0, l=from.length ; i < l ; i++) {
str = str.replace(RegExp(from[i], "gi"), to[i]);
}
str = str.toLowerCase()
.trim()
.replace(/[^a-z0-9\-]/g, '-')
.replace(/-+/g, '-');
return str;
}
@GiangThanhDat
Copy link

GiangThanhDat commented Sep 13, 2022

Thanks for sharing <3

@hhuuthien
Copy link

You saved my life!!! Thanks a lot

@southxzx
Copy link

God job!

@DinhNghiaVo
Copy link

it not working for "Đ"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment