Modules@robinpath/template

@robinpath/template

0.1.0Public

Mustache-like template engine with variable substitution, conditional sections, loops, and simple string interpolation

@robinpath/template

Mustache-like template engine with variable substitution, conditional sections, loops, and simple string interpolation

Category Functions Auth License

Why use this module?

The template module lets you:

  • Render a Mustache-like template string with variable substitution, sections, and loops
  • Read a template from a file and render it with the provided data object
  • HTML-escape a string, converting &, <, >, ", and ' to their HTML entity equivalents
  • Validate template syntax, checking for unclosed tags, mismatched sections, and other structural errors
  • Extract all unique variable and section names used in a template

All functions are callable directly from RobinPath scripts with a simple, consistent API.

Installation

npm install @robinpath/template

Quick Start

No credentials needed — start using it right away:

template.renderFile "/tmp/greeting.mustache" { "name": "World" }

Available Functions

FunctionDescription
template.renderRender a Mustache-like template string with variable substitution, sections, and loops
template.renderFileRead a template from a file and render it with the provided data object
template.escapeHTML-escape a string, converting &, <, >, ", and ' to their HTML entity equivalents
template.compileValidate template syntax, checking for unclosed tags, mismatched sections, and other structural errors
template.extractVariablesExtract all unique variable and section names used in a template
template.renderStringSimple string interpolation using ${key} placeholders (no sections or loops)

Examples

Read a template from a file and render it with the provided data object

template.renderFile "/tmp/greeting.mustache" { "name": "World" }

HTML-escape a string, converting &, <, >, ", and ' to their HTML entity equivalents

template.escape "<script>alert(1)</script>"

Validate template syntax, checking for unclosed tags, mismatched sections, and other structural errors

template.compile "{{#items}}{{name}}{{/items}}"

Integration with RobinPath

import { RobinPath } from "@wiredwp/robinpath";
import Module from "@robinpath/template";

const rp = new RobinPath();
rp.registerModule(Module.name, Module.functions);
rp.registerModuleMeta(Module.name, Module.functionMetadata);

const result = await rp.executeScript(`
  template.renderFile "/tmp/greeting.mustache" { "name": "World" }
`);

Full API Reference

See MODULE.md for complete documentation including all parameters, return types, error handling, and advanced examples.

Related Modules

License

MIT

Versions (1)

VersionTagPublished
0.1.0latestyesterday
Install
$ robinpath install @robinpath/template
Version0.1.0
LicenseMIT
Unpacked Size5.9 KB
Versions1
Weekly Downloads0
Total Downloads0
Stars0
Last Publishyesterday
Createdyesterday

Category

utilities