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

@butility/dom

v1.0.1

Published

Welcome to the Utility package! This library provides a comprehensive set of tools for manipulating HTML elements, managing attributes and classes, handling events, and traversing the DOM. With features designed to streamline web development, this package

Downloads

121

Readme

Butility DOM Utils

Welcome to the Utility package! This library provides a comprehensive set of tools for manipulating HTML elements, managing attributes and classes, handling events, and traversing the DOM. With features designed to streamline web development, this package is essential for modern web applications.

Features

  • Attribute Management: Easily get, set, remove, and toggle HTML attributes.
  • Class Management: Add, remove, and toggle CSS classes with various conditions and options.
  • Element Creation and Manipulation: Create and modify HTML elements dynamically.
  • Event Handling: Simplify event delegation and data management for DOM events.
  • DOM Traversal: Efficiently find and manipulate elements in the DOM tree.

Installation

To install the package, you can use npm or CDN:

npm install @butility/dom
<!-- To use all the functions and methods -->
<script src="https://unpkg.com/@butility/dom@latest/dom.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@butility/dom@latest/dom.js" type="module"></script>
<!-- To use HTML utils -->
<script src="https://unpkg.com/@butility/dom@latest/html.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@butility/dom@latest/html.js" type="module"></script>
<!-- To use Element utils -->
<script src="https://unpkg.com/@butility/dom@latest/element.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@butility/dom@latest/element.js" type="module"></script>
<!-- To use Event utils -->
<script src="https://unpkg.com/@butility/dom@latest/event.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@butility/dom@latest/event.js" type="module"></script>
<!-- To use Class utils -->
<script src="https://unpkg.com/@butility/dom@latest/class.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@butility/dom@latest/class.js" type="module"></script>
<!-- To use Attribute utils -->
<script src="https://unpkg.com/@butility/dom@latest/attribute.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@butility/dom@latest/attribute.js" type="module"></script>

Examples

// Function based html creation
import { body, head, div, button, title, meta, a, ul, li, img, h1, p} from "@butility/dom/html";

head(
    title("my dom package"),
    meta({name: "", content: ""}),
)
// This will append all the children to the body
body(
    div({ class: "content-wrapper" },
        h1("Welcome!"),
        p("This is an example paragraph."),
        button({ class: "btn-primary", onclick: "console.log(\"i am clicked\")" }, "Click Me"),
        a({ href: "https://github.com/butility" }, "Butility"),
        ul(
            li("Item 1"),
            li("Item 2")
        ),
        img({ src: "image.png", alt: "Example image" })
    )
)

import ClassUtils from "@butility/dom/class";
import Element from "@butility/dom/element";
import Attribute from "@butility/dom/attribute";

ClassUtils.toggleClassOnConnectionStatus(button, "online", "offline");
ClassUtils.toggleClassOnCopy(button, "copied");
ClassUtils.toggleClassOnOrientationChange(button, "orientation"); // output class name `orientation-portrait or landscape
ClassUtils.toggleClassOnDeviceMotion(button, "moved"); // like when device is tilted
ClassUtils.addUniqueClass(button, "unique-class")
ClassUtils.toggleClassOnGeolocationChange(button, "location-changed", {
    enableThrottling: true,
    throttleInterval: 6000, // 6 sec
    onClassToggle: () => {} // Change UI 
});

Element.setHTML(script, "console.log(\"hi\")", true); // setHTML to script
Attribute.setAttribute(button, {
    class: "button-class",
    set: "custom data-set"
}, { addPrefix: true })

Documentation

For @butility/dom documentation refer to the docs folder.

Changelog

You can find changelog here

License

This project is licensed under the MIT License.