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

@t09tanaka/typed-hbs

v0.1.1

Published

Minimal typed Handlebars-style template engine for TypeScript

Readme

typed-hbs

Minimal typed Handlebars-style template engine for TypeScript.

{{key}} placeholders are replaced with values from a typed context object. Zero dependencies.

Install

npm install @t09tanaka/typed-hbs

Usage

import { render } from "@t09tanaka/typed-hbs";

type ContactMailProps = {
  name: string;
  email: string;
  meta: { ip: string };
};

const props: ContactMailProps = {
  name: "Alice",
  email: "[email protected]",
  meta: { ip: "127.0.0.1" },
};

render<ContactMailProps>("Hello {{name}}", props);
// => "Hello Alice"

render<ContactMailProps>("ip={{ meta.ip }}", props);
// => "ip=127.0.0.1"

Dot paths

Nested objects are accessed with . separated paths.

render("{{a.b.c}}", { a: { b: { c: "deep" } } });
// => "deep"

Array indices

Array elements are accessed by numeric index.

render("{{items.0.title}}", { items: [{ title: "First" }] });
// => "First"

Loops

Iterate over arrays with {{#each}}. Parent props are accessible inside the loop, and item properties take precedence.

const template = "{{#each items}}- {{title}} by {{author}}\n{{/each}}";

const props = {
  author: "Alice",
  items: [{ title: "Post 1" }, { title: "Post 2" }],
};

render(template, props);
// => "- Post 1 by Alice\n- Post 2 by Alice\n"
//
// - Post 1 by Alice
// - Post 2 by Alice

For primitive arrays, use {{.}} to reference the current value:

const tagList = "{{#each tags}}#{{.}} {{/each}}";

render(tagList, { tags: ["ts", "js", "node"] });
// => "#ts #js #node "

Conditionals

Show or hide content based on truthy/falsy values:

const tpl = `{{#if premium}}
  Premium member
{{else}}
  Free member
{{/if}}`;

render(tpl, { premium: true });
// =>
//   Premium member
//

render(tpl, { premium: false });
// =>
//   Free member
//

Chained conditions with {{else if}}:

const tpl = `{{#if role}}Admin{{else if guest}}Guest{{else}}User{{/if}}`;

render(tpl, { role: false, guest: true });
// => "Guest"

Use {{#unless}} for negated conditions:

const tpl = "{{#unless paid}}Please pay{{/unless}}";

render(tpl, { paid: false });
// => "Please pay"

Behavior

| Value | Result | | ------------- | ------------------------------------------- | | string, etc | String(value) | | null | "" (empty string) | | undefined | Throws Error | | Missing key | Throws Error |

  • Prototype chain values are not resolved (hasOwnProperty check).
  • HTML escaping is not performed. Escape on the caller side if needed.
  • Empty arrays produce an empty string (the {{#each}} block is removed).
  • Non-array values in {{#each}} throw an Error.
  • {{#if}} uses JavaScript truthy/falsy rules (false, 0, "", null, undefined are falsy).
  • Blocks can be nested ({{#if}} inside {{#each}}, etc.).

API

render<T>(template: string, props: T): string

Replaces all {{key}} placeholders in template with values from props.

Throws an Error if any key is missing or resolves to undefined.

Scripts

npm test          # Run tests
npm run build     # Build ESM + CJS
npm run typecheck # Type check

License

MIT