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

engraft

v0.0.33

Published

๐ŸŽ‹ A simple and tiny utility library for building fast web interfaces using regular JavaScript

Downloads

3

Readme

engraft.js ๐ŸŽ‹

๐Ÿšง Status: In Development ๐Ÿ› ๏ธ

EngraftJS is a JavaScript micro-library aimed at help building web user interfaces. A simple and tiny utility library for creating UIs using regular JavaScript, as an extra part of the toolkit for everyday web development using the Web Platform. The power of this lone star at the client-side scripting, is similar to writing bits of HTML, but inside of a JavaScript file. Build components with a light abstraction for some DOM manipulations like events binding at the own template element, avoiding document.createElement("tag") and element.addEventListener('event', callback) for example.

Install via npm

$ npm install --save engraft

Features

๐Ÿ”ง This micro-library was meant to be a JSX-like but as a tool for UI prototyping with ordinary JS, and plays very well with the Web Components v1, which one of the major benefit - its component pattern, therefore, the UIs are split into distinct pieces in the application. Breaking the interface into small chunks of code through Web Components bring all the benefits of then. Just use what is familiar, the loyal, trusted and eternal Web Standards: Web APIs, HTML5, CSS3, standard JavaScript (aka vanilla JS) and the awesome Web Components all together. #usetheplatform

The HTML templating implementation provided by Dr. Axel Rauschmayer at his book was used as starting point.

Nothing new or needed to learned

The motivation for EngraftJS was to provide a light way to use HTML elements inside JavaScript, together with Web Components, allow the componentization of user interfaces--splitting them up into small chunks of related HTML and JavaScript. Grammar in EngraftJS is mostly the same as in HTML, but there are subtle differences to watch out for. The differences from traditional HTML are listed below:

  1. Adding Event Listeners smoothly: use function reference onevent="myFunction", not function invocation onevent="myFunction()". Note that in HTML, event listener names are written in all lowercase, such as onclick or onmouseover. In some libraries, however, like JSX or lit-html, event listener names are written in camelCase or with the prefix @, such as onClick or @click, respectively. The philosophy behind EngraftJS is to avoid at the most any divergence from common HTML syntax.
  2. Passing inline CSS properties not only through strings, but by literal objects too: when using styling objects the JSON-based format is mandatory, example: style='{"border-radius": "7px", "color": "green"}'. OBS: single properties names will work {color: "blue"} but are better to follow the standard rules.
  3. Avoid use the innerHTML property directly (like document.body.innerHTML or document.body["innerHTML"]), instead, use the innerHTML Symbol reference (document.body[innerHTML]) and the html tagged template function provided by the EngraftJS library.

html method is primarily a convenience function, and it can be especially useful when manipulating callback events.

Code Example

Uses Serve as recommended Web Server, run:

$ npm i serve

For Web Components


import { innerHTML, html } from './index.mjs';

class MyComponent extends HTMLElement {
  static get observedAttributes() { return ['name']; }
  constructor(...args) {
    super(...args);
  }
  attributeChangedCallback() { this.render(); }
  connectedCallback() { this.render(); }
  showNodeName() {
    alert(this.nodeName);
  }
  render() {
    this[innerHTML] = html`
      <p id="shaula" onblur='${(e)=>console.log(e.target.textContent)}' class='par' name="ฮป" contenteditable>
        <slot name="user-text">&#x3bb; Sco</slot>
      </p>
      <h1 onclick='${this.showNodeName}' style="${{"color": "red", "font-size": "5em"}}">
        Hello, &lambda; ${this.getAttribute('name')}
      </h1>
    `;
  }
}

customElements.define('my-component', MyComponent);

And plain JavaScript DOM app

const mc = new MyComponent;
mc.setAttribute('name', 'Scorpii');
document.body.appendChild(mc);

var p = document.createElement('p');
p[innerHTML] = html`
  Lorem, ipsum dolor sit amet consectetur adipisicing elit. <span style="${{"color": "green"}}">
  Tincidunt</span> ornare massa eget egestas purus. Bibendum enim facilisis gravida neque convallis a. Vitae suscipit tellus mauris a diam maecenas. Ultricies leo integer malesuada nunc vel risus commodo viverra maecenas.
`;
document.body.appendChild(p);

โš ๏ธ Warning: โ˜ข๏ธ not optimized for production โ˜ฃ๏ธ

https://www.w3.org/TR/custom-elements/

https://www.w3.org/wiki/WebComponents/

https://github.com/w3c/webcomponents/