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

@telga/gotpl

v0.1.1

Published

A Go-style server-side HTML template engine for Bun and Node.js

Readme

gotpl

Go-style server-side HTML templates for Bun and Node.js.

gotpl is designed to render existing Go-style templates without changing the template files:

import gotpl from "@telga/gotpl";

const templates = gotpl.parseFiles(
  "./views/common.html",
  "./views/home.html",
);

const html = templates.execute("/", {
  Title: "Home",
  Items: ["one", "two"],
});

Supported template syntax

  • define and template inclusion
  • if, else, and else if
  • range, including else and range variables
  • with
  • Dot and nested field access such as .User.Name
  • $ variables and pipelines
  • Common built-ins including eq, ne, len, index, slice, printf, print, call, html, js, and urlquery
  • Go-style comments and whitespace trimming
  • Context-sensitive escaping for HTML text, attributes, URLs, JavaScript, and CSS

parseFiles is synchronous, matching the simple local-file workflow of Go's ParseFiles. Parsing happens once; a TemplateSet can be reused for many requests.

For one-off templates, use parse:

import { parse } from "@telga/gotpl";

const template = parse("<h1>{{ .Title }}</h1>");
const html = template.execute({ Title: "Home" });

For file-based routes, parseGlob wraps each matched file as a named template. Paths are relative to the glob base; index.html maps to /, and nested index files retain their trailing slash:

import { parseGlob } from "@telga/gotpl";

const templates = parseGlob("views/**/*.html");
templates.execute("/", { Title: "Home" });
templates.execute("/admin/", { Title: "Admin" });

Bun usage

import gotpl from "@telga/gotpl";

const templates = gotpl.parseFiles("views/common.html", "views/app.html");

Bun.serve({
  fetch(request) {
    const html = templates.execute(new URL(request.url).pathname, {
      Title: "Dashboard",
    });
    return new Response(html, {
      headers: { "content-type": "text/html; charset=utf-8" },
    });
  },
});

Security model

Template source should be trusted application code. Do not load arbitrary user-provided templates.

Interpolated values are escaped according to their HTML context. Unsafe URL schemes and event-handler attributes are rejected. The html built-in intentionally creates an unescaped value and should only be used with trusted HTML.

This project aims for practical compatibility with Go-style templates; it is not a byte-for-byte implementation of every behavior in Go's html/template package.

Development

bun install
bun test
bun run build

The package build emits dist/index.js and the published package contains only the compiled module, type declarations, and README.