diff --git a/lib/speakingurl.js b/lib/speakingurl.js index 4a62bc0..4e2ee50 100644 --- a/lib/speakingurl.js +++ b/lib/speakingurl.js @@ -1460,7 +1460,8 @@ if (typeof opts === 'object') { maintainCase = opts.maintainCase || false; - customReplacements = (opts.custom && typeof opts.custom === 'object') ? opts.custom : customReplacements; + const customIsObject = typeof opts.custom === 'object' + customReplacements = (opts.custom && customIsObject) ? opts.custom : customReplacements; truncate = (+opts.truncate > 1 && opts.truncate) || false; uricFlag = opts.uric || false; uricNoSlashFlag = opts.uricNoSlash || false; @@ -1511,6 +1512,8 @@ if (v.length > 1) { r = new RegExp('\\b' + escapeChars(v) + '\\b', 'gi'); + } else if (customIsObject && /^[0-9]$/.test(v)) { + r = null } else { r = new RegExp(escapeChars(v), 'gi'); } diff --git a/test/test-custom.js b/test/test-custom.js index aea5ef0..959b98f 100644 --- a/test/test-custom.js +++ b/test/test-custom.js @@ -16,6 +16,12 @@ describe('getSlug with custom replacement', function () { }) .should.eql('буу'); + getSlug('top 100 waterfalls', { + custom: ['.'] + }) + .should.eql('top-100-waterfalls'); + + getSlug('[nodejs]', { custom: { '[': '[',