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

prmtx

v0.0.1

Published

npm package template with tsup and typescript

Readme

imprompt 🔨

A TypeScript toolkit for building structured AI prompts using proven prompting techniques. Provider-agnostic — outputs plain strings you can send to any LLM (Claude, GPT-4, Gemini, etc.).

Install

npm install imprompt

Quick Start

Every technique is a function that returns a string. Compose them freely:

import { persona, chainOfThought, instruction, compose } from "imprompt";

const prompt = compose([
  persona({
    role: "senior TypeScript engineer",
    expertiseLevel: "world-class",
    specialisations: ["type safety", "performance"],
    traits: ["concise", "direct"],
    task: "Review this code.",
  }),
  chainOfThought({
    question: "What are the critical issues?",
    strategy: "first-principles",
  }),
  instruction({
    task: "Provide a structured code review.",
    dos: ["Group by severity", "Include fixes"],
    donts: ["Don't repeat the code verbatim"],
    outputFormat: "markdown",
  }),
]);

Techniques

Functions (stateless — preferred API)

| Function | Technique | Best for | | ------------------ | ---------------- | ---------------------- | | fewShot() | Few-Shot | Format/style adherence | | chainOfThought() | Chain-of-Thought | Reasoning & math | | persona() | Role/Persona | Domain expertise | | instruction() | Instruction | Structured constraints | | compose() | Composition | Combining techniques |

Classes (stateful — for multi-step workflows)

| Class | Technique | Best for | | ---------------- | --------------- | ---------------------- | | PromptChain | Prompt Chaining | Multi-step pipelines | | ReActPrompt | ReAct | Agentic tool-use loops | | PromptTemplate | Templates | Reusable {{var}} |


Usage

1. Few-Shot

import { fewShot } from "imprompt";

const prompt = fewShot({
  instruction: "Classify the sentiment of the review.",
  examples: [
    { input: "Great product!", output: "Positive" },
    { input: "Terrible experience.", output: "Negative" },
  ],
  query: "Not bad, could be better.",
});

2. Chain-of-Thought

import { chainOfThought } from "imprompt";

const prompt = chainOfThought({
  question: "If a train travels 60 mph for 2.5 hours, how far does it go?",
  strategy: "step-by-step", // "first-principles" | "pros-cons" | "custom"
});

3. Persona

import { persona } from "imprompt";

const prompt = persona({
  role: "data scientist",
  expertiseLevel: "senior", // "junior" | "mid" | "senior" | "world-class"
  specialisations: ["NLP", "Python"],
  traits: ["concise", "pragmatic"],
  task: "Explain transformer attention to a junior engineer.",
});

4. Instruction

import { instruction } from "imprompt";

const prompt = instruction({
  task: "Summarise this article.",
  dos: ["Be concise", "Use bullet points"],
  donts: ["Don't add opinions"],
  outputFormat: "bullet-list",
  tone: "technical",
  audience: "engineers",
});

5. Compose

Combine any number of sections into one prompt:

import { compose, persona, instruction } from "imprompt";

const prompt = compose([
  persona({ role: "copywriter", task: "Write ad copy." }),
  instruction({ task: "Write a tagline.", tone: "casual" }),
]);

// Custom divider (default is "\n\n---\n\n")
const prompt2 = compose([...sections], "\n\n");

6. Prompt Chain

import { PromptChain } from "imprompt";

const chain = new PromptChain({
  initialInput: "The history of the Roman Empire",
  steps: [
    {
      name: "Outline",
      instruction: "Create a 5-point outline about: {{input}}",
      outputKey: "outline",
    },
    {
      name: "Draft",
      instruction: "Write an intro based on:\n{{outline}}",
      outputKey: "intro",
    },
    { name: "Polish", instruction: "Polish this intro:\n{{intro}}" },
  ],
});

// Execute step by step, injecting model responses as variables
const step0 = chain.buildStep(0);
// ... send to model, get response ...
chain.setVariable("outline", modelResponse);
const step1 = chain.buildStep(1);

7. ReAct

import { ReActPrompt } from "imprompt";

const react = new ReActPrompt({
  goal: "Find the current population of Tokyo.",
  tools: [
    {
      name: "search",
      description: "Search the web for current facts.",
      usageExample: 'search("Tokyo population 2024")',
    },
  ],
  maxCycles: 5,
});

const prompt = react.build();

// Continue an in-progress loop:
react
  .addHistory({ cycle: "thought", content: "I need to search for this." })
  .addHistory({ cycle: "action", content: 'search("Tokyo population 2024")' })
  .addHistory({ cycle: "observation", content: "~13.96 million as of 2024." });

const nextPrompt = react.build();

8. Template

import { PromptTemplate } from "imprompt";

const template = new PromptTemplate({
  template: "Review the following {{language}} code:\n\n```{{language}}\n{{code}}\n```",
  variables: [
    { name: "language", defaultValue: "TypeScript" },
    { name: "code", required: true },
  ],
});

const prompt = template.fill({ code: "const x = 1" }).build();

TypeScript Types

All options objects are fully typed:

import type {
  FewShotOptions,
  FewShotExample,
  CoTStrategy,
  ChainOfThoughtOptions,
  ExpertiseLevel,
  PersonaOptions,
  ChainStep,
  PromptChainOptions,
  ReActTool,
  ReActOptions,
  InstructionOptions,
  OutputFormat,
  ToneHint,
  PromptBuilder,
} from "imprompt";

Build

npm install
npm run build
# Output in ./dist — includes .js, .d.ts, and source maps

License

MIT