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

@degjs/dom-utils

v3.0.0

Published

A utility library for working with the DOM.

Downloads

5

Readme

domUtils

Build Status

Working with the browser's Document Object Model (DOM) via JavaScript has historically been harder than it should be, filled with enough inconsistencies and browser bugs to drive even the best developer crazy. These challenges were a huge factor in the ubiquity of JavaScript helper libraries such as jQuery across the web.

Fortunately, those days are largely behind us. Modern-day DOM interaction is simpler and more consistent, to the point where jQuery shouldn't be an assumed dependency anymore (no, really).

domUtils bridges the gap between vanilla JS and a full-fledged library. It's a collection of helper methods that can be imported individually to keep your codebase lean, or together when more are needed.

Install

domUtils is an ES6 module. Consequently, you'll need an ES6 transpiler (Babel is a nice one) as part of your Javascript workflow.

If you're already using NPM for your project, you can install domUtils with the following command:

$ npm install @degjs/dom-utils

Usage

Importing individual domUtils methods:

import { createElement } from "@degjs/dom-utils";

let newEl = createElement('div', ['classNameA', 'classNameB']); // Create a new element
document.body.appendChild(newEl); // Add the new element to the DOM

Importing all domUtils methods:

import * as domUtils from "@degjs/dom-utils";

let newEl = domUtils.createElement('div', ['classNameA', 'classNameB']); // Create a new element
document.body.appendChild(newEl); // Add the new element to the DOM
domUtils.removeElements(newEl); // Remove the new element from the DOM

Methods

isElement(el)

The isElement method tests a supplied value to see if it's a valid HTML element, and returns true or false.

el

Type: Element
The potential element to test.

createElement(nodeName, classNames)

nodeName

Type: String
The name of the new HTML element you want to create (i.e., 'div', 'li', etc.).

classNames

Type: String or Array
An indivudal class name, or array of class names, that will be added to the returned element.

emptyElements(els)

The emptyElements method removes all child elements from the supplied list of HTML elements.

els

Type: Element or Array
A single HTML element or an array of HTML elements that will be emptied.

replaceContent(el, newContent)

The replaceContent method replaces an element's content with the supplied new content.

el

Type: Element
A single HTML element that will have its content replaced.

newContent

Type: String
The content that will replace the element's old content.

removeElements(els)

The removeElements method removes all supplied HTML elements from the DOM.

els

Type: Element or Array
A single HTML element or an array of HTML elements that will be removed.

wrapElements(elsToWrap, wrapperEl)

The wrapElements method wraps all supplied HTML elements within another supplied element.

elsToWrap

Type: Element or Array
A single HTML element or an array of HTML elements that will be wrapped by the wrapperEl element.

wrapperEl

Type: Element
A single HTML element that will be wrapped around the supplied elsToWrap elements.

unwrapElements(wrapperEls)

The unwrapElements method removes a wrapping parent HTML element, leaving all of its child elements in place.

wrapperEls

Type: Element or Array
A single HTML element or an array of HTML elements that will be removed, without removing child elements.

Browser Support

domUtils depends on the following browser APIs:

To support legacy browsers, you'll need to include polyfills for the above APIs.