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

domik

v1.0.4

Published

A powerful yet tiny set of dom manipulation helpers

Downloads

5

Readme

Description

DOM-manipulating API in pure Javascriptn is verbose and pain to write in. JQuery partially solves this problem, but who wants to have another bulky dependency? domik is a tiny toolbox of DOM-manipulating helpers written in pure javacript, that allows creating complex DOM element structures in declarative fashion with significantly less code. It uses concise clear API inspired by JQuery, but manipulates native DOM elements without any extra wrappers.

Basic usage

Import the entire module:

import * as util from "domik";

API

bake(name, recipe)

Bakes DOM element according to recipe in a declarative fashion.

  • name (string) Required. Type of the created element.
  • recipe (object) Optional JSON object that describes created element. can have following properties:
    • id - string id to be set
    • classes - string or array. Single class or array of classes to be set
    • attributes - object of attributes key vaule pairs. Any valid html attributes can be passed
    • html - inner html
    • text - inner text
    • val - value
    • style - css string inline style for the element
    • children - single DOM element or array of DOM elements that will be appended as children
    • listeners - JSON object with keys - events types, vaules - event handlers

Code example:

    import * as util from "domik";
    
    //baking simple span
    let mySpan = util.bake("span", {
        text: "I am simple span",
    });
    
    //baking complex DOM structure
    let wrapper = util.bake("div", {
        classes: "wrapper",
        style: "width: 100px; display: flex;",
        listeners: {
            "click": ()=>{ alert("Hello world") }
        },
        children: [
            mySpan,
            util.bake("div", {
                style: "border: 1px solid grey; border-radius: 5px",
                children: util.bake("h1", {
                    html: "Hello World",
                    style: "color: green",
                    listeners: {
                        "click": ()=>{ alert("Hello hello!") }
                    }
                })
            })
        ]
    })

$(selector)

  • selector (string) Query selector

This is an alias for native document.querySelector method

util.$("#selector")

$$(selector)

  • selector (string) Query selector

This is an alias for native document.querySelectorAll method

util.$$(".another-selector")

appendChildren(parent, children)

  • parent (DOM element)
  • children (DOM element or array of DOM elements)

Appends child or array of children to a parent

show(element)

  • element (string or DOM element)

Alias in jquery style for display: block

hide(element)

  • element (string or DOM element)

Alias in jquery style for display: none

flex(element)

  • element (string or DOM element)

Alias in jquery style for display: flex

val(element, value)

  • element (string or DOM element)
  • value (string)

Sets value for given element

html(element, html)

  • element (string or DOM element)
  • html (string)

Sets innerHTML for given element

text(element, text)

  • element (string or DOM element)
  • text (string)

Sets innerText for given element

addClass(element, class)

  • element (string or DOM element)
  • class (string) css class

Adds class to element’s classlist

removeClass(element, class)

  • element (string or DOM element)
  • class (string) css class

Removes class from element’s classlist

generateRandomId(length, prefix, postfix)

  • length (number) Length of generated id not including prefix and postfix
  • prefix (string) Optional prefix string
  • postfix (string) Optional postfix string

Generates and returns random id of a given length in form of: “prefix-random-id-postfix”