Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

@ftanrisevdi

This comment has been minimized.

Copy link

@ftanrisevdi ftanrisevdi commented Sep 18, 2017

Tesekkurler :)

@kutluhann

This comment has been minimized.

Copy link

@kutluhann kutluhann commented Jul 23, 2019

Teşekkürler :D

@ozknozsrt

This comment has been minimized.

Copy link

@ozknozsrt ozknozsrt commented Sep 20, 2019

Teşekkür 👌

@bigboytr

This comment has been minimized.

Copy link

@bigboytr bigboytr commented Oct 30, 2019

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

@frknbasaran

This comment has been minimized.

Copy link

@frknbasaran frknbasaran commented Apr 26, 2020

teşekkürler :)

@nazifcand

This comment has been minimized.

Copy link

@nazifcand nazifcand commented Jun 9, 2020

Teşekkürler starladım :)

@Kahraman160621

This comment has been minimized.

Copy link

@Kahraman160621 Kahraman160621 commented Oct 18, 2020

Teşekkürler

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