useful utils
npm install kpripper-libkpripper-lib is a JavaScript library that provides a utility function, waitForElement, which allows you to wait for a specific DOM element to appear in the document. This is particularly useful for scenarios where elements are dynamically added to the DOM.
You can install the library using npm:
```
npm install kpripper-lib
`javascript`
const { waitForElement } = require("kpripper-lib")
`javascript`
import { waitForElement } from "kpripper-lib"
`javascript`
const element = await waitForElement(".my-class", {
scope: document.querySelector(".container"),
timeout: 10000,
})
- selector: A string representing the CSS selector to match the element.
- options: An optional object to configure the search.
- scope: The DOM element or document to search within (default is document).5000
- timeout: The maximum time to wait in milliseconds (default is ).
The domWatcher is a singleton instance that helps you watch for DOM elements appearing and disappearing from the document.
#### Examples
`javascript
// Example 1: Watching for an element to appear
domWatcher.watch(".my-class", (element) => {
console.log("Element appeared:", element);
});
// Example 2: Watching for an element to disappear
domWatcher.watch(".my-class", null, (element) => {
console.log("Element disappeared:", element);
});
``
This project is licensed under the MIT License.