Skip to content

Commit c7b05ad

Browse files
keithamusmuan
andcommitted
fix: correctly dasherize cap suffixes
Co-authored-by: Mu-An Chiou <me@muanchiou.com>
1 parent 05aaeaa commit c7b05ad

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/register.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface CustomElement {
1111
*/
1212
export function register(classObject: CustomElement): void {
1313
const name = classObject.name
14-
.replace(/([A-Z][a-z])/g, '-$1')
14+
.replace(/([A-Z]($|[a-z]))/g, '-$1')
1515
.replace(/(^-|-Element$)/, '')
1616
.toLowerCase()
1717
if (!window.customElements.get(name)) {

test/register.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ describe('register', () => {
3434
expect(window.customElements.get('url-bar')).to.equal(URLBar)
3535
})
3636

37+
it('dasherizes cap suffixed names correctly', () => {
38+
class ClipX {}
39+
register(ClipX)
40+
expect(window.customElements.get('clip-x')).to.equal(ClipX)
41+
})
42+
3743
it('automatically drops the `Element` suffix', () => {
3844
class ASuffixedElement {}
3945
register(ASuffixedElement)

0 commit comments

Comments
 (0)