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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@js-template-engine/extension-react

v2.0.0

Published

React extension for the JS Template Engine: renders data-defined component templates as React function components

Readme

@js-template-engine/extension-react

The React framework extension. Renders components defined as plain, typed data into React function components in TypeScript.

import { process } from '@js-template-engine/core';
import { react } from '@js-template-engine/extension-react';
import { defineTemplate } from '@js-template-engine/types';

const template = defineTemplate({
  type: 'component',
  name: 'Button',
  props: {
    label: { type: 'string', required: true },
  },
  children: [
    {
      type: 'element',
      tag: 'button',
      attributes: { class: ['button'], type: 'button' },
      events: [{ name: 'click', handler: 'handleClick' }],
      children: [{ type: 'text', expression: 'label' }],
    },
  ],
});

const result = process(template, { extensions: [react()] });
// result.files → [{ path: 'Button.tsx', content: '...' }]

Generated components

A template renders as one <Name>.tsx file containing:

  • a <Name>Props interface generated from the declared props, with optional markers and destructured defaults (const { variant = 'primary' } = props;)
  • the component script content inside the function body, where handlers referenced from JSX are in scope
  • JSX with the template's concepts translated to idiomatic React (below)

Concept translation

| Concept | React output | |---|---| | Text expression | {user.name} | | Attribute binding | src={props.avatarUrl} | | Conditional | {condition && (...)} / ternary chains for else branches | | Iteration | {items.map((item) => ...)} | | Conditional classes | className={'btn' + (condition ? ' btn--lg' : '')} — no runtime dependency | | Events | onClick={handleClick} | | Fragment | <>...</> | | Comment | {/* ... */} |

Slots become props

React has no slot primitive, so slots render as component props: the default slot as children, named slots as props named after the slot. Slot names normalize to valid JavaScript identifiers (navigation-menunavigationMenu); two slots normalizing to the same identifier, or a slot colliding with a declared prop, are processing errors.

Each slot also adds an optional ReactNode entry to the generated props interface, and fallback content renders through ??:

{props.header ?? <h2>Default header</h2>}

Iteration keys

When an iteration body is a single element, its key lands directly on it (<li key={user.id}>); any other body shape is wrapped in <Fragment key={...}>. An iteration without a key renders without one and emits a warning.

Event modifiers

prevent, stop, and self are applied in a generated handler in declared order, as are the key-guard modifiers (enter, escape, arrow-down, ...), which become event.key guards:

onKeyUp={(event) => { if (event.key !== 'Enter') return; submitSearch(event); }}

capture maps to React's Capture-suffixed props (onClickCapture). once and passive cannot be expressed through React's declarative event props and emit a warning.

Output strategies

| Strategy | Styles | Scripts | |---|---|---| | inline | style={{ ... }} objects | — | | in-file (default) | a rendered <style> element | script in the component function | | separate-file | <Name>.css + import | — |

Styles with nested selectors (pseudo-classes, media queries) always require a stylesheet and stay in the <style> element under the inline strategy. Scripting supports only in-file: requesting inline or separate-file scripts with this extension is a processing error.

The scss stylesheet language (styling.language) emits nested SCSS. A React <style> element is injected at runtime and cannot parse SCSS, so scss is supported only with the separate-file strategy (<Name>.scss + an import); in-file and inline under scss are a processing error.

Node-level overrides

Element nodes may carry React-specific overrides under extensions.react: attributes merges into the node's attributes per key, and events replaces the node's event list.

{
  type: 'element',
  tag: 'button',
  events: [{ name: 'click', handler: 'handleClick' }],
  extensions: {
    react: { events: [{ name: 'click', handler: 'handleReactClick' }] },
  },
}

Component-level overrides under the root node's extensions.react merge extension-specific imports, script, style, and props into the component, each with a merge (default) or replace strategy.

License

MIT