instance-verification
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

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:

    const divs = getElementsWithClassName('div', HTMLDivElement)

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

Package Sidebar

Install

npm i instance-verification

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

19.3 kB

Total Files

11

Last publish

Collaborators

  • juanchibm