Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deal with custom transformations correctly #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/speakingurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
Expand Down
6 changes: 6 additions & 0 deletions test/test-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
'[': '[',
Expand Down