Philipp Partosch 46a936d7de added all files to project | 2 years ago | |
---|---|---|
.. | ||
.npmignore | 2 years ago | |
Readme.md | 2 years ago | |
component.json | 2 years ago | |
package.json | 2 years ago | |
slugg.js | 2 years ago |
Make strings url-safe.
window.slugg
) and AMD/CommonJS-flavoured module loadersnpm install slugg
var slug = require('slugg')
slug('My fantastic blog post')
//-> 'my-fantastic-blog-post'
slug('Today I found £5')
//-> 'today-i-found-5'
slug('I ♥ you')
//-> 'i-you'
If you want a separator other than ‘-’, pass it in as the second argument:
slug('Kevin Spacey', ' ')
//-> 'kevin spacey'
By default, slugg will strip (i.e. remove and not replace) any sort of quotemark: '"’‘”“
.
If you want to control which characters are stripped, pass a regex as the last option that will match the chars you want to replace, eg:
slug('Mum\'s cooking', /'/g)
//-> 'mums-cooking'
Remember to use the g
flag if you want all the matches stripped (not just the first).
After version 1.1.0, a new syntax has been introduced:
If you want a separator other than ‘-’, pass it in as the separator
option:
slug('Kevin Spacey', { separator: ' ' })
//-> 'kevin spacey'
If you want to control which characters are stripped, pass a regex as the toStrip
option
that will match the chars you want to replace, eg:
slug('Mum\'s cooking', { toStrip: /'/g })
//-> 'mums-cooking'
Remember to use the g
flag if you want all the matches stripped (not just the first).
By default, slugg will convert your string to lower case. If you want to disable it just
pass the toLowerCase
option as false
, eg:
slug('Slugg rocks!', { toLowerCase: false })
//-> 'Slugg-rocks'