@orkestrel/template
v0.0.12
Published
Stateful template registry and filler with typed placeholders. Part of the @orkestrel line.
Readme
@orkestrel/template
A named, versionable template layer:
{{name}}tokens in acontentstring, resolved against a values record by a single-pass fill engine, and registered and looked up by id through a self-owningTemplateManager.
Declare a template with the createTemplate function, fill it against the
values record your caller supplies, and register it in a TemplateManager
where several templates are looked up by id. Reach for validate where you
need to know which placeholders a fill would reject before you run it. Part of
the @orkestrel line.
Install
npm install @orkestrel/templateRequirements
- Node.js >= 22.12.0
- Runtime dependencies
@orkestrel/contractand@orkestrel/emitter
Usage
import { createTemplate, createTemplateManager } from '@orkestrel/template'
const greeting = createTemplate({ name: 'greeting', content: 'Hi {{name}}' })
greeting.fill({ name: 'Ada' }) // 'Hi Ada'
const templates = createTemplateManager({ templates: [greeting] })
templates.fill(greeting.id, { name: 'Grace' }) // 'Hi Grace'An unresolved required placeholder is governed by TemplateFillOptions.missing,
which defaults to 'error' and throws a TemplateError coded MISSING.
'empty' substitutes '' instead, and 'literal' re-emits the original
{{name}} token.
Guide
For the full surface, see guides/template.md.
