added prettier and eslint for dev

This commit is contained in:
2022-06-30 11:29:39 +02:00
parent 0039e54de2
commit 77c3b90d02
17 changed files with 3301 additions and 1488 deletions

32
lib/domUtils.ts Normal file
View File

@@ -0,0 +1,32 @@
export const addGlobalEventListener = (
type: string,
selector: string,
callback: (arg0: Event) => void,
options: boolean | AddEventListenerOptions,
parent = document
): void => {
parent.addEventListener(
type,
(e: Event) => {
if (e != null && e.target != null) {
const el = e.target as Element
if (el.matches(selector)) callback(e)
}
},
options
)
}
export const qs = (
selector: string | keyof HTMLElementTagNameMap,
parent = document
): Element => {
return parent.querySelector(selector)
}
export const qsa = (
selector: string | keyof HTMLElementTagNameMap,
parent = document
): Element[] => {
return [...parent.querySelectorAll(selector)]
}