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

@wmdigi/dom

v1.1.3

Published

A lightweight, type-safe DOM manipulation library with jQuery-like syntax.

Downloads

421

Readme

@wmdigi/dom

A lightweight, type-safe DOM manipulation library with jQuery-like syntax.

Installation

# Using npm
npm install @wmdigi/dom

# Using yarn
yarn add @wmdigi/dom

# Using bun
bun add @wmdigi/dom

Usage

import { $ } from "@wmdigi/dom";

// Basic selectors
$(".button").addClass("active");
$("#main").hide();
$('input[type="text"]').val("Hello");

// Class checking
if ($(".card").hasClass("active")) {
	console.log("Card is active");
}

// Timeout utility
const clear = $.timeout(() => {
	console.log("This will run after 1 second");
}, 1000);

// Optional: Cancel timeout
clear();

// Chaining
$(".card").addClass("highlight").attr("data-active", "true").show();

// Type-safe event handling
$<HTMLButtonElement>(".submit-button").on("click", (e) => {
	console.log("Button clicked at:", e.clientX, e.clientY);
});

// Input handling with type safety
$<HTMLInputElement>('input[name="email"]').val("[email protected]");

// DOM Ready
$.ready(() => {
	console.log("DOM is ready");
});

// Creating elements
$.create('<div class="new">Content</div>').addClass("active");

API

Selectors

  • $(selector) - Select elements using CSS selector
  • $(element) - Wrap DOM element
  • $(elements) - Wrap array of DOM elements

Methods

  • .first - Get first element
  • .array - Get array of elements

Values & Content

  • .val([value]) - Get/set input value
  • .text([content]) - Get/set text content

Classes

  • .addClass(...classes) - Add classes
  • .removeClass(...classes) - Remove classes
  • .toggleClass(class) - Toggle class
  • .hasClass(class) - Check if element has class

Attributes

  • .attr(name, [value]) - Get/set attribute

Events

  • .on(event, callback) - Add event listener

Display

  • .hide() - Hide elements
  • .show() - Show elements

Static Methods

  • $.ready(callback) - DOM ready handler
  • $.create(html) - Create element from HTML
  • $.timeout(callback, ms) - Execute callback after delay with auto cleanup

Type Safety

The library is fully typed and provides TypeScript support out of the box:

// Proper type inference
$<HTMLInputElement>("input").val(); // Returns string
$<HTMLButtonElement>("button").on("click", (e) => {
	// e is properly typed as MouseEvent
});

Development

# Clone the repository
git clone https://github.com/wmdigi/dom.git
cd dom

# Install dependencies
bun install

# Build
bun run build

Publishing

# Publish patch version (1.0.0 -> 1.0.1)
bun pub

# Publish minor version (1.0.0 -> 1.1.0)
bun pub minor

# Publish major version (1.0.0 -> 2.0.0)
bun pub major

This will automatically:

  1. Build the library
  2. Commit changes
  3. Bump version
  4. Push to git (with tags)
  5. Publish to npm

License

MIT

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Credits

Created by Wonder Makers - a digital studio, making the web simpler, one library at a time.