Skip to content

Commit 9b9ea51

Browse files
committed
feat: drop Element suffix from controller classes
1 parent 4279ccf commit 9b9ea51

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/register.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ interface CustomElement {
1010
* Example: HelloController => hello-controller
1111
*/
1212
export function register(classObject: CustomElement): void {
13-
const name = classObject.name.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase()
13+
const name = classObject.name
14+
.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-')
15+
.replace(/-Element$/, '')
16+
.toLowerCase()
1417
if (!window.customElements.get(name)) {
1518
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1619
// @ts-ignore

test/register.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ describe('register', () => {
2727
ThisIsAnExampleOfADasherisedClassName
2828
)
2929
})
30+
31+
it('automatically drops the `Element` suffix', () => {
32+
class ASuffixedElement {}
33+
register(ASuffixedElement)
34+
expect(window.customElements.get('a-suffixed')).to.equal(ASuffixedElement)
35+
})
3036
})

0 commit comments

Comments
 (0)