Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kebab case function to handle names with digits #43

Merged
merged 3 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/services/naming-conventions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const kebabCase = input => {
return input
.trim()
.replace(/[ _]/g, '-') // from snake_case (or spaces)
.replace(/([a-z])([A-Z])/g, '$1-$2') // from PascalCase or camelCase
.replace(/([a-z\d])([A-Z])/g, '$1-$2') // from PascalCase or camelCase
.toLowerCase()
.replace(/-+/g, '-') // remove duplicate dashes
.replace(/^-|-$/g, ''); // remove leading and trailing dashes
Expand Down
5 changes: 5 additions & 0 deletions test/services/naming-conventions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ describe('services', () => {
expect(kebabCase('OneTwoThree')).to.equal('one-two-three');
});

test.it('handles PascalCase with digits', () => {
expect(kebabCase('One1Two')).to.equal('one1-two');
expect(kebabCase('One1Two2Three')).to.equal('one1-two2-three');
});

test.it('handles kebab-case', () => {
expect(kebabCase('one-two')).to.equal('one-two');
expect(kebabCase('one-two-three')).to.equal('one-two-three');
Expand Down