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

render-tmpl

v0.0.1

Published

Use `<template>` as a rendering engine, < 100 lines of code.

Downloads

17

Readme

render-tmpl

Use <template> as a rendering engine, < 100 lines of code.

  • Alpine/Vue-like directive notation data-s-{text,attr,show} for use with <template> elements.
  • No reactivity, pairs well with web components/custom elements.
  • copy-paste onto your page (< 100 lines of code or ESM import).

Quickstart

<template data-s-tmpl="tmpl">
  <div data-s-text="greeting"></div>
  <img data-s-attr="src=url,alt=greeting" />
</template>
<script type="importmap">
  { "imports": { "render-tmpl": "https://esm.sh/render-tmpl" } }
</script>
<script type="module">
  import { renderTmpl } from "render-tmpl";
  document.appendChild(
    renderTmpl(document.querySelector("[data-s-tmpl=tmpl]"), {
      greeting: "hello",
      url: "my-url",
    }),
  );
</script>

Directives

data-s-tmpl

data-s-tmpl is a convention to denote templates that will be used with render-tmpl.

Usage: <template data-s-tmpl="loading"></template>.

data-s-show

data-s-show will set display: none; if the expression is false and will unset display if it's true.

Usage: <div data-s-show="isShown"></div>

Use of negation is allowed with !, eg. <div data-s-show="!isLoading"></div>, note: any arbitrary number of ! works, but other boolean logic (&&, ||, ()) will not work, this is because the value is not eval-ed as JavaScript.

data-s-text

Set the textContent of the node to the value of the referenced variable.

Usage: <p data-s-text="message"></p>

data-s-attr

Set attributes on the element based on provided key-value attr1=value1,attr2=value2 pairs.

Aliases: data-s-attrs

Usage: <img data-s-attr="src=url,alt=greeting" /> sets src and alt attributes to the values contained in url and greeting variables.

data-s-slot

Used as the element into which sub-templates are injected.

Usage:

<template data-s-tmpl="tmpl">
  <div data-s-slot></div>
  <template data-s-tmpl="no-results">
    No Results <span data-s-text="requestId"></span>
  </template>
</template>
<script type="module">
  import { renderTmpl } from "render-tmpl";
  document.appendChild(
    renderTmpl(document.querySelector("[data-s-tmpl=tmpl]"), {}, (tmpl) =>
      renderTmpl(tmpl.querySelector("[data-s-tmpl=no-results]"), {
        requestId: "1234",
      }),
    ),
  );
</script>

Requirements

  • Node 20
  • npm v8+

Setup

  1. Clone the repository
  2. Run npm install installs all required dependencies.

npm scripts

  • npm test will run tests using the Node.js test runner and the node:test module.
  • npm run format will run prettier on all the examples files (and tests).

LICENSE

Code is licensed under the MIT License.