@orkestrel/template 0.0.16 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -12
- package/dist/src/core/index.cjs +4643 -159
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +2479 -141
- package/dist/src/core/index.d.ts +2479 -141
- package/dist/src/core/index.js +4528 -161
- package/dist/src/core/index.js.map +1 -1
- package/package.json +20 -11
package/README.md
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
# @orkestrel/template
|
|
2
2
|
|
|
3
|
-
> A
|
|
4
|
-
>
|
|
5
|
-
>
|
|
6
|
-
|
|
7
|
-
Declare
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
> A template registry, single-pass `{{name}}` filler, and compiled Jinja
|
|
4
|
+
> `TemplateTree` compiler, evaluator, canonical renderer, and safe AST
|
|
5
|
+
> projector into `@orkestrel/html` and `@orkestrel/markdown`.
|
|
6
|
+
|
|
7
|
+
Declare single-pass templates with `createTemplate` and manage collections by id
|
|
8
|
+
through `createTemplateManager`, or compile Jinja chat templates into an
|
|
9
|
+
immutable `TemplateTree` AST with `createTemplateTree` to evaluate values,
|
|
10
|
+
round-trip canonical source through `renderTemplate`, and project safely into
|
|
11
|
+
`@orkestrel/html` and `@orkestrel/markdown` (`templateToHTML`,
|
|
12
|
+
`templateToMarkdown`). Reach for `validate` where you need to know which
|
|
13
|
+
placeholders a single-pass fill would reject before you run it. Part of the
|
|
14
|
+
`@orkestrel` line.
|
|
12
15
|
|
|
13
16
|
## Install
|
|
14
17
|
|
|
@@ -18,19 +21,30 @@ npm install @orkestrel/template
|
|
|
18
21
|
|
|
19
22
|
## Requirements
|
|
20
23
|
|
|
21
|
-
- Node.js >= 22.
|
|
22
|
-
- Runtime dependencies `@orkestrel/contract
|
|
24
|
+
- Node.js >= 22.18.0
|
|
25
|
+
- Runtime dependencies `@orkestrel/contract`, `@orkestrel/emitter`, `@orkestrel/html`, and `@orkestrel/markdown`
|
|
23
26
|
|
|
24
27
|
## Usage
|
|
25
28
|
|
|
26
29
|
```ts
|
|
27
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
createTemplate,
|
|
32
|
+
createTemplateManager,
|
|
33
|
+
createTemplateTree,
|
|
34
|
+
templateToHTML,
|
|
35
|
+
templateToMarkdown,
|
|
36
|
+
} from '@orkestrel/template'
|
|
28
37
|
|
|
29
38
|
const greeting = createTemplate({ name: 'greeting', content: 'Hi {{name}}' })
|
|
30
39
|
greeting.fill({ name: 'Ada' }) // 'Hi Ada'
|
|
31
40
|
|
|
32
41
|
const templates = createTemplateManager({ templates: [greeting] })
|
|
33
42
|
templates.fill(greeting.id, { name: 'Grace' }) // 'Hi Grace'
|
|
43
|
+
|
|
44
|
+
const tree = createTemplateTree({ source: '{% for user in users %}Hello {{ user }}!{% endfor %}' })
|
|
45
|
+
tree.evaluate({ users: ['Ada'] }) // 'Hello Ada!'
|
|
46
|
+
templateToHTML('Hi {{ user }}', { user: 'Ada' })
|
|
47
|
+
templateToMarkdown('# Hi {{ user }}', { user: 'Ada' })
|
|
34
48
|
```
|
|
35
49
|
|
|
36
50
|
An unresolved required placeholder is governed by `TemplateFillOptions.missing`,
|