Skip to content

Instantly share code, notes, and snippets.

View as3k's full-sized avatar
🏠
Staying safe at home

Zachary A Guerrero as3k

🏠
Staying safe at home
View GitHub Profile
@as3k
as3k / slugify.js
Created June 30, 2021 01:30 — forked from codeguy/slugify.js
Create slug from string in Javascript
function string_to_slug (str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}