Package Exports
- slugify
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (slugify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
slugify
var slugify = require('slugify')
slugify('some string') // some-string
// if you prefer something other than '-' as separator
slugify('some string', '_') // some_string
- Vanilla ES5 JavaScript
- No dependencies
- Coerces foreign symbols to their English equivalent (check out the charMap for more details)
- Works in the browser (window.slugify) and AMD/CommonJS-flavored module loaders
Options
slugify('some string', {
replacement: '-', // replace spaces with replacement character, defaults to `-`
remove: undefined, // remove characters that match regex, defaults to `undefined`
lower: false, // convert to lower case, defaults to `false`
strict: false, // strip special characters except replacement, defaults to `false`
})
For example, to remove *+~.()'"!:@
from the result slug, you can use slugify('..', {remove: /[*+~.()'"!:@]/g})
.
Extend
Out of the box slugify
comes with support for a handful of Unicode symbols. For example the ☢
(radioactive) symbol is not defined in the charMap
and therefore it will be stripped by default:
slugify('unicode ♥ is ☢') // unicode-love-is
However you can extend the supported symbols, or override the existing ones with your own:
slugify.extend({'☢': 'radioactive'})
slugify('unicode ♥ is ☢') // unicode-love-is-radioactive
Keep in mind that the extend
method extends/overrides the default charMap
for the entire process. In case you need a fresh instance of the slugify's charMap
object you have to clean up the module cache first:
delete require.cache[require.resolve('slugify')]
var slugify = require('slugify')
Contribute
- Add chars to
charmap.json
- Run tests
npm test
- The tests will build the charmap in
index.js
and will sort thecharmap.json
- Commit all modified files
This module was originally a vanilla javascript port of node-slug.
Note that the original slug module has been ported to vanilla javascript too.
One major difference between the two modules is thatslugify
does not depend on the external unicode module.