diff --git a/slug.js b/slug.js index fb95d99..ceebea7 100644 --- a/slug.js +++ b/slug.js @@ -10,14 +10,15 @@ function symbols(code) { } function slug(string, opts) { - opts = opts || {}; string = string.toString(); if ('string' === typeof opts) opts = {replacement:opts}; + opts = opts || {}; opts.mode = opts.mode || slug.defaults.mode; var defaults = slug.defaults.modes[opts.mode]; ['replacement','multicharmap','charmap','remove'].forEach(function (key) { - opts[key] = opts[key] || defaults[key]; + if ('replacement' !== key || 'string' !== typeof opts[key]) + opts[key] = opts[key] || defaults[key]; }); if ('undefined' === typeof opts.symbols) opts.symbols = defaults.symbols; diff --git a/test/slug.test.coffee b/test/slug.test.coffee index 3aa690b..fe2e717 100644 --- a/test/slug.test.coffee +++ b/test/slug.test.coffee @@ -8,6 +8,7 @@ describe 'slug', -> it 'should replace whitespaces with replacement', -> [slug 'foo bar baz'].should.eql ['foo-bar-baz'] [slug 'foo bar baz', '_'].should.eql ['foo_bar_baz'] + [slug 'foo bar baz', ''].should.eql ['foobarbaz'] it 'should remove trailing space if any', -> [slug ' foo bar baz '].should.eql ['foo-bar-baz']