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

@joshuapassos/prompt-ts

v1.2.0

Published

Type-safe prompt templating engine with Zod schema support

Downloads

37

Readme

@joshuapassos/prompt-ts

Type-safe prompt templating engine for TypeScript. Build structured LLM prompts with compile-time placeholder validation, multi-language support, and optional Zod schema integration.

Install

pnpm add @joshuapassos/prompt-ts

Features

  • Type-safe placeholders{{key}} syntax validated at compile time
  • System/User message pairs — structured prompt rendering for chat-based LLMs
  • Multi-language support — define templates per language, select at render time
  • Composable sections — reusable prompt fragments via promptSection()
  • Zod schema — optional structured output validation
  • Conditional options — only requires systemOptions/userOptions when the corresponding template has placeholders

Usage

Basic (string mode)

import { prompt } from "@joshuapassos/prompt-ts";

const p = prompt(
  "greet",
  "You are a {{role}}.",
  "Say hello to {{name}}."
);

const result = p.render({
  systemOptions: { role: "assistant" },
  userOptions: { name: "Alice" },
});
// => { systemPrompt: "You are a assistant.", userPrompt: "Say hello to Alice." }

Multi-language mode

const p = prompt(
  "classify",
  {
    en: "You are a {{category}} classifier",
    pt: "Você é um classificador de {{categoria}}",
  },
  {
    en: "Classify: {{text}}",
    pt: "Classifique: {{texto}}",
  }
);

p.render("en", {
  systemOptions: { category: "sentiment" },
  userOptions: { text: "I'm happy" },
});

p.render("pt", {
  systemOptions: { categoria: "sentimentos" },
  userOptions: { texto: "Estou feliz" },
});

Composable sections

import { promptSection } from "@joshuapassos/prompt-ts";

const persona = promptSection("You are a {{role}}.");
const tone = promptSection("Be professional and concise.");

const systemPrompt = [
  persona.render({ role: "translator" }),
  tone.render(),
].join("\n\n");
// => "You are a translator.\n\nBe professional and concise."

Sections can be composed into a prompt:

const p = prompt(
  "translate",
  systemPrompt,
  "Translate: {{text}}"
);

p.render({ userOptions: { text: "Hello world" } });

With Zod schema

import { z } from "zod";

const schema = z.object({
  sentiment: z.enum(["positive", "negative", "neutral"]),
  confidence: z.number(),
});

const p = prompt(
  "sentiment",
  "You are a sentiment classifier.",
  "Classify: {{text}}",
  schema
);

// Access the schema for structured output parsing
p.zodSchema; // z.ZodObject<...>

API

prompt(name, systemTemplate, userTemplate, zodSchema?)

| Param | Type | Description | |---|---|---| | name | string | Unique identifier for logging/tracing | | systemTemplate | string \| Record<string, string> | System message template(s) | | userTemplate | string \| Record<string, string> | User message template(s) | | zodSchema | z.ZodType<T> | Optional Zod schema for output validation |

.render(options) (string mode)

.render(lang, options) (multi-language mode)

Returns { systemPrompt: string, userPrompt: string }.

Options are { systemOptions?, userOptions? } — each is required only when the corresponding template contains {{placeholders}}.

promptSection(template)

Creates a reusable prompt fragment. Returns { template, render(vars?) }.

Scripts

pnpm test          # Run tests
pnpm build         # Compile TypeScript
pnpm typecheck     # Type-check without emitting