Skip to content

Instantly share code, notes, and snippets.

@AttilaSATAN
Last active October 22, 2018 14:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AttilaSATAN/9447379cb7c749878af9 to your computer and use it in GitHub Desktop.
Save AttilaSATAN/9447379cb7c749878af9 to your computer and use it in GitHub Desktop.
Angularjs için türkçe slugify servisi.
angular.module('app.utils.services', []).
factory('slugify', function () {
return function(text){
if (!text) return null;
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