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

@borf/elemental

v0.2.0

Published

> NOTE: This library is extremely early in development and is probably broken in a lot of ways. Use at your own risk.

Downloads

4

Readme

@borf/elemental

NOTE: This library is extremely early in development and is probably broken in a lot of ways. Use at your own risk.

A novel way to write web components (A.K.A. custom elements). Perfect for adding components to an existing website without rewriting it all in a full JavaScript framework.

In a JS file (elements.js):

import { element, html, css } from "https://unpkg.com/@borf/elemental";

// Define a new element with its HTML tag name,
// (optional) array of observed attributes which will cause a re-render when they are set,
// and a callback function that defines the element
element("elemental-example", ["title"], (c) => {
  // for debugging
  c.debug("printed when window.ELEMENTAL_LOG_LEVEL >= 'debug' or 0");
  c.info("fyi");
  c.log("message");
  c.warn("bad!");
  c.error("really bad!!");

  // access element's internal state
  c.get();
  c.get("value");
  c.set({ value: 5 });
  c.set("value", 5);

  // listen for events ('connect' and 'disconnect' are only emitted inside the element)
  c.on("connect", () => {
    c.log("view is now connected");
  });
  c.on("disconnect", () => {
    c.log("view is now disconnected");
  });

  // also standard DOM events
  c.on("click", () => {
    c.log("a click event bubbled up");
  });

  // emit custom events (listen to this one with 'onexplode')
  c.emit("explode", { message: "BOOM!" });

  // render with virtual DOM which doesn't eat your whole function scope
  c.render((state, attrs) => {
    return html`
      <div>
        <h1>${attrs.title}</h1>
        <slot />
      </div>
    `;
  });
});

In an HTML file (index.html):

<html>
  <body>
    <elemental-example title="This is a header!">
      <p>This is a child of the elemental view</p>
    </elemental-example>

    <script src="./elements.js" type="module"></script>
  </body>
</html>

Questions / Design

  • Should attributes be written in HTML in kebab-case but passed to the element in camelCase? HTML is not case sensitive but JS is, and JS doesn't deal well with dashes in property names.