Skip to content

Commit

Permalink
fix: slug type does not remove non-alphanumeric characters (#24)
Browse files Browse the repository at this point in the history
* fix: slug type does not remove special characters

Closes #23

* fix: slug type does not trim whitespace

* test: correction to name of slug test
  • Loading branch information
acodeninja authored Jan 24, 2025
1 parent 0eb072c commit d1bdaa9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/type/resolved/SlugType.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class SlugType extends ResolvedType {

return slugify(model?.[property], {
lower: true,
strict: true,
trim: true,
});
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/type/resolved/SlugType.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ test('SlugType.of(name).resolve({name: \'Testing the Slug\')) returns \'testing-
t.is(SlugType.of('name').resolve({name: 'Testing the Slug'}), 'testing-the-slug');
});

test('SlugType.of(name).resolve({name: \' Trimming whitespace \')) returns \'trimming-whitespace\'', t => {
t.is(SlugType.of('name').resolve({name: ' Trimming whitespace '}), 'trimming-whitespace');
});

test('SlugType.of(name).resolve()) returns \'\'', t => {
t.is(SlugType.of('name').resolve(), '');
});

test('SlugType.of(special).resolve({special: \'don\'t include special characters\')) returns \'dont-include-special-characters\'', t => {
t.is(SlugType.of('special').resolve({special: 'don\'t include special characters'}), 'dont-include-special-characters');
});

0 comments on commit d1bdaa9

Please sign in to comment.