Comparing version 3.3.0 to 3.3.1
{ | ||
"name": "slug", | ||
"description": "slugifies even utf-8 chars!", | ||
"version": "3.3.0", | ||
"version": "3.3.1", | ||
"homepage": "https://github.com/Trott/slug", | ||
@@ -22,3 +22,4 @@ "author": "dodo (https://github.com/dodo)", | ||
"scripts": { | ||
"test": "standard && nyc --reporter none mocha test/**/*.js && karma start --single-run --browsers ChromeHeadless,FirefoxHeadless .karma.config.js && nyc report --reporter=text --reporter=html && nyc check-coverage --lines 100 --branches 100 --statements 100 --functions 100" | ||
"test": "standard && nyc --reporter none mocha test/**/*.js && karma start --single-run --browsers ChromeHeadless,FirefoxHeadless .karma.config.js && nyc report --reporter=text --reporter=html && nyc check-coverage --lines 100 --branches 100 --statements 100 --functions 100", | ||
"benchmark": "node benchmark/benchmark.js" | ||
}, | ||
@@ -34,3 +35,3 @@ "dependencies": {}, | ||
"karma-mocha": "^2.0.1", | ||
"mocha": "^7.0.0", | ||
"mocha": "^8.0.1", | ||
"nyc": "^15.0.1", | ||
@@ -37,0 +38,0 @@ "requirejs": "^2.3.6", |
@@ -62,2 +62,9 @@ # [slug](https://github.com/Trott/slug) | ||
// > unicode-love-is | ||
// Custom removal of characters from resulting slug. Let's say that we want to | ||
// remove all numbers for some reason. | ||
print(slug('one 1 two 2 three 3')) | ||
// > one-1-two-2-three-3 | ||
print(slug('one 1 two 2 three 3', { remove: /[0-9]/g })) | ||
// > one-two-three | ||
``` | ||
@@ -83,3 +90,3 @@ | ||
replacement: '-', | ||
remove: /[.]/g, | ||
remove: null, | ||
lower: false, | ||
@@ -86,0 +93,0 @@ charmap: slug.charmap, |
13
slug.js
@@ -102,3 +102,4 @@ /* global btoa */ | ||
var lengths = [] | ||
for (const key in opts.multicharmap) { | ||
// "let" instead of "const" in next line is for IE11 compatibilty | ||
for (let key in opts.multicharmap) { // eslint-disable-line prefer-const | ||
if (!Object.prototype.hasOwnProperty.call(opts.multicharmap, key)) { continue } | ||
@@ -127,9 +128,11 @@ | ||
} | ||
const allowedChars = opts.mode === 'rfc3986' ? /[^\w\s\-.~]/g : /[^A-Za-z0-9\s]/g | ||
// next line preserves the replacement character in case it is included in allowedChars | ||
char = char.replace(opts.replacement, ' ') | ||
char = char.replace(allowedChars, '') // allowed | ||
if (opts.remove) char = char.replace(opts.remove, '') // add flavour | ||
result += char | ||
} | ||
const allowedChars = opts.mode === 'rfc3986' ? /[^\w\s\-.~]/g : /[^A-Za-z0-9\s]/g | ||
result = result.replace(allowedChars, '') // allowed | ||
if (opts.remove) { | ||
result = result.replace(opts.remove, '') | ||
} | ||
result = result.trim() | ||
@@ -816,3 +819,3 @@ result = result.replace(/[-\s]+/g, opts.replacement) // convert spaces | ||
replacement: '-', | ||
remove: /[.]/g, | ||
remove: null, | ||
lower: true, | ||
@@ -819,0 +822,0 @@ charmap: slug.defaults.charmap, |
Sorry, the diff of this file is not supported yet
22229
812
95