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

odt-templater

v1.0.1

Published

A simple templating engine for OpenDocument Text (.odt) files.

Readme

Odt-templater

A simple templating engine for OpenDocument Text (.odt) files that can be used in Node.js and in the browser.

🚀 Super lightweight: 2KB (zipped 659 bytes)

Features

  • Placeholder replacement
  • Conditionals
  • Empty conditionals

Getting Started

npm i odt-templater

The odt templater requires the content of the ODT file as a string as a parameter. The content must be read from the content.xml file within the ODT file. Any ZIP library, such as JSZip or PizZip, can be used for this task.

There is a GitHub repository with the following examples.

Usage in Node.js

const { OdtTemplater } = require("odt-templater");
const fs = require("fs");
const PizZip = require("pizzip");

const data = {
  title: "Hello World",
  description: "A wonderful text",
  user: {
    first_name: "John",
    last_name: "Doe",
    city: "New York",
    age: 30,
    email: "[email protected]",
    website: "https://example.com",
  },
};

// 1. Load the ODT template file
const templateBuffer = fs.readFileSync("./template.odt");
const zip = new PizZip(templateBuffer);
const contentFile = zip.file("content.xml");
if (!contentFile) throw new Error("content.xml not found in the ODT file.");
const content = contentFile.asText();

// 2. Initialize OdtTemplater and render the document
const templater = new OdtTemplater(content);
const renderedContent = templater.render(data);

// 3. Replace the content in the ZIP
zip.file("content.xml", renderedContent);

// 4. Generate the output ODT file
const outputBuffer = zip.generate({ type: "nodebuffer" });
fs.writeFileSync("./output.odt", outputBuffer);

Usage in the browser

import { OdtTemplater } from "odt-templater";

You can also embed the odt-templater from a CDN.

import { OdtTemplater } from "https://cdn.jsdelivr.net/npm/odt-templater/dist/esm/index.js";
async function generateOdtDocument() {
  const data = {
    title: "Hello World",
    description: "A wonderful text",
    user: {
      first_name: "John",
      last_name: "Doe",
      city: "New York",
      age: 30,
      email: "[email protected]",
      website: "https://example.com",
    },
  };

  // 1. Load the ODT template file
  const response = await fetch("template.odt");
  const templateArrayBuffer = await response.arrayBuffer();

  // 2. Get the 'content.xml' from the ODT file
  const jszip = new JSZip();
  const zip = await jszip.loadAsync(templateArrayBuffer);
  const contentFile = zip.file("content.xml");
  if (!contentFile) throw new Error("content.xml not found in the ODT file.");
  const content = await contentFile.async("string");

  // 3. Initialize OdtTemplater and render the document
  const templater = new OdtTemplater(content);
  const renderedContent = templater.render(data);

  // 4. Replace the content in the ZIP
  zip.file("content.xml", renderedContent);

  // 5. Generate the output ODT file as a Blob
  const outputBlob = await zip.generateAsync({ type: "blob" });

  // 6. Create a download link and trigger the download
  const url = URL.createObjectURL(outputBlob);
  const a = document.createElement("a");
  a.href = url;
  a.download = "output.odt";
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
  URL.revokeObjectURL(url);
}

document.getElementById("generateBtn").addEventListener("click", generateOdtDocument);

Template Syntax

Placeholders

Placeholders are defined in the ODT template file with curly braces. The following syntax is supported:

Single key placeholders:

{key}

(Replaces with the value of data[key])

Nested key placeholders:

{key.key}

(Replaces with the value of data[key][key])

An space can be added between the braces and the key:

{ key }
{ key.key }

Example

{ title }

Hello {user.first_name} {user.last_name}!

This is an example.
{ description }

Conditionals syntax

Conditions are defined with curly braces, a hash mark, the key being checked, a double equal sign, and the value being compared.

Inline conditionals

{#key == value} Hello World {/}
{#key.key == value} Hello World {/}

An space can be added between the braces and the key:

{ #key == value } Hello World {/}
{ #key.key == value } Hello World {/}

Block conditionals

{#key == value}
  Hello World
{/}
{#user.first_name == John}
  Hello {user.first_name}
{/}

Empty Conditionals

Check your values for empty strings, null or undefined values.

Empty conditionals are defined with curly braces, a hash mark, and a key.

Inline conditionals

{#key} Hello World {/}
{#key.key} Hello World {/}

An space can be added between the braces and the key:

{ #key } Hello World {/}
{ #key.key } Hello World {/}

Block conditionals

{#key}
  Hello World
{/}
{#user.first_name}
  Hello {user.first_name}
{/}