Skip to content

Commit

Permalink
Remove contractions and possessives (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
aegatlin authored Jan 28, 2023
1 parent fe4d089 commit 48a9112
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export default function slugify(string, options) {

string = string.replace(patternSlug, options.separator);
string = string.replace(/\\/g, '');

// Detect contractions/possessives by looking for any word followed by a `-t`
// or `-s` in isolation and then remove it.
string = string.replace(/([a-zA-Z\d]+)-([ts])(-|$)/g, '$1$2$3');

if (options.separator) {
string = removeMootSeparators(string, options.separator);
}
Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ test('main', t => {
t.is(slugify('Util APIs'), 'util-apis');
});

test('possessives and contractions', t => {
t.is(slugify('Conway\'s Law'), 'conways-law');
t.is(slugify('Conway\'s'), 'conways');
t.is(slugify('Don\'t Repeat Yourself'), 'dont-repeat-yourself');
t.is(slugify('my parents\' rules'), 'my-parents-rules');
});

test('custom separator', t => {
t.is(slugify('foo bar', {separator: '_'}), 'foo_bar');
t.is(slugify('aaa bbb', {separator: ''}), 'aaabbb');
Expand Down

0 comments on commit 48a9112

Please sign in to comment.