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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lutlelk-tools/dom

v1.0.0

Published

DOM utilities including element selection, class manipulation, style management, and event handling

Readme

@lutlelk-tools/dom

A lightweight DOM manipulation utility library for JavaScript/TypeScript.

Installation

npm install @lutlelk-tools/dom
# or
pnpm add @lutlelk-tools/dom
# or
yarn add @lutlelk-tools/dom

Usage

import { $, $$, addClass, on, createElement } from '@lutlelk-tools/dom'

API

Selector

$(selector: string, context?: ParentNode): Element | null

Select a single element using CSS selector.

const el = $('.my-class')
const el2 = $('#my-id', container)

$$(selector: string, context?: ParentNode): Element[]

Select multiple elements using CSS selector.

const els = $$('.my-class')
const els2 = $('div', container)

Class Operations

addClass(element: Element, ...classNames: string[]): void

Add one or more class names to an element.

addClass(el, 'class1', 'class2')

removeClass(element: Element, ...classNames: string[]): void

Remove one or more class names from an element.

removeClass(el, 'class1', 'class2')

toggleClass(element: Element, className: string, force?: boolean): boolean

Toggle a class name on an element. Returns the new state.

toggleClass(el, 'active')
toggleClass(el, 'active', true)  // force add
toggleClass(el, 'active', false) // force remove

hasClass(element: Element, className: string): boolean

Check if an element has a specific class.

if (hasClass(el, 'active')) {
  // do something
}

Attribute Operations

getAttr(element: Element, name: string): string | null

Get an attribute value from an element.

const id = getAttr(el, 'id')

setAttr(element: Element, name: string, value: string): void

Set an attribute value on an element.

setAttr(el, 'id', 'my-id')

removeAttr(element: Element, name: string): void

Remove an attribute from an element.

removeAttr(el, 'id')

Style Operations

getStyle(element: HTMLElement, property: string): string

Get the computed style value of an element.

const color = getStyle(el, 'color')

setStyle(element: HTMLElement, property: string, value: string): void

Set a style property on an element.

setStyle(el, 'color', 'red')

Element Operations

createElement<K>(tagName: K, options?): HTMLElementTagNameMap[K]

Create a new HTML element with optional configuration.

const div = createElement('div')
const link = createElement('a', {
  attributes: { href: '#', target: '_blank' },
  className: 'link'
})
const button = createElement('button', {
  textContent: 'Click me'
})

remove(element: Element): void

Remove an element from the DOM.

remove(el)

insertBefore(newNode: Node, referenceNode: Node): void

Insert a node before a reference node.

insertBefore(newEl, referenceEl)

insertAfter(newNode: Node, referenceNode: Node): void

Insert a node after a reference node.

insertAfter(newEl, referenceEl)

Event Operations

on(target, type, listener, options?): void

Add an event listener to a target.

on(window, 'resize', () => console.log('resized'))
on(el, 'click', (e) => console.log('clicked'))

off(target, type, listener, options?): void

Remove an event listener from a target.

off(window, 'resize', handler)

once(target, type, listener, options?): void

Add an event listener that will be called only once.

once(el, 'click', () => console.log('clicked once'))

Utility Functions

contains(parent: Node, child: Node): boolean

Check if a parent node contains a child node.

if (contains(parent, child)) {
  // child is inside parent
}

isElement(value: unknown): value is Element

Type guard to check if a value is an Element.

if (isElement(value)) {
  // value is Element
}

isVisible(element: HTMLElement): boolean

Check if an element is visible in the DOM.

if (isVisible(el)) {
  // element is visible
}

License

ISC