Skip to content

Commit

Permalink
Add support for empty separator (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnovsky authored Jul 18, 2020
1 parent 774c5b9 commit d7bf7cc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ declare namespace slugify {
slugify('BAR and baz', {separator: '_'});
//=> 'bar_and_baz'
slugify('BAR and baz', {separator: ''});
//=> 'barandbaz'
```
*/
readonly separator?: string;
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const slugify = (string, options) => {

string = string.replace(patternSlug, options.separator);
string = string.replace(/\\/g, '');
string = removeMootSeparators(string, options.separator);
if (options.separator) {
string = removeMootSeparators(string, options.separator);
}

if (shouldPrependUnderscore) {
string = `_${string}`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"id"
],
"dependencies": {
"@sindresorhus/transliterate": "^0.1.0",
"@sindresorhus/transliterate": "^0.1.1",
"escape-string-regexp": "^4.0.0"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ slugify('BAR and baz');

slugify('BAR and baz', {separator: '_'});
//=> 'bar_and_baz'

slugify('BAR and baz', {separator: ''});
//=> 'barandbaz'
```

##### lowercase
Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test('main', t => {

test('custom separator', t => {
t.is(slugify('foo bar', {separator: '_'}), 'foo_bar');
t.is(slugify('aaa bbb', {separator: ''}), 'aaabbb');
t.is(slugify('BAR&baz', {separator: '_'}), 'bar_and_baz');
t.is(slugify('Déjà Vu!', {separator: '-'}), 'deja-vu');
t.is(slugify('UNICORNS AND RAINBOWS!', {separator: '@'}), 'unicorns@and@rainbows');
Expand Down

0 comments on commit d7bf7cc

Please sign in to comment.