Skip to content

Commit

Permalink
Support empty string replacement and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zertz-Lenovo committed Dec 19, 2014
1 parent bb278ca commit 54ca940
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions slug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/slug.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 54ca940

Please sign in to comment.