Skip to content

Commit 606c825

Browse files
keithamusmuan
andcommitted
fix: always remove leading - and Element suffix
Co-authored-by: Mu-An Chiou <me@muanchiou.com>
1 parent c7b05ad commit 606c825

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/register.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface CustomElement {
1212
export function register(classObject: CustomElement): void {
1313
const name = classObject.name
1414
.replace(/([A-Z]($|[a-z]))/g, '-$1')
15-
.replace(/(^-|-Element$)/, '')
15+
.replace(/(^-|-Element$)/g, '')
1616
.toLowerCase()
1717
if (!window.customElements.get(name)) {
1818
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

test/register.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ describe('register', () => {
4141
})
4242

4343
it('automatically drops the `Element` suffix', () => {
44-
class ASuffixedElement {}
45-
register(ASuffixedElement)
46-
expect(window.customElements.get('a-suffixed')).to.equal(ASuffixedElement)
44+
class AutoCompleteElement {}
45+
register(AutoCompleteElement)
46+
expect(window.customElements.get('auto-complete')).to.equal(AutoCompleteElement)
4747
})
4848
})

0 commit comments

Comments
 (0)