Skip to content

Commit

Permalink
Remove leading/trailing hyphens (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
angus-c authored May 8, 2022
1 parent cefd53b commit 8dedcd1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/string-kebab-case/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ function kebabCase(str) {
return str
.trim()
.split(wordSeparators)
.join('-');
.join('-')
.replace(/^-/, '')
.replace(/-\s*$/, '');
}
7 changes: 7 additions & 0 deletions test/string-kebab-case/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ test('string with mixed spaces and punctuation', function(t) {
t.end();
});

test('string with leading or trailing punctuation', function(t) {
t.plan(2);
t.equal(kebabCase('*Rank Ordinal*'), 'rank-ordinal');
t.equal(kebabCase('Rank (Ordinal)'), 'rank-ordinal');
t.end();
});

test('string with capitalization', function(t) {
t.plan(8);
t.equal(kebabCase('theQuickBrownFox'), 'the-quick-brown-fox');
Expand Down

0 comments on commit 8dedcd1

Please sign in to comment.