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

@octorchard/crown

v1.1.0

Published

👑 A tiny JS function to easily create elements

Downloads

4

Readme

crown

An easier way to make new elements

let el = crowm(
  "div#header.fade-in",
  { title: "This is a div!" },
  { backgroundColor: "#11191f", color: "white" }
);

document.body.appendChild(el);

Let's face it - creating vanilla elements is tedious, especially if you want to assign multiple classes, IDs, styles and attributes. Sounds like a lot of code! But that's where crown comes into the picture.

Crown is a tiny (~1kb) JavaScript function that can help you make elements and assign them classes and IDs using CSS selector syntax. It also lets you set the innerHTML of the element, and add attributes and inline styles to the element.

It uses the good 'ol document.createElement function, and adds attributes as required. Crown also returns the HTML element, so you can append it to the DOM.

Usage

Importing

Using npm

npm i @octorchard/crown
import crown from "@octorchard/crown";

crown(<args>)

Note: this package is ESM-only.

Get it from the releases

Head over to the releases and grab the latest crown.js and the sourcemap, if you want it.

Transpile it yourself

git clone https://github.com/octorchard/crown
cd crown
esbuild --bundle index.js --minify --sourcemap --target=chrome58,firefox57,safari11,edge16 --outfile=build/crown.js

build/crown.js is the output. Feel free to tweak the --target.

New elements

let el = crown(<selector>, <innerHTML>, <attributes>, <styles>)

where

  • selector is a CSS selector string (containing only a base element, .classes and #ids),

  • innerHTML is a string containing the text content of the element

  • attributes is an Object of { attr1: "value", attr2: "value", ... } attributes which are to be added to the element

  • styles is an object of CSS styles ({ property: "value", ... }). The properties must me in camelCase, just like in React.

The returned value is a HTML element.

Commands

Build:

esbuild --bundle index.js --minify --sourcemap --target=chrome58,firefox57,safari11,edge16 --outfile=build/crown.js

Thanks!