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

js-create-html-elements

v1.0.0

Published

An easier way to dinamically create html elements.

Downloads

1

Readme

create-element

This simple js file helps you create html elements, and makes that process less cumbersome and a bit easier to read.

Index

Why create-element?

This is an opinionated piece of javascript, but it lets you create and stack html elements in an easier way - compared to vanilla at least. Take a look at some comparisons below:

Without create-element

let p = document.createElement('p');
p.classList.add('class1', 'class2');
p.setAttribute('attr1', 'value1');
p.setAttribute('attr2', 'value2');
p.textContent = 'some text';

document.body.appendChild(p);
  • The appending is at the end, which breaks the logic train of thought (hierarchy-wise)
  • The way to assign information changes depending on the information itself - you don't change the classes the same way you change the content, etc
  • Not particularly hard to read, but not that easy.

Using create-element

document.body.appendChild(create({
    type: 'p',
    class: ['class1', 'class2'],
    attr: [
        ['attr1', 'value1'],
        ['attr2', 'value2']
    ],
    text: 'some text'
}))
  • The appending is at the beggining
  • the info is indented, helps with visualizing hierachy
  • every thing is the same - type, class, attributes, etc follow the same logic

Using create-element more

Here's an example of a hierachy tree in HTML

<div class="container">
    <div class="row">
        <div class="col-4">Book A</div>
        <div class="col-4">Book B</div>
        <div class="col-4">Book C</div>
    </div>
</div>

And here's how to build it with create-element

let arrayOfBooks = ['Book A', 'Book B', 'Book C']

parent.appendChild(create({
    class: ['container'],
    child: create({
        class: ['row'],
        child: Array.from(arrayOfBooks, book => {
            return create({
                class: ['col-4'],
                text: book
            })
        })
    })
}))

Notice how easy it is to build nested structures like this! All while being easy to understand the logic and hierarchy.

Documentation

There's nothing here...

How to use

Via CDN

Paste this at the bottom of the body tag of your document.

<script src="https://cdn.jsdelivr.net/gh/alexandre97costa/create-element/utilities.min.js"></script>

npm when?

I might be a bit too dumb to understand how to upload a package to npm.