Skip to content

Instantly share code, notes, and snippets.

@leekiernan
Created August 29, 2013 19:29
Show Gist options
  • Save leekiernan/6382386 to your computer and use it in GitHub Desktop.
Save leekiernan/6382386 to your computer and use it in GitHub Desktop.
var Slugify = function() {
this.charmap = {
'€': 'euro', '₢': 'cruzeiro', '₣': 'french franc', '£': 'pound',
'₤': 'lira', '₥': 'mill', '₦': 'naira', '₧': 'peseta', '₨': 'rupee', '₹': 'indian rupee',
'₩': 'won', '₪': 'new shequel', '₫': 'dong', '₭': 'kip', '₮': 'tugrik',
'₯': 'drachma', '₰': 'penny', '₱': 'peso', '₲': 'guarani', '₳': 'austral',
'₴': 'hryvnia', '₵': 'cedi', '¢': 'cent', '¥': 'yen', '元': 'yuan',
'円': 'yen', '﷼': 'rial', '₠': 'ecu', '¤': 'currency', '฿': 'baht',
"$": 'dollar',
'©':'(c)', 'œ': 'oe', 'Œ': 'OE', '∑': 'sum', '®': '(r)', '†': '+',
'“': '"', '”': '"', '‘': "'", '’': "'", '∂': 'd', 'ƒ': 'f', '™': 'tm',
'℠': 'sm', '…': '...', '˚': 'o', 'º': 'o', 'ª': 'a', '•': '*',
'∆': 'delta', '∞': 'infinity', '♥': 'love', '&': 'and', '|': 'or',
'<': 'less', '>': 'greater'
};
this.space = '-';
}
Slugify.prototype.prepare = function(text) {
return text.toLowerCase().trim()
}
Slugify.prototype.clean = function(text) {
return this.prepare(text).replace( /[\s]+/g, this.space );
};
Slugify.prototype.transliterate = function(text){
return text.replace( /[^-\w]+/g, '' );
};
Slugify.prototype.toURL = function(text) {
var url = this.clean(text);
return this.transliterate(url);
};
Slugify.prototype.toTags = function(text) {
return this.prepare(text).split(' ');
};
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
module.exports = new Slugify;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment