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

@light-stack/templater

v0.0.2

Published

Readme

@light-stack/templater

Isomorphic document templating over docxtemplater: declare a variable schema, validate human input, then fill a .docx (ArrayBuffer in → ArrayBuffer out). No React, no filesystem, no secrets.

| Concern | docxtemplater | @light-stack/templater | |---------|---------------|--------------------------| | Replace {{full_name}} in a .docx | Yes | Delegates | | Title / description / required for a form | No | Schema | | List missing required fields before convert | No | validate() | | Missing values → empty string | You set nullGetter each time | Fixed policy in convert() |

Install

pnpm add @light-stack/templater
npm install @light-stack/templater

Quick start

import { DocumentTemplater } from '@light-stack/templater';

const templater = new DocumentTemplater({
  variables: [
    {
      placeholder: 'full_name', // appears in the file as {{full_name}}
      title: 'Full name',
      description: 'As in the charter',
      required: true,
    },
    {
      placeholder: 'notes',
      title: 'Notes',
      description: 'Optional remarks',
      required: false,
    },
  ],
  // delimiters: { start: '{{', end: '}}' }, // default
});

const values = { full_name: 'Ada Lovelace', notes: '' };

const result = templater.validate(values);
if (!result.ok) {
  // result.missingRequired — full variable objects (title + description for UI)
  // result.invalidValues — non-string entries
}

const filled = await templater.convert(docxArrayBuffer, values);
// ArrayBuffer — missing/empty/unknown tags → ""

Typical host flow:

  1. validate(values)
  2. If missingRequired.length, show UI with title + description
  3. Cancel → stop. Continue → convert() (blanks in the file)

API

| Export | Description | |--------|-------------| | DocumentTemplater | Constructor + getVariables(), validate(), convert(), inspect() | | TemplaterOptions | { variables, delimiters? } | | Variable | Schema entry (placeholder, title, description, required, optional type: 'string') | | ValidateResult | { ok, missingRequired, unknownKeys, invalidValues } | | Values | Record<string, string> |

Constructor

  • variables must be a non-empty unique list; placeholder is the identity (non-empty, no delimiter characters).
  • Invalid schema throws TypeError on construct.
  • placeholder is without delimiters so PDF/other engines can reuse the same schema later.

validate(values)

  • Required is missing if the key is absent, undefined, null, or whitespace-only.
  • Non-strings are listed in invalidValues (ok: false).
  • Extra keys are allowed and listed in unknownKeys.
  • Never reads the document — schema only.

convert(input, values, options?)

  • v1 format: docx only (options.format defaults to 'docx').
  • Always substitutes; missing values → "". Does not refuse on missing required fields.
  • Extra keys in values are passed through to docxtemplater.
  • Non-string values throw TypeError.
  • Does not mutate input.

inspect(input)

Returns placeholder names found in the file (via docxtemplater’s inspect module) for schema vs file diffs.

Runtime

Isomorphic — works in browser and Node. Pass ArrayBuffer / Uint8Array-backed buffers; no DOM or fs APIs.