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

whitecube-dom

v1.0.7

Published

A super lightweight JavaScript Dom manipulator

Downloads

6

Readme

Dom

A super lightweight JavaScript Dom manipulator

Installation

NPM

npm i whitecube-dom

Yarn

yarn add whitecube-dom

and then in your code simply import the classes you need:

import { Dom, DomCollection, DomElement } from 'whitecube-dom';

Dom

The Dom class aims to give you shortcuts to make your life easier when working with dom elements.

Dom.element(tag, classes = [], attributes = {})

→ returns a DomElement instance.

let x = Dom.element('div');
let y = Dom.element('div', ['class-one']);
let z = Dom.element('div', ['class-one', 'class-two'], { 
  'data-test': 'Hello there'
});

DomCollection

The DomCollection class wraps multiple DomElements.

Constructor

new DomCollection(elements = [])

Properties

DomCollection.els → An array/nodelist containing the DomElements

Methods

DomCollection.add(el)

param {DomElement|HTMLElement} el The element to add
→ returns this
Add an element to the collection.


DomCollection.each(callback, reverse = false)

param {callback} callback The code to execute
@param {boolean} reverse Should we loop in reverse
→ returns this
Iterate over each of the DomElements and run code.


DomCollection.on(event, callback)

param {string} event The event to listen for
param {callback} callback The code to execute
→ returns this
Add event listeners to all elements of the collection.


DomCollection.off(event, callback)

param {string} event The event to stop listening for
param {callback} callback → returns this
Remove event listeners from all elements of the collection.


DomCollection.insertInto(parent)

param {DomElement|HTMLElement} parent The element to insert into
→ returns this
Insert this collection into an element.


DomCollection.count()

→ returns int
Returns the amount of items in the collection.


DomElement

The DomElement class is a container for a single dom element.
Most of the following methods return this to allow method chaining.

Constructor

new DomElement(element = null)

Properties

DomElement.tag → the tag name of this element
DomElement.classes → an array containing the classes
DomElement.attributes → an object containing the available attributes
DomElement.el → the underlying HTMLElement

Methods

DomElement.create(tag, classes = [], content = null, attributes = {})

→ returns this
Creates a node


DomElement.addClass(className)

→ returns this
Adds a class to the element.


DomElement.removeClass(className)

→ returns this
Removes a class from the element.


DomElement.hasClass(className)

→ returns boolean
Checks if the element has the specified class.


DomElement.setAttribute(attribute, value)

param {string} attribute The attribute name
param {mixed} value The value to set the attribute to
→ returns this
Sets an attribute on the element.


DomElement.removeAttribute(attribute)

param {string} attribute The attribute name to remove
→ returns this
Removes an attribute from the element.


DomElement.hasAttribure(attribute)

param {string} attribute The attribute name to check for
→ returns boolean
Checks if the element has the specified attribute.


DomElement.remove(duration = 0, className = '')

param {int} duration The duration after which to remove the element
param {string} className An optional class name to add to the element before removing it
→ returns this
Removes an element from the DOM.


DomElement.insertInto(element)

param {HTMLElement|DomElement} element The parent element
→ returns this
Inserts the element into the specified element.


DomElement.appendChild(childNode)

param {HTMLElement|DomElement} childNode The child element
→ returns this
Appends a child element to the element.


DomElement.on(event, callback)

param {string} event The event to listen for
param {callback} callback The actions to perform
Adds an event listener to this element.


DomElement.off(event, callback)

param {string} event The event to stop listening for
param {callback} callback
Removes an event listener.


DomElement.clone(deep = true)

param {boolean} deep Should we copy the child nodes as well
→ returns DomElement
Create a copy of this element.


DomElement.qs(selector)

param {string} selector Query selector
→ returns DomElement
Finds an child element.


DomElement.qsa(selector)

param {string} selector Query selector
→ returns DomCollection
Finds child elements.


DomElement.height()

→ returns int
Get the height of the element.


DomElement.width()

→ returns int
Get the width of the element.