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

@m5nv/dom

v1.0.0

Published

A nano jQuery‑like DOM manipulation library

Readme

Dom (@m5nv/dom)

A nano‑jQuery–like DOM manipulation library for evergreen browsers.


Overview

@m5nv/dom is a zero‑dependency library that wraps most commonly used native DOM APIs in a chainable, jQuery‑like fluent API. Event binding, class manipulation (add, remove, toggle, has), attribute handling, CSS styling, and DOM traversal can be achieved with much less code without loss of performance or code comprehension.

Why

The Document Object Model is like a castle. You might know it exists and have seen it in action using your favorite frameworks. The hard truth is you don't know it well enough until you explore it on your own.

Frameworks are like tour buses with tour guides—they keep you on the trodden path. On the flip side, exploring the DOM using its API can get tiring. You know the roads to take to get to the parts of the DOM you want to interact with—up close. This library is designed to be your bicycle, helping you get there faster without the baggage or the guardrails offered by frameworks.

Concepts

Selectors

A selector in @m5nv/dom is a value used to specify which DOM elements to wrap into a chainable collection. The library supports several types of selectors:

  • CSS Selectors (String):
    Pass a CSS selector string (e.g., "#myId", ".my-class", "div > p") to internally use document.querySelectorAll to select elements.

  • DOM Node:
    Pass a single DOM node (e.g., the result of document.getElementById("myId")) to wrap that specific element.

  • NodeList or Array of Nodes:
    Pass a NodeList (e.g., from document.querySelectorAll) or an array of DOM nodes, and each node will be wrapped.

  • Global Objects:
    Pass the global window or document objects to work with them directly.

By abstracting selectors, @m5nv/dom enables you to interact with any set of elements in a consistent, chainable way.

Features

  • Minimal Footprint:
    Minimal code with no loss in performance.

  • Chainable API:
    Write fluent code that reads naturally—no more nesting callbacks or cumbersome syntax.

Installation

npm

npm install @m5nv/dom

Usage

Import the default export (recommended aliases: $ or dom):

import $ from "@m5nv/dom";

Example: Selecting Elements & Event Binding

// Bind a click event to a button
$("#myButton").on("click", () => console.log("Button clicked!"));

// Toggle a class on an element
$("#myPanel").toggleClass("active");

Equivalence Examples

1. Element Selection & Event Binding

Native DOM:

const btn = document.getElementById("myButton");
btn.addEventListener("click", () => console.log("Clicked!"));

@m5nv/dom:

$("#myButton").on("click", () => console.log("Clicked!"));

2. Class Manipulation

Native DOM:

document.querySelector(".item").classList.add("active");
document.querySelector(".item").classList.toggle("active");
const has = document.querySelector(".item").classList.contains("active");

@m5nv/dom:

$(".item").addClass("active");
$(".item").toggleClass("active");
const has = $(".item").hasClass("active");

3. DOM Traversal

Native DOM:

const parent = document.getElementById("child").parentNode;

@m5nv/dom:

$("#child").parent();

API Reference

When you call dom(selector), you receive an object with the following methods:

Selection & Traversal

  • dom(sel)
    Wraps a CSS selector, DOM node, or NodeList into a chainable object.

  • find(selector)
    Returns a new wrapped collection of descendant elements.

  • closest(selector)
    Returns the nearest ancestor matching the selector.

  • next()
    Returns the next sibling element.

  • parent()
    Returns the parent node.

Event Binding

  • on(event, callback)
    Binds an event listener to all selected elements.

Iteration

  • each(callback)
    Iterates over each element, passing (index, element) to the callback.

Class Manipulation

  • addClass(className)
    Adds the specified class to all elements.

  • removeClass(className)
    Removes the specified class from all elements.

  • toggleClass(className)
    Toggles the class on all elements.

  • hasClass(className)
    Returns a boolean indicating if the first element has the specified class.

Attributes & CSS

  • attr(name, value?)
    Gets or sets an attribute. (If value is omitted, returns the attribute on the first element.)

  • css(property, value)
    Sets an inline CSS style on all elements.

Contributing

Contributions to improve @m5nv/dom are welcome. Please submit issues or pull requests on our GitHub repository.

License

Distributed under the MIT License. See LICENSE for details.


Happy DOM-ing!