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-svelte

v2.0.0

Published

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

Readme

@js-template-engine/extension-svelte

The Svelte framework extension. Renders components defined as plain, typed data into Svelte components.

import { process } from '@js-template-engine/core';
import { svelte } from '@js-template-engine/extension-svelte';
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: [svelte()] });
// result.files → [{ path: 'Button.svelte', content: '...' }]

Generated components

A template renders as one <Name>.svelte component containing, in order:

  • a <script lang="ts"> block with the component imports, an export let declaration for each declared prop (typed, with its default when present), and the component script content where the markup's on:event handlers resolve
  • the markup, with the template's concepts translated to idiomatic Svelte (below)
  • a <style> block with the collected CSS

Components with no props, imports, or script omit the <script> block; components with no styles omit the <style> block.

Concept translation

| Concept | Svelte output | |---|---| | Text expression | {user.name} | | Attribute binding | src={props.avatarUrl} | | Conditional | {#if} / {:else if} / {:else} / {/if} | | Iteration | {#each items as item, i (item.id)} | | Conditional classes | class:btn--lg={size === 'large'} alongside static class | | Events | on:click={handleClick} | | Slots | <slot name="...">fallback</slot> | | Fragment | sibling nodes (no wrapper) | | Comment | <!-- ... --> |

Conditionals and iterations

Conditionals and iterations render as Svelte logic blocks wrapping their children: {#if condition} ... {/if} and {#each items as item, i (item.id)} ... {/each}. The iteration index is the second as binding and the key expression is the trailing (...); an iteration without a key renders without one and emits a warning.

Props

Each declared prop becomes a typed export let declaration:

export let label: string;
export let variant: 'primary' | 'secondary' = 'primary';

A required prop with no default is declared without one; an optional prop with no default defaults to undefined.

Event modifiers

Every modifier maps to a native Svelte modifier, appended to the event name in declared order: on:submit|preventDefault, on:click|stopPropagation|once.

Svelte's native modifier set has no key filters, so a key-guard modifier (enter, escape, arrow-down, ...) wraps the handler in a generated event.key guard; self, prevent, and stop move into the wrapper with it in declared order, while once, capture, and passive stay native pipe modifiers:

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

Output strategies

| Strategy | Styles | Scripts | |---|---|---| | inline | style="..." attributes | — | | in-file (default) | a <style> block in the component | <script> | | separate-file | <Name>.css + import from <script> | — |

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

The scss stylesheet language (styling.language) emits nested SCSS. The <style> block is tagged <style lang="scss"> under any strategy (your Svelte preprocessor compiles it), and separate-file writes <Name>.scss imported from <script>.

Node-level overrides

Element nodes may carry Svelte-specific overrides under extensions.svelte: attributes merges into the node's attributes per key, and events replaces the node's event list. Override attributes render verbatim, which is how framework-specific bindings without a generic concept — such as the bind: family — are authored:

{
  type: 'element',
  tag: 'input',
  extensions: {
    svelte: { attributes: { 'bind:value': { $expression: 'name' } } },
  },
}
// → <input bind:value={name} />

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

License

MIT