Skip to content

Instantly share code, notes, and snippets.

View akondas's full-sized avatar

Arkadiusz Kondas akondas

View GitHub Profile
@akondas
akondas / slugify.js
Last active August 29, 2015 14:10 — forked from mathewbyrne/slugify.js
Make friendly url and remove Polish national characters
function slugify(text)
{
var fromChar = [/ą/ig, /ę/ig, /ó/ig, /ś/ig, /ł/ig, /ż/ig, /ź/ig, /ć/ig, /ń/ig];
var toChar = ['a', 'e', 'o', 's', 'l', 'z', 'z', 'c', 'n'];
for ( var i in fromChar )
text = text.replace(fromChar[i], toChar[i]);
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -