Skip to content

Instantly share code, notes, and snippets.

View josephNg95's full-sized avatar
🎯
Focusing

Joseph Ng josephNg95

🎯
Focusing
  • Hanoi/VietNam
  • 14:34 (UTC +07:00)
View GitHub Profile
@bluzky
bluzky / slug.js
Last active August 12, 2024 15:30
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()