mollusc
![NPM version](https://camo.githubusercontent.com/485da87c9348467227688401755e999df6d3b8e4327970c70043f79396b8856e/68747470733a2f2f62616467652e667572792e696f2f6a732f6d6f6c6c7573632e706e67)
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?)
Install
npm install mollusc
Usage
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
API
slug(input[, options])
options
replacement
Replace spaces with value.
Type: string
Default: -
symbols
Replace unicode symbols with their name.
Type: Boolean
Default: true
remove
Regex to remove characters.
Type: Boolean
Default: null
lower
Convert result to lower case.
Type: Boolean
Default: true
charmap
Replace special characters.
Type: Object
Default: slug.charmap
multicharmap
Replace strings with another string.
Type: Object
Default: slug.multicharmap
Browser
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