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

domper

v0.0.7

Published

Effortless and efficient DOM manipulation

Readme

Domper

Introducing Domper, your new companion for effortless and efficient DOM manipulation and Web Components creation.

Features

  • Effortless DOM Manipulation: Create, select, and modify DOM elements with a simple API.
  • Web Components: Quickly define and manage custom elements with defineElement.

Installation

npm install domper

or

yarn add domper

Basic Usage

Import the Library

// Import the entire library
import * as Domper from 'domper';

// Or import individual functions
import { defineElement, create } from 'domper';

Define a Custom Element with defineElement

Easily create Web Components using the defineElement function.

Example

import { defineElement } from 'domper';

defineElement('my-element', ({ props }) => {
  return `<div>${props.text}</div>`;
}, {
  style: '.my-element { color: red; }',
  afterRender: () => { console.log('Component has been rendered'); }
});

Parameters

  • tagName (String): The name of the custom element.
  • componentFn (Function): A function that returns the HTML template.

Options

  • style (String): CSS styles.
  • afterRender (Function): A function called after the component is rendered.

Usage

<my-element data-props='{"text": "Hello, world!"}'></my-element>

Accessing and Modifying props and state

Get and Set props

// Get current props
const myElement = document.querySelector('my-element');
const currentProps = JSON.parse(myElement.getAttribute('data-props'));

// Set new props
const newProps = { text: 'New text!' };
myElement.setAttribute('data-props', JSON.stringify(newProps));

Get and Set state

State is managed internally and can be set using setState within the componentFn.

defineElement('my-element', ({ state, setState }) => {
  // Set new state
  setState({ count: state.count + 1 });

  // Your render logic
  return `<div>${state.count}</div>`;
});

Create an Element (create)

Create new DOM elements with optional configurations.

Example

import { create } from 'domper';

const newDiv = create('div', {
  classes: ['myClass1', 'myClass2'],
  attributes: { id: 'myId', 'data-test': 'testValue' },
  text: 'Hello, world!'
});

// This creates a new <div> element with:
//  - Classes 'myClass1' and 'myClass2'
//  - An ID of 'myId'
//  - A 'data-test' attribute with value 'testValue'
//  - Text content 'Hello, world!'

Parameters

  • tag (String): The tag name of the element.
  • options (Object): Optional configurations like classes, attributes, text, shadow root, and more.

Select Element (select and selectAll)

Select single or multiple elements based on your selector queries.

Example

import { select, selectAll } from 'domper';

const myElement = select(document.body, ['#myElement']);
const allElements = selectAll(document.body, ['.myClass']);

Parameters

  • parent (HTMLElement | ShadowRoot): The parent element or shadow root to search within.
  • selector (Array): An array of selectors to be used for searching.

Get and Set Property (getProperty and setProperty)

Retrieve and set properties of DOM elements, supporting different data types.

Example

import { getProperty, setProperty } from 'domper';

// Get a property
const id = getProperty(element, 'id');

// Set a property
setProperty(element, { id: 'newId' });

Parameters

  • target (HTMLElement | ShadowRoot): Target element or shadow root.
  • properties (Object): An object containing key-value pairs for setting properties.
  • type (String): Optional type for value conversion (e.g., 'object', 'number').

Insert Template (insertTemplate)

Insert an HTML template into a target element.

Example

import { insertTemplate } from 'domper';

insertTemplate('<p>Hello, world!</p>', element);

Add Style (addStyle)

Add a style element to a target element.

Example

import { addStyle } from 'domper';

addStyle('.myClass { color: red; }', element);

Toggle, Add, and Remove Classes (toggleClass, addClass, removeClass)

Toggle, add, or remove a class from an element.

Example

import { toggleClass, addClass, removeClass } from 'domper';

toggleClass(element, 'myClass');
addClass(element, 'anotherClass');
removeClass(element, 'myClass');

License

This project is licensed under the MIT License.