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

nunjitsu

v0.3.1

Published

A secure direct string template engine written in TypeScript

Readme

Nunjitsu

Nunjitsu is a secure native TypeScript template engine for direct template rendering. It supports a focused subset of Nunjucks 3.2.4 through a closed, synchronous interpreter rather than generated JavaScript.

Use Nunjitsu when templates may be untrusted and the application needs explicit control over every value and function exposed to them. The package targets Node.js 22 or newer and accepts inline template source only; filesystem loading, precompilation, streaming, browser execution, and asynchronous callbacks are outside its scope.

Use the Nunjucks templating documentation as the general syntax reference, then check the local compatibility guide for the subset supported by Nunjitsu. See the security model for trust-boundary details.

Installation

Install using your favorite package manager:

pnpm add nunjitsu
npm install nunjitsu
yarn add nunjitsu

TypeScript API

Quick start

Create a renderer once, then render templates synchronously:

import { createTemplateRenderer } from 'nunjitsu';

const renderer = createTemplateRenderer();

const output = renderer.render('Hello ${{ name }}!', {
  name: 'world',
});

console.log(output); // Hello world!

The default variable delimiters are ${{ and }}.

Creating a renderer

function createTemplateRenderer(
  options?: TemplateRendererOptions,
): TemplateRenderer;

createTemplateRenderer returns an immutable renderer. Its filters, globals, delimiter mode, and whitespace behavior cannot be changed after creation.

| Option | Type | Default | Description | | -------------------- | ------------------------------------------ | ------- | --------------------------------------------------------------- | | filters | Readonly<Record<string, TemplateFilter>> | {} | Trusted synchronous template filters. | | globals | Readonly<Record<string, TemplateGlobal>> | {} | Trusted values and synchronous functions. | | cookiecutterCompat | boolean | false | Uses {{ and }} plus supported Jinja compatibility behavior. | | trimBlocks | boolean | false | Removes one newline immediately after block tags. | | lstripBlocks | boolean | false | Removes indentation before block tags on otherwise blank lines. |

Rendering

interface TemplateRenderer {
  render(
    source: string,
    context?: TemplateContext | PreparedTemplateContext,
    options?: TemplateRenderOptions,
  ): string;
}

Each call parses and renders one complete template.

const result = renderer.render(
  '${{ user.name }} has ${{ items | length }} items',
  {
    user: { name: 'Patrik' },
    items: ['one', 'two'],
  },
);

Use renderValue when a sole interpolation should retain its value type:

interface TemplateRenderer {
  renderValue(
    source: string,
    context?: TemplateContext | PreparedTemplateContext,
    options?: TemplateRenderOptions,
  ): TemplateValue | undefined;
}

const config = renderer.renderValue('${{ config }}', {
  config: { retries: 3 },
});
// { retries: 3 }

Templates containing text, multiple interpolations, or statements return their normally rendered string. Returned arrays and records are copied and frozen. This is useful for configuration, workflow, and structured-data templates.

TemplateRenderOptions configures per-render resource limits. See Security for details.

Prepared contexts

Use a prepared context when the same data is rendered repeatedly. It is copied once into an immutable snapshot owned by the renderer:

interface TemplateRenderer {
  prepareContext(context?: TemplateContext): PreparedTemplateContext;
}

interface PreparedTemplateContext {
  withPath(
    path: readonly string[],
    value: TemplateValue,
  ): PreparedTemplateContext;
}

withPath returns a new snapshot and leaves the original unchanged.

const initial = renderer.prepareContext({
  parameters: { service: 'catalog' },
  steps: {},
});

const afterBuild = initial.withPath(['steps', 'build'], {
  output: { image: 'example/catalog:1.0' },
});

renderer.render('${{ steps.build.output.image }}', afterBuild);

A prepared context can only be used with the renderer that created it.

Template values

Contexts and capability results use plain data values:

type TemplateValue =
  | null
  | boolean
  | number
  | string
  | readonly TemplateValue[]
  | Readonly<{ [key: string]: TemplateValue }>;

type TemplateContext = Readonly<Record<string, TemplateValue>>;

Filters and globals

type TemplateFilter = (
  input: TemplateValue | undefined,
  ...arguments_: readonly (TemplateValue | undefined)[]
) => TemplateValue | undefined;

type TemplateGlobalFunction = (
  ...arguments_: readonly (TemplateValue | undefined)[]
) => TemplateValue | undefined;

type TemplateGlobal = TemplateValue | TemplateGlobalFunction;

Filters and global functions must be synchronous.

const renderer = createTemplateRenderer({
  filters: {
    slugify(input) {
      if (typeof input !== 'string') {
        throw new TypeError('slugify requires a string');
      }
      return input.toLowerCase().replaceAll(' ', '-');
    },
  },
  globals: {
    environment: 'production',
    deployment(name) {
      if (typeof name !== 'string') {
        throw new TypeError('deployment requires a string');
      }
      return { name, ready: true };
    },
  },
});

See Security for the capability boundary and failure behavior.

Development

Development requires Node.js 22.18 or newer and the pnpm version pinned in package.json.

pnpm install
pnpm test

Run pnpm benchmark for the full Nunjucks comparison harness. Architecture, testing, compatibility, and release documentation start in docs/. Contributors and coding agents must also follow AGENTS.md.

License

Licensed under the MIT License. Adapted Nunjucks tests retain their upstream license and attribution as documented in Compatibility.