Skip to content

JuanchiiBM/instance-verification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

With this module you can avoid typical typescript errors, such as making mistakes when you are selecting elements from the DOM

Instance Verification

Instance Verification is a module that will allow us to obtain elements from the DOM making sure they exist before taking them

Why Use It?

Many times we put the ID wrong in our constant and there is no error until we want to manipulate it, with these functions, those problems cease to exist, or also, when we get confused and let typescript treat our elements with instances that really are not the correct ones.

How To Use

There will be 5 functions that we will have available:

const btn = getElementWithId('btnID', HTMLButtonElement)
const btn = getElementsWithClassName('btnClass', HTMLButtonElement)
const btn = getElementsWithName('btnName', HTMLButtonElement)
const btn = getFirstElementWithClassName('btnClass', HTMLButtonElement)
const btn = getFirstElementWithName('btnName', HTMLButtonElement)

Example

HTML:

    <div class="div"></div>
    <div class="div"></div>
    <button class="div"></button>
    <div class="div"></div>
    <div class="div"></div>

TS:

    import { getElementsWithClassName } from 'instance-verification'

    const divs = getElementsWithClassName('div', HTMLDivElement)

Error: The children element '2' with the class: 'div' isn't an HTMLDivElement

About

With this module you can avoid typical typescript errors, such as making mistakes when you are selecting elements from the DOM but you type the ID wrong

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors