Skip to content

Instantly share code, notes, and snippets.

@canhbk
Forked from bluzky/slug.js
Created June 14, 2021 13:32
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 canhbk/23247a72942ce7e49b3cd570fd0454f0 to your computer and use it in GitHub Desktop.
Save canhbk/23247a72942ce7e49b3cd570fd0454f0 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