You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Coerces foreign symbols to their english equivalent
Works in browser (window.slug) and AMD/CommonJS-flavoured module loaders (except the unicode symbols unless you use browserify but who wants to download a ~2mb js file, right?)
npm install slug
bower install slug
example
varslug=require('slug')varprint=console.log.bind(console,'>')print(slug('i ♥ unicode'))// > i-love-unicodeprint(slug('unicode ♥ is ☢'))// yes!// > unicode-love-is-radioactiveprint(slug('i ♥ unicode','_'))// If you prefer something else then `-` as seperator// > i_love_unicodeslug.charmap['♥']='freaking love'// change default charmap or use option {charmap:{…}} as 2. argumentprint(slug('I ♥ UNICODE'))// > I-freaking-love-UNICODEprint(slug('☏-Number',{lower: true}))// If you prefer lower case// > telephone-numberprint(slug('i <3 unicode'))// > i-love-unicode
options
// options is either object or replacement (sets options.replacement)slug('string',[{options}||'replacement']);
slug.defaults.mode='pretty';slug.defaults.modes['rfc3986']={replacement: '-',// replace spaces with replacementsymbols: true,// replace unicode symbols or notremove: null,// (optional) regex to remove characterslower: true,// result in lower casecharmap: slug.charmap,// replace special charactersmulticharmap: slug.multicharmap// replace multi-characters};slug.defaults.modes['pretty']={replacement: '-',symbols: true,remove: /[.]/g,lower: false,charmap: slug.charmap,multicharmap: slug.multicharmap};
browser
When using browserify you might want to remove the symbols table from your bundle by using --ignore similar to this: