-
-
Save destan/dd50a77a4aecea2fa596 to your computer and use it in GitHub Desktop.
slugify_tr slugify tr js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment