Skip to content
Permalink
Browse files

fix: make dasherize trim first

  • Loading branch information...
ojeytonwilliams authored and raisedadead committed Sep 26, 2019
1 parent 3dc4e58 commit f1596458108b8dce1dd2743178f2d177dcc826e8
Showing with 6 additions and 3 deletions.
  1. +1 −0 utils/slugs.js
  2. +5 −3 utils/slugs.test.js
@@ -1,6 +1,7 @@
exports.dasherize = function dasherize(name) {
return ('' + name)
.toLowerCase()
.trim()
.replace(/\s/g, '-')
.replace(/[^a-z\d\-.]/g, '');
};
@@ -11,9 +11,11 @@ describe('dasherize', () => {
expect(dasherize('UPPERCASE')).toBe('uppercase');
});
it('converts spaces to dashes', () => {
expect(dasherize(' the space between ')).toBe(
'--the-space--between----'
);
expect(dasherize('the space between')).toBe('the-space--between');
});

it('trims off surrounding whitespace', () => {
expect(dasherize(' the space between ')).toBe('the-space--between');
});

it('removes everything except letters, numbers, - and .', () => {

0 comments on commit f159645

Please sign in to comment.
You can’t perform that action at this time.