npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@knighttower/element-helper

v1.0.11

Published

ElementHelper is a JavaScript class that adds extra functionality to interact with DOM elements. This class is part of a larger project and can be imported from the @knighttower/adaptive package.

Downloads

19

Readme

ElementHelper Class Documentation

yarn add @knighttower/element-helper
import ElementHelper from '@knighttower/element-helper';

Overview

ElementHelper is a JavaScript class that adds extra functionality to interact with DOM elements. This class is part of a larger project and can be imported from the @knighttower/adaptive package.

Table of Contents

  1. Author and License
  2. Class Definition
  3. Constructor
  4. Public Methods
  5. Private Section
  6. Examples

Author and License

Class Definition

export default class ElementHelper

Parameters

  • selector (String|Object): Class, ID, or DOM element.
  • scope (String): The scope to search in. Defaults to document.

Return

  • Returns an Object instance of ElementHelper.

Examples

const element = new ElementHelper('elementSelector') // return the DOM element
const element = new ElementHelper('elementSelector', domElement|window|document)

Constructor

constructor(selector, scope = document)

Initializes the ElementHelper class with the given selector and scope.

Public Methods

isInDom()

  • Returns: Boolean
  • Description: Checks if the element exists or is visible in the DOM.

whenInDom()

  • Returns: Promise
  • Description: Waits until the element exists or becomes visible in the DOM.
  • const element = new ElementHelper('elementSelector').whenInDom() // element.then() => {}

getElementByXpath(xpath)

  • Parameters: xpath (String)
  • Returns: Object (DOM element)
  • Description: Finds an element by its XPath string.
  • Example: getElementByXpath("//html[1]/body[1]/div[1]")

getXpathTo()

  • Returns: String
  • Description: Returns the XPath string of the element.
  • Example: const elementPath = new ElementHelper('elementSelector').getXpathTo()

getAttribute(attr)

  • Parameters: attr (String)
  • Returns: String|Array|Object|Null
  • Description: Gets the value of the specified attribute.
  • Example: const elementAttr = new ElementHelper('elementSelector').getAttribute('style') // returns all inline styles

getHash()

  • Returns: String
  • Description: Creates a unique hash for the element derived from its XPath.

Private Section

This section is reserved for future enhancements, possibly to extend the prototype of DOM elements.

Examples

const element = new ElementHelper('.my-class');
if (element.isInDom()) {
  // Do something
}

element.whenInDom().then((elem) => {
  // Do something when element is in DOM
});

const attrValue = element.getAttribute('data-attribute');

This documentation covers all the features, methods, and examples mentioned in the provided code. Please note that the code relies on DomObserver from the @knighttower/js-dom-observer package, which is not covered in this documentation.