Comparing version 4.0.3 to 4.0.4
@@ -0,1 +1,8 @@ | ||
## [4.0.4](https://github.com/Trott/slug/compare/v4.0.3...v4.0.4) (2021-04-16) | ||
### Bug Fixes | ||
* honor special character replacements in charmap ([f5e18c9](https://github.com/Trott/slug/commit/f5e18c9ff8e21e5c5bc636f34b811b4b73e1b204)) | ||
## [4.0.3](https://github.com/Trott/slug/compare/v4.0.2...v4.0.3) (2021-02-24) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "slug", | ||
"description": "slugifies even utf-8 chars!", | ||
"version": "4.0.3", | ||
"version": "4.0.4", | ||
"homepage": "https://github.com/Trott/slug", | ||
@@ -6,0 +6,0 @@ "author": "dodo (https://github.com/dodo)", |
12
slug.js
@@ -174,2 +174,4 @@ /* global btoa */ | ||
const disallowedChars = opts.mode === 'rfc3986' ? /[^\w\s\-.~]/ : /[^A-Za-z0-9\s]/ | ||
let result = '' | ||
@@ -194,10 +196,12 @@ for (let char, i = 0, l = string.length; i < l; i++) { | ||
char = opts.charmap[char] | ||
} else if (char.includes(opts.replacement)) { | ||
// preserve the replacement character in case it is excluded by disallowedChars | ||
char = char.replace(opts.replacement, ' ') | ||
} else { | ||
char = char.replace(disallowedChars, '') | ||
} | ||
} | ||
// next line preserves the replacement character in case it is included in allowedChars | ||
char = char.replace(opts.replacement, ' ') | ||
result += char | ||
} | ||
const allowedChars = opts.mode === 'rfc3986' ? /[^\w\s\-.~]/g : /[^A-Za-z0-9\s]/g | ||
result = result.replace(allowedChars, '') // allowed | ||
if (opts.remove) { | ||
@@ -204,0 +208,0 @@ result = result.replace(opts.remove, '') |
28623
878