Make strings url-safe and replace unicode symbols with their name
- respecting RFC 3986
- Comprehensive tests
- No dependencies, except unicode data
- 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 mollusc
const slug = require('mollusc')
slug('i ♥ unicode')
//= i-love-unicode
slug('unicode ♥ is ☢')
//= unicode-love-is-radioactive
slug('i ♥ unicode', {
replacement: '_'
})
//= i_love_unicode
slug.charmap['♥'] = 'freaking love'
slug('I ♥ UNICODE')
//= i-freaking-love-unicode
slug('☏-NUMBER', {
lower: false
})
//= telephone-NUMBER
slug(input[, options])
Replace spaces with value.
Type: string
Default: -
Replace unicode symbols with their name.
Type: Boolean
Default: true
Regex to remove characters.
Type: Boolean
Default: null
Convert result to lower case.
Type: Boolean
Default: true
Replace special characters.
Type: Boolean
Default: slug.charmap
Replace strings with another string.
Type: Boolean
Default: slug.multicharmap
When using browserify you might want to remove the symbols table from your bundle.
browserify slug.js --ignore unicode-json/category/So -s slug > slug-browser.js