# obol

obol is Go's [`text/template`](https://pkg.go.dev/text/template) for Node.js.
It ports Go's lexer, parser and executor, so a template that runs in Go runs
here and prints the same text.

```ts
import { Template } from '@memomori/obol'

const page = new Template('page').parse(`
{{- define "item"}}<li>{{.name}}{{if .done}} ✓{{end}}</li>{{end -}}
<h1>{{printf "%s (%d)" .title (len .items) | html}}</h1>
<ul>{{range .items}}{{template "item" .}}{{else}}<li>Nothing yet</li>{{end}}</ul>
`)

page.execute({
  title: 'Groceries',
  items: [
    { name: 'Rice', done: true },
    { name: 'Tea', done: false },
  ],
})
```

```text
<h1>Groceries (2)</h1>
<ul><li>Rice ✓</li><li>Tea</li></ul>
```

## What it covers

- actions, pipelines, variables, comments and trim markers
- `if`, `with`, `range`, `break` and `continue`, each with `else`
- `define`, `block` and `template`, and sets of associated templates
- every builtin function, `printf` verbs included
- custom delimiters and `missingkey` options
- `parseFiles` and `parseGlob`
- Go's error messages, with line and column

It has no dependencies and runs on Node 22.18 or later.

## Why

A Go service and a JavaScript tool can share templates: a site generator, an
email preview, an editor that renders what the server will. obol checks itself
against about 800 templates run through real Go. See
[Conformance](conformance.md).

JavaScript forces a few [differences](differences.md), such as one number
type.

## License

MIT.
