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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tonyism1/dom-utils

v1.0.0

Published

Lightweight DOM manipulation utilities (jQuery-lite)

Downloads

5

Readme

DOM Utils - A Lightweight jQuery-like DOM Utility Library

This is a lightweight, jQuery-like DOM utility library designed for easy manipulation of the Document Object Model (DOM) in web browsers. It provides a simple API for selecting elements, modifying content, handling events, and more, without the overhead of a full-fledged library like jQuery.

Project Structure

dom-utils/
├── package.json
├── index.js
├── README.md
├── demo/
│   ├── index.html
│   └── demo.css

Features

  • $(selector, context): Selects the first element matching the CSS selector within the given context (defaults to document). Returns a wrapped element object with utility methods.
  • $all(selector, context): Selects all elements matching the CSS selector within the given context. Returns an array of wrapped element objects.
  • Chainable Methods: Most methods return the wrapped element object, allowing for method chaining.
  • DOM Manipulation: html(), text(), val(), append(), prepend(), remove(), empty(), clone()
  • Attribute & Data Handling: attr(), removeAttr(), data()
  • Class Manipulation: addClass(), removeClass(), toggleClass(), hasClass()
  • CSS Styling: css() for getting and setting inline styles.
  • Event Handling: on(), off(), trigger()
  • Display Control: show(), hide(), toggle()

Installation

You can install dom-utils via npm:

npm install dom-utils

Usage

ES Module (Recommended)

import { $, $all } from 'dom-utils';

// Update content
$("#title").text("Hello from DOM Util Lite!");

// Add event listener
$("#myButton").on("click", () => {
  $("#output")
    .text("Button Clicked!")
    .addClass("active")
    .css({ color: "red", fontWeight: "bold" });

  $("#list").append("<li>New Item</li>");
});

// Multiple items
$all(".item").forEach((item, i) => {
  item.text("Item " + (i + 1));
});

// Attribute & dataset
$("#link").attr("href", "https://example.com").data("track", "outbound");

CommonJS

const { $, $all } = require('dom-utils');

// Your code here

Direct Inclusion (Global Scope)

If you prefer, you can still include index.js directly in your HTML file using a <script> tag. This will expose $ and $all globally.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>DOM Util Lite Demo</title>
  <link rel="stylesheet" href="demo/demo.css" />
</head>
<body>
  <h1 id="title">DOM Util Lite</h1>

  <button id="myButton">Click Me</button>
  <p id="output"></p>

  <ul id="list">
    <li class="item">Old Item 1</li>
    <li class="item">Old Item 2</li>
  </ul>

  <a id="link" href="#">Link</a>

  <script src="./index.js"></script>
  <script>
    // Update content
    $("#title").text("Hello from DOM Util Lite!");

    // Add event listener
    $("#myButton").on("click", () => {
      $("#output")
        .text("Button Clicked!")
        .addClass("active")
        .css({ color: "red", fontWeight: "bold" });

      $("#list").append("<li>New Item</li>");
    });

    // Multiple items
    $all(".item").forEach((item, i) => {
      item.text("Item " + (i + 1));
    });

    // Attribute & dataset
    $("#link").attr("href", "https://example.com").data("track", "outbound");
  </script>
</body>
</html>

Running the Demo

  1. Install serve globally (if you haven't already):
    npm install -g serve
  2. Navigate to the project root and start the server:
    npm run start
  3. Open your browser and go to http://localhost:3000/demo/index.html (or the address provided by serve).

Development

To contribute or develop further:

  1. Clone the repository.
  2. Make your changes to index.js.
  3. Test your changes using the demo/index.html file.

License

This project is licensed under the MIT License.