Skip to content

Instantly share code, notes, and snippets.

@bluzky

bluzky/slug.js

Last active Jun 14, 2021
Embed
What would you like to do?
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;
}
@thuyettiensinh

This comment has been minimized.

Copy link

@thuyettiensinh thuyettiensinh commented May 30, 2020

You are missing y case :)

Ex: nước Mỹ

@bluzky

This comment has been minimized.

Copy link
Owner Author

@bluzky bluzky commented Jun 3, 2020

fixed. Thank you

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