Skip to content

Instantly share code, notes, and snippets.

@muratcorlu
Created September 11, 2012 12:46
Show Gist options
  • Star 55 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save muratcorlu/3698167 to your computer and use it in GitHub Desktop.
Save muratcorlu/3698167 to your computer and use it in GitHub Desktop.
Javascript Türkçe karakter destekli slugify (url metni oluşturucu)
/**
* Metni url'de kullanılabilir hale çevirir. Boşluklar tireye çevrilir,
* alfanumerik olmayan katakterler silinir.
*
* Transform text into a URL path slug(with Turkish support).
* Spaces turned into dashes, remove non alnum
*
* @param string text
*/
slugify = function(text) {
var trMap = {
'çÇ':'c',
'ğĞ':'g',
'şŞ':'s',
'üÜ':'u',
'ıİ':'i',
'öÖ':'o'
};
for(var key in trMap) {
text = text.replace(new RegExp('['+key+']','g'), trMap[key]);
}
return text.replace(/[^-a-zA-Z0-9\s]+/ig, '') // remove non-alphanumeric chars
.replace(/\s/gi, "-") // convert spaces to dashes
.replace(/[-]+/gi, "-") // trim repeated dashes
.toLowerCase();
}
@huseyinyilmaz
Copy link

@ftanrisevdi
Copy link

Tesekkurler :)

@kutluhann
Copy link

Teşekkürler :D

@ozknozsrt
Copy link

Teşekkür 👌

@bigboytr
Copy link

Oldukça kullanışlı. İhtiyacı karışılıyor.

@frknbasaran
Copy link

teşekkürler :)

@nazifcand
Copy link

Teşekkürler starladım :)

@kahramaninalcik
Copy link

Teşekkürler

@serdargoleli
Copy link

Eline sağlık teşekkürler :)

@hkkcngz
Copy link

hkkcngz commented Apr 24, 2023

👍🤗

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