This is a fork. you might want the original one from Sindresorhus. check that out. This only transpiles it to be compatible to older browsers.
Slugify a string
Useful for URLs, filenames, and IDs.
$ npm install @sindresorhus/slugify
const slugify = require('@sindresorhus/slugify');
slugify('I ♥ Dogs');
//=> 'i-love-dogs'
slugify(' Déjà Vu! ');
//=> 'deja-vu'
slugify('fooBar 123 $#%');
//=> 'foo-bar-123'
slugify('BAR and baz', {separator: '_'});
//=> 'bar_and_baz'
slugify('I ♥ 🦄 & 🐶', {
customReplacements: [
['🐶', 'dog']
]
});
//=> 'i-love-unicorn-and-dog'
Type: string
Type: Object
Type: string
Default: -
Type: Array
Default: [ ['&', 'and'], ['🦄', 'unicorn'], ['♥', 'love'] ]
Specifying this only replaces the default if you set an item with the same key, like &
.
- slugify-cli - CLI for this module
- filenamify - Convert a string to a valid safe filename
MIT © Sindre Sorhus