Skip to content

Commit

Permalink
test: coverage for util (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc authored Nov 17, 2020
1 parent c4ae3b5 commit aeb93d9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 2 additions & 0 deletions __tests__/unit/utils/kebab-case-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ describe('kebabCase', () => {
expect(kebabCase('fontSize')).toEqual('font-size');
expect(kebabCase('aBBB')).toEqual('a-b-b-b');
expect(kebabCase('aBcDeFggggHHH')).toEqual('a-bc-de-fgggg-h-h-h');

expect(kebabCase('520')).toEqual('5-2-0');
});
});
6 changes: 1 addition & 5 deletions src/utils/kebab-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ export function kebabCase(word: string) {
return word;
}
const result = word.match(/(([A-Z]{0,1}[a-z]*[^A-Z])|([A-Z]{1}))/g);
return result
? result.reduce((a, b) => {
return `${a ? `${a.toLowerCase()}-` : ''}` + b.toLowerCase();
})
: '';
return result.map((s: string) => s.toLowerCase()).join('-');
}

0 comments on commit aeb93d9

Please sign in to comment.