High-speed, unicode-aware, browser-friendly slug generator
npm install sluggosluggo is a slug generator that:
* Understands Unicode
* Runs fast (much, much faster than a RegExp solution)
* Replaces all runs of punctuation (in any language), control characters, whitespace, etc. with single dashes, with no leading or trailing dashes
* Allows you to let one punctuation character through if you wish, such as a slash for pathnames
* Allows you to change the separator character
* Is small enough to include in your browser javascript (<10K), even with the Unicode data
``bash`
npm install sluggo
`javascript
var sluggo = require('sluggo');
var s = sluggo('@ monkey\'s are elab؉؉orate fools##');
console.log(s);
`
Outputs:
``
monkey-s-are-elab-orate-fools
Change the string separator by passing a string (usually one character) to separator.
`javascript
const sluggo = require('sluggo');
const s = sluggo('monkey\'s are elaborate fools', {
separator: ','
});
console.log(s);
`
Outputs:
``
monkey,s,are,elaborate,fools
Set a single-character string to allow in returned strings. Otherwise all punctuation characters are replaced by the separator.
`javascript
const sluggo = require('sluggo');
const s = sluggo('@ monkey\'s are elab؉؉orate fools##', {
allow: '؉'
});
console.log(s);
`
Outputs:
``
monkey-s-are-elab؉؉orate-fools
You just want sluggo.js. Add that file to your frontend javascript world.
Now you can call the sluggo() function anywhere.
You do NOT need generator.js, which we will use when the next version of Unicode comes out to update this module.
sluggo was created at P'unk Avenue for use in ApostropheCMS, an open-source content management system built on Node.js. If you like sanitize-html you should definitely check out Apostrophe.
Feel free to open issues on Github.
options property while still accepting a string. Declared stable.$3
- Accepts the empty string as a legitimate value for def, as was always intended, rather than forcing none in that situation. If def is not set at all none is still the fallback default.$3
- Updates package.json with new metadata
- Updates README.$3
Whoops, the classic apostrophe slugify method accepted
allow, not allowed. We just released this today, so I've switched to allow in sluggo` as well. However I did bump to 0.2.0 to remain faithful to the semver standard.Converts to lowercase properly.
Packaged correctly to work in either node or the browser.
Initial release.