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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tinyplate.js

v1.0.0

Published

A dead simple templating (<38 LOC) engine written in pure typescript.

Readme

tinyplate

Tinyplate is a dead simple templating engine written in pure typescript. It is designed to be super fast, minimal, with zero dependencies and easy to use.

It's tiny with only 37 lines of code and a size of 583 bytes when bundled.

Features

  • Has 0 dependencies
  • Extremely fast
  • Supports HTML encoding
  • Requires no options or configurations for use
  • Works in Node, Bun, Deno, browser, and even your toaster (probably)

The bundle even fits here:

var g=/`|\\/g,a=/\\(`|\\)/g,p=/[\r\t\n]/g,E=/<%=([\s\S]+?)%>/g,i=/<%!([\s\S]+?)%>/g,l=/<%([\s\S]+?(\}?)+)%>/g,_=/\n`;/g;function u(c,o){let t=(n)=>n.replace(a,"$1").replace(p," "),r=`const encode = ${((n)=>{let e={"&":"&#38;","<":"&#60;",">":"&#62;",'"':"&#34;","'":"&#39;","/":"&#47;"};return n.replace(/&(?!#?\w+;)|<|>|"|'|\//g,(s)=>e[s])}).toString()};let _=\`${c.replace(g,"\\$&").replace(E,(n,e)=>`\`+(${t(e)})+\``).replace(i,(n,e)=>`\`+encode(${t(e)})+\``).replace(l,(n,e)=>`\`;${t(e)};_+=\``).replace(_,"`;")}\`;return _;`;return new Function("it",r)(o)}export{u as default};

Important Considerations ⚠️

  • Tinyplate is extremely minimal; it does not have any options or configurations.
  • It allows arbitrary code execution in templates, which can be extremely powerful but also be dangerous. Do not use user input as part of the template.
  • Although it supports HTML encoding through <%! .. %> tags, the library is new and has not been fully tested against code injection. Use caution with untrusted input.
  • If you need more features out of the box, consider trying doT or eta. Both are excellent tools that have inspired this library.

Usage

  • Install with npm i tinyplate.js
  • <% .. %> - for code blocks
  • <%= .. %> - for interpolations
  • <%! .. %> - for interpolations with HTML encoding

Examples

You can check some examples here and in the examples folder. Even this README is generated using tinyplate.

Basic example

import tinyplate from "tinyplate.js";

tinyplate("<li><%= it.name %></li>", { name: "tinyplate" });

Using a file

import fs from "node:fs";
import tinyplate from "tinyplate.js";

const template = fs.readFileSync("template.txt", "utf8");
tinyplate(template, { name: "tinyplate" });

Layout and partials

import tinyplate from "tinyplate.js";

const LAYOUT_TEMPLATE = `
<html>
<head>
  <title><%! it.title %></title>
</head>
<body>
<%= it.body %>
</body>`;

const BODY_TEMPLATE = `
<main>
  <h1><%! it.content %></h1>
</main>
`;

const context = { title: "tinyplate", content: "Hello, world!" };
tinyplate(LAYOUT_TEMPLATE, {
	...context,
	body: tinyplate(BODY_TEMPLATE, context),
});

Logic

import tinyplate from "tinyplate.js";

const TEMPLATE = `
<div>
  <ul>
  <% for (let i = 0; i < it.amount; i++) { %>
    <li><%= i %></li>
  <% } %>
  </ul>

  <% if (it.name) { %>
    <p>Hello, <%= it.name %>!</p>
  <% } else { %>
    <p>Hello, world!</p>
  <% } %>
</div>`;

tinyplate(TEMPLATE, { name: "tinyplate", amount: 5 });

Credits

Tinyplate is heavily inspired by doT and eta. Huge thanks to the creators of doT from where I borrowed the regexes and some of the logic. Also, a big shoutout to the creators of eta for inspiring the templating syntax.