Comparing version
{ | ||
"name": "sluggo", | ||
"version": "0.2.0", | ||
"version": "0.3.1", | ||
"description": "High-speed, unicode-aware, browser-friendly slug generator", | ||
@@ -11,3 +11,3 @@ "main": "sluggo.js", | ||
"type": "git", | ||
"url": "https://github.com/punkave/sluggo" | ||
"url": "https://github.com/apostrophecms/sluggo" | ||
}, | ||
@@ -19,8 +19,11 @@ "keywords": [ | ||
], | ||
"author": "P'unk Avenue LLC", | ||
"author": "Apostrophe Technologies, Inc.", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/punkave/sluggo/issues" | ||
"url": "https://github.com/apostrophecms/sluggo/issues" | ||
}, | ||
"homepage": "https://github.com/punkave/sluggo" | ||
"homepage": "https://github.com/apostrophecms/sluggo", | ||
"devDependencies": { | ||
"mocha": "^8.3.2" | ||
} | ||
} |
@@ -1,5 +0,4 @@ | ||
sluggo | ||
====== | ||
# sluggo | ||
<a href="http://apostrophenow.org/"><img src="https://raw.github.com/punkave/sluggo/master/logos/logo-box-madefor.png" align="right" /></a> | ||
<a href="https://apostrophecms.com/"><img src="https://raw.githubusercontent.com/apostrophecms/sanitize-html/main/logos/logo-box-madefor.png" align="right" alt="Made for ApostropheCMS"/></a> | ||
@@ -36,8 +35,14 @@ sluggo is a slug generator that: | ||
You can change the separator and specify a single punctuation character to be tolerated: | ||
## Options | ||
### separator | ||
Change the string separator by passing a string (usually one character) to `separator`. | ||
```javascript | ||
var sluggo = require('sluggo'); | ||
const sluggo = require('sluggo'); | ||
var s = sluggo('@ monkey\'s are elab؉؉orate fools##', { separator: ',', allow: '؉'}); | ||
const s = sluggo('monkey\'s are elaborate fools', { | ||
separator: ',' | ||
}); | ||
console.log(s); | ||
@@ -49,5 +54,24 @@ ``` | ||
``` | ||
monkey,s,are,elab؉؉orate,fools | ||
monkey,s,are,elaborate,fools | ||
``` | ||
### allow | ||
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 | ||
``` | ||
## In the Browser | ||
@@ -61,30 +85,33 @@ | ||
## About P'unk Avenue and Apostrophe | ||
## About ApostropheCMS | ||
`sluggo` was created at [P'unk Avenue](http://punkave.com) for use in many projects built with Apostrophe, an open-source content management system built on node.js. If you like `sluggo` you should definitely [check out apostrophenow.org](http://apostrophenow.org). | ||
sluggo was created at [P'unk Avenue](https://punkave.com) for use in [ApostropheCMS](https://apostrophecms.com), 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](http://github.com/punkave/sluggo). | ||
Feel free to [open issues on Github](http://github.com/apostrophecms/sluggo/issues). | ||
<a href="http://punkave.com/"><img src="https://raw.github.com/punkave/sluggo/master/logos/logo-box-builtby.png" /></a> | ||
## Changelog | ||
### CHANGES IN 0.2.0 | ||
### 0.3.1 - 2021-04-23 | ||
- 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. | ||
### 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. | ||
### CHANGES IN 0.1.2 | ||
### 0.1.2 | ||
Converts to lowercase properly. | ||
### CHANGES IN 0.1.1 | ||
### 0.1.1 | ||
Packaged correctly to work in either node or the browser. | ||
### CHANGES IN 0.1.0 | ||
### 0.1.0 | ||
Initial release. | ||
@@ -74,3 +74,3 @@ var _sluggoRanges; | ||
// No slug at all is usually bad news for Express wildcard routes, etc. | ||
n = options.def || 'none'; | ||
n = (options.def == null) ? 'none' : options.def; | ||
} | ||
@@ -77,0 +77,0 @@ return n; |
@@ -10,20 +10,36 @@ var assert = require("assert"); | ||
var s = sluggo('@ monkey\'s are elab؉؉orate fools##'); | ||
assert.equal(s, 'monkey-s-are-elab-orate-fools'); | ||
assert.strictEqual(s, 'monkey-s-are-elab-orate-fools'); | ||
}); | ||
it('slugifies a complex unicode string with allowed punctuation and a different separator', function() { | ||
var s = sluggo('@ monkey\'s are elab؉؉orate fools##', { separator: ',', allow: '؉'}); | ||
assert.equal(s, 'monkey,s,are,elab؉؉orate,fools'); | ||
assert.strictEqual(s, 'monkey,s,are,elab؉؉orate,fools'); | ||
}); | ||
it('behaves sensibly with existing slugs', function() { | ||
var s = sluggo('monkey-s-are-elab-orate-fools'); | ||
assert.equal(s, 'monkey-s-are-elab-orate-fools'); | ||
assert.strictEqual(s, 'monkey-s-are-elab-orate-fools'); | ||
}); | ||
it('converts to lowercase', function() { | ||
var s = sluggo('Monkeys Are Elaborate Fools'); | ||
assert.equal(s, 'monkeys-are-elaborate-fools'); | ||
assert.strictEqual(s, 'monkeys-are-elaborate-fools'); | ||
}); | ||
it('behaves sensibly when only the allowed punctuation character is present', function() { | ||
var s = sluggo('/', { allow: '/' }); | ||
assert.equal(s, '/'); | ||
assert.strictEqual(s, '/'); | ||
}); | ||
it('Fallback default is none', function() { | ||
var s = sluggo('@#(*&@', {}); | ||
assert.strictEqual(s, 'none'); | ||
var s = sluggo('', {}); | ||
assert.strictEqual(s, 'none'); | ||
var s = sluggo('test', {}); | ||
assert.strictEqual(s, 'test'); | ||
}); | ||
it('Empty string can be passed as default', function() { | ||
var s = sluggo('@#(*&@', { def: '' }); | ||
assert.strictEqual(s, ''); | ||
var s = sluggo('', { def: '' }); | ||
assert.strictEqual(s, ''); | ||
var s = sluggo('test', { def: '' }); | ||
assert.strictEqual(s, 'test'); | ||
}); | ||
}); |
196
8.89%115
30.68%18452
-5.39%1
Infinity%6
-25%