Skip to content

Instantly share code, notes, and snippets.

@huantt
Forked from bluzky/slug.js
Created May 1, 2022 11:19
Show Gist options
  • Save huantt/62bb78cb8daae1d5391bd55d45342dba to your computer and use it in GitHub Desktop.
Save huantt/62bb78cb8daae1d5391bd55d45342dba 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment