sluggo v1.0.0
sluggo
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
Installation
npm install sluggoUsage
var sluggo = require('sluggo');
var s = sluggo('@ monkey\'s are elab؉؉orate fools##');
console.log(s);Outputs:
monkey-s-are-elab-orate-foolsOptions
separator
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,foolsallow
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-foolsIn the Browser
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.
About ApostropheCMS
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.
Support
Feel free to open issues on Github.
Changelog
1.0.0 - 2023-05-03
- Accepts an array of exceptions in the
allowoptions property while still accepting a string. Declared stable.
0.3.1 - 2021-04-23
- Accepts the empty string as a legitimate value for
def, as was always intended, rather than forcingnonein that situation. Ifdefis not set at allnoneis still the fallback default.
0.3.0 - 2020-01-27
- Updates package.json with new metadata
- Updates README.
0.2.0
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.
0.1.2
Converts to lowercase properly.
0.1.1
Packaged correctly to work in either node or the browser.
0.1.0
Initial release.