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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@trunkjs/html-scope

v1.0.5

Published

Add a lightweight reactive "scope" to plain HTML using <tj-html-scope> and @trunkjs/template.

Readme

html-scope

Add a lightweight reactive "scope" to plain HTML using and @trunkjs/template.

Quick start

<tj-html-scope update-on="change keyup" scope-init='{ "name": "World", "repeatCount": 3 }'>
  <template>
    <div *for="i of Array.from({ length: repeatCount })">Hello {{name}}</div>
  </template>

  <input type="text" name="name" value="World" />
  <input type="number" name="repeatCount" value="3" />
</tj-html-scope>
  • update-on: space/comma separated events that trigger scope updates from inputs inside the element.
  • Inputs with a name attribute are synced into the scope as scope[name] = value.

scope-init

Initialize or extend the component scope from an evaluated expression. The expression runs in an async context with access to:

  • host element (as host), current scope (as scope)
  • window, document, console, fetch

Rules:

  • The expression must evaluate to an object. That object is shallow-merged into the current scope.
  • It is evaluated on connect and whenever the scope-init attribute changes.
  • A scope-update event is dispatched after merging.

Examples

  • Inline object

    <tj-html-scope scope-init='{ "name": "Jane", "repeatCount": 2 }'></tj-html-scope>
  • From the DOM

    <script id="seed" type="application/json">{"name":"Dom","repeatCount":4}</script>
    <tj-html-scope
      scope-init='JSON.parse(document.querySelector("#seed")?.textContent ?? "{}")'
    ></tj-html-scope>
  • Remote (async)

    <tj-html-scope
      scope-init='await fetch("/api/scope").then(r => r.json())'
    ></tj-html-scope>

Notes

  • The expression is executed as code. Do not inject untrusted strings.
  • If the expression does not return an object, the evaluation will fail and be ignored by the component.

Events

  • scope-update: fired after the scope is extended via scope-init.

Building

Run nx build html-scope to build the library.

Running unit tests

Run nx test html-scope to execute the unit tests via Vitest (jsdom environment).

Template rendering demo

Three ways to initialize scope using scope-init:

  • Inline object

    <tj-html-scope scope-init='{ "name": "World", "repeatCount": 3 }'>
      <template>
        <div *for="i of Array.from({ length: repeatCount })">Hello {{name}}</div>
      </template>
    </tj-html-scope>
  • From a script element (application/json)

    <script id="seed-user" type="application/json">{"name":"Dom","repeatCount":4}</script>
    <tj-html-scope
      scope-init='JSON.parse(document.querySelector("#seed-user")?.textContent ?? "{}")'>
      <template>
        <div *for="i of Array.from({ length: repeatCount })">Hi {{name}}</div>
      </template>
    </tj-html-scope>
  • External JSON via fetch (async)

    <tj-html-scope
      scope-init='await fetch("/demo/data/user.json").then(r => r.json())'>
      <template>
        <div *for="i of Array.from({ length: repeatCount })">Welcome {{name}}</div>
      </template>
    </tj-html-scope>

See a full showcase at /demo/template-rendering.html when running the dev server.