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

dombr

v0.1.1

Published

Dombr, pronounced Dumber, is a Dom Builder which is dumber (read easier) to use! Inspired by the fluid pattern and the ease of jQuery, it allows to quickly create dom elements without all the boilerplate.

Downloads

1

Readme

Dombr

Dombr, pronounced Dumber, is a Dom Builder which is dumber (read easier) to use! Inspired by the fluid pattern and the ease of jQuery, it allows to quickly create dom elements without all the boilerplate.

Status

Currently in development, expect bugs or missing features.

Installation

Install dombr with your preferred node package manager:

npm i dombr;
yarn add dombr;
pnpm i dombr;

Usage

import D from 'dombr';

const nav = D.nav()
  .ul()
  .li({ repeat: 3 })
  .a({ href: '/cat-$', text: 'Category $' })
  .build();

The above will produce the following html:

<nav>
  <ul>
    <li><a href="/cat-1">Category 1</a></li>
    <li><a href="/cat-2">Category 2</a></li>
    <li><a href="/cat-3">Category 3</a></li>
  </ul>
</nav>

How it works

Dombr is a factory to easily create any valid HTML elements. It allows you to create any element available to HTML5 by calling a method with its corresponding tag name, for example Dombr.div().

The returned value of that call is Dombr itself. The method updates some internal state. In order to build the actual dom elements, you need to call .build().

Features

Creating an element

You can call a method with the same name as the html5 element you want to create, for ex: img, svg, div, article, etc...

That method optionally takes an object with some options as described below:

| Option | Default | Description | | :------ | :------ | :--------------------------------------------------------- | | repeat | 1 | How many times to repeat creating this element | | text | null | Sets the innerText of the element. Supports $ | | data | {} | Assign key-values to data-* attributes on the element | | classes | null | String, array or object of classes to apply to the element | | events | null | Object of events to listen for and their callbacks |

In addition to these options, any other property found inside the options will be assumed to be an attribute to assign to the element, for example href or disabled.

Here is an example of creating an anchor link with the above options:

const isSelected = true;
const a = D.a({
  href: 'https://google.com',
  classes: { active: isSelected },
  text: 'Visit Google',
}).build();

The above would produce the following html:

<a href="https://google.com" class="active">Visit Google</a>

Traversing the builder

Everytime you call a tag method, it will insert that element as a child of the previously created element. ex: D.div().p() would add p inside the div.

In order to add as a sibling, simply call .sibling() before calling your element. ex: D.div().p().sibling().span() would add span in the same div where p was added.

You can also call .parent() to achieve a similar result, but to add in the parent rather than a sibling.

Here is an example:

const article = D.article()
  .header()
  .h1({ text: 'My title' })
  .parent()
  .p({ text: 'My content' })
  .sibling()
  .footer()
  .p({ text: 'My footer' })
  .build();

The above would generate the following html:

<article>
  <header>
    <h1>My title</h1>
  </header>
  <p>My content</p>
  <footer>
    <p>My footer</p>
  </footer>
</article>

What about custom elements

The different methods available on the builder are only for tags which are present in the typescript definition of HTMLElementTagNameMap. Any custom elements will not be included in the builder.

On the other hand, those methods are all helpers which call Dombr.el(), which expects the tag name of the element to create. If you have an element called <my-counter /> you can instantiate it with Dombr.el('my-counter'). It accepts a second parameter which is the same object option as the other methods.

Here is an example of using the above counter elements:

import D from 'dombr';

const counter = D.el('my-counter', {
  count: '3',
  events: {
    updateCount: ev => console.log(ev.details.count),
  },
}).build();

document.body.appendChild(counter);

The above example would not only add the custom element to the dom, but also assign an attribute count and listen for the event updateCount.