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

@monime/docx-templater

v1.0.3

Published

Advanced DOCX template engine with support for placeholders, loops, conditionals, tables, and images

Readme

DOCX Templater - Feature Guide

Overview

This DOCX templater supports advanced features including conditionals, loops, tables, and image embedding.

Features

1. Basic Placeholders

Template: Hello {name}, today is {date}
Data: { name: "John", date: "2024-10-17" }
Result: Hello John, today is 2024-10-17

2. Loops

Repeat content for each item in an array:

Template: {#employees}Employee: {name} - {department}{/employees}
Data: {
  employees: [
    { name: "John", department: "IT" },
    { name: "Jane", department: "HR" }
  ]
}
Result: Employee: John - IT
        Employee: Jane - HR

3. Conditionals

Simple Conditional

Template: {?isApproved}✅ Document approved{/isApproved}
Data: { isApproved: true }
Result: ✅ Document approved

If-Else Conditional

Template: {?hasErrors}❌ Errors found{:else}✅ No errors{/hasErrors}
Data: { hasErrors: false }
Result: ✅ No errors

Condition Evaluation

Conditions are considered "truthy" if:

  • Boolean true
  • Non-empty strings (except "false", "0", "")
  • Non-zero numbers
  • Non-empty arrays
  • Non-null objects

4. Tables

Generate table rows from array data:

  1. Create a table in your DOCX template
  2. In the row where you want data repeated, place {table:arrayName}
  3. Add placeholders for the data fields: {field1}, {field2}, etc.
Template table row: | {table:products} | {name} | {price} | {category} |
Data: {
  products: [
    { name: "Laptop", price: "$999", category: "Electronics" },
    { name: "Book", price: "$25", category: "Education" }
  ]
}
Result: Two table rows with the data filled in

5. Images

Embed images with size control:

{
  signature: {
    type: "image",
    buffer: imageBuffer,      // Buffer containing image data
    extension: "png",         // File extension
    widthInches: 3,          // Optional: width in inches
    heightInches: 2          // Optional: height in inches
  }
}

Usage Example

import { generateDocx } from "./utils";
import { readFileSync, writeFileSync } from "fs";

const templateBuffer = readFileSync("template.docx");
const imageBuffer = readFileSync("signature.png");

const data = {
  // Basic data
  companyName: "Acme Corp",
  date: "2024-10-17",

  // Conditional data
  isUrgent: true,
  hasAttachments: false,

  // Array for loops
  items: [
    { name: "Item 1", status: "Complete" },
    { name: "Item 2", status: "Pending" },
  ],

  // Array for tables
  employees: [
    { name: "John", dept: "IT", salary: "50000" },
    { name: "Jane", dept: "HR", salary: "45000" },
  ],

  // Image
  logo: {
    type: "image",
    buffer: imageBuffer,
    extension: "png",
    widthInches: 2,
  },
};

const outputBuffer = await generateDocx(templateBuffer, data);
writeFileSync("output.docx", outputBuffer);

Template Examples

Document with all features:

{companyName} - {date}

{?isUrgent}🚨 URGENT DOCUMENT{/isUrgent}

Items:
{#items}
- {name}: {status}
{/items}

Employee Table:
| Name | Department | Salary |
|------|------------|--------|
| {table:employees} | {name} | {dept} | {salary} |

{?hasAttachments}📎 Attachments included{:else}No attachments{/hasAttachments}

Signature: {logo}

Tips

  1. Loops: Use {#arrayName}...{/arrayName} for repeating content
  2. Conditionals: Use {?condition}...{/condition} or {?condition}...{:else}...{/condition}
  3. Tables: Place {table:arrayName} in the first column of the row you want to repeat
  4. Images: Always specify the correct file extension
  5. Nested structures: You can nest loops and conditionals