fix: make dasherize trim first

This commit is contained in:
Oliver Eyton-Williams
2019-09-26 18:08:17 +02:00
committed by mrugesh
parent 3dc4e5897d
commit f159645810
2 changed files with 6 additions and 3 deletions

View File

@ -1,6 +1,7 @@
exports.dasherize = function dasherize(name) { exports.dasherize = function dasherize(name) {
return ('' + name) return ('' + name)
.toLowerCase() .toLowerCase()
.trim()
.replace(/\s/g, '-') .replace(/\s/g, '-')
.replace(/[^a-z\d\-.]/g, ''); .replace(/[^a-z\d\-.]/g, '');
}; };

View File

@ -11,9 +11,11 @@ describe('dasherize', () => {
expect(dasherize('UPPERCASE')).toBe('uppercase'); expect(dasherize('UPPERCASE')).toBe('uppercase');
}); });
it('converts spaces to dashes', () => { it('converts spaces to dashes', () => {
expect(dasherize(' the space between ')).toBe( expect(dasherize('the space between')).toBe('the-space--between');
'--the-space--between----' });
);
it('trims off surrounding whitespace', () => {
expect(dasherize(' the space between ')).toBe('the-space--between');
}); });
it('removes everything except letters, numbers, - and .', () => { it('removes everything except letters, numbers, - and .', () => {