sluggo 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
npm install sluggo
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
.
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.
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.
- Accepts an array of exceptions in the
allow
options property while still accepting a string. Declared stable.
- Accepts the empty string as a legitimate value for
def
, as was always intended, rather than forcingnone
in that situation. Ifdef
is not set at allnone
is still the fallback default.
- Updates package.json with new metadata
- Updates README.
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.