
Make strings url-safe.
Vanilla javascript, no production dependencies.
Why not use slug? Or slugify? Well, I built this because I wanted a more transparent and powerfull implementation. If I wanted to preserve "/" and change "." to ":" I want to be able to do that, but still have the comfort of everything else being a default slugifier.
npm install larvitslugify
Examples
const { slugify, defaultCharmap } = require('larvitslugify');
slugify('i ♥ unicode');
slugify('unicode ♥ is ☢');
slugify('i ♥ unicode', '_');
slugify('I ♥ UNICODE', { charmap: { ...defaultCharmap, '♥': 'freaking love' } }));
slugify('i <3 unicode');
Options
slugify('string', [{options} || 'whitespaceReplaceChar']);
All options
slugify('string', {
'whitespaceReplaceChar': '-',
'charmap': {'Å': 'A', 'Ö': 'O' ... },
'multiCharmap': = {'<3': 'love', '||': 'and'},
'removeMultipleWhitespace': = true,
'trim': = true,
'unidentifiedReplaceChar': = '',
'whitespaces': = [' ', '\t', '\xa0']
'save': = undefined
});
Changelog
1.2.0