@formfeed/engine 0.1.0
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/LICENSE +21 -0
- package/README.md +54 -0
- package/index.cjs +3306 -0
- package/index.js +3273 -0
- package/package.json +70 -0
- package/types/index.d.cts +17 -0
- package/types/index.d.ts +17 -0
- package/types/lib/analysis/tags.d.cts +36 -0
- package/types/lib/analysis/tags.d.ts +36 -0
- package/types/lib/assemble.d.cts +147 -0
- package/types/lib/assemble.d.ts +147 -0
- package/types/lib/engines/handlebars.d.cts +3 -0
- package/types/lib/engines/handlebars.d.ts +3 -0
- package/types/lib/engines/index.d.cts +7 -0
- package/types/lib/engines/index.d.ts +7 -0
- package/types/lib/engines/jinja2.d.cts +5 -0
- package/types/lib/engines/jinja2.d.ts +5 -0
- package/types/lib/engines/liquid.d.cts +16 -0
- package/types/lib/engines/liquid.d.ts +16 -0
- package/types/lib/errors.d.cts +24 -0
- package/types/lib/errors.d.ts +24 -0
- package/types/lib/helpers/codes.d.cts +21 -0
- package/types/lib/helpers/codes.d.ts +21 -0
- package/types/lib/helpers/collections.d.cts +2 -0
- package/types/lib/helpers/collections.d.ts +2 -0
- package/types/lib/helpers/document.d.cts +29 -0
- package/types/lib/helpers/document.d.ts +29 -0
- package/types/lib/helpers/format.d.cts +5 -0
- package/types/lib/helpers/format.d.ts +5 -0
- package/types/lib/helpers/index.d.cts +17 -0
- package/types/lib/helpers/index.d.ts +17 -0
- package/types/lib/helpers/logic.d.cts +2 -0
- package/types/lib/helpers/logic.d.ts +2 -0
- package/types/lib/helpers/registry.d.cts +18 -0
- package/types/lib/helpers/registry.d.ts +18 -0
- package/types/lib/import/apitemplate.d.cts +45 -0
- package/types/lib/import/apitemplate.d.ts +45 -0
- package/types/lib/limits.d.cts +10 -0
- package/types/lib/limits.d.ts +10 -0
- package/types/lib/preview.d.cts +30 -0
- package/types/lib/preview.d.ts +30 -0
- package/types/lib/schema.d.cts +22 -0
- package/types/lib/schema.d.ts +22 -0
- package/types/lib/snippets.d.cts +22 -0
- package/types/lib/snippets.d.ts +22 -0
- package/types/lib/types.d.cts +140 -0
- package/types/lib/types.d.ts +140 -0
- package/types/types/modules.d.cts +85 -0
- package/types/types/modules.d.ts +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Philipp Staudt IT-Dienstleistungen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @formfeed/engine
|
|
2
|
+
|
|
3
|
+
The template engine behind [Formfeed](https://formfeed.dev): Jinja2, Liquid and Handlebars templates
|
|
4
|
+
with one set of helpers, compiled and rendered to a complete HTML document. The same package runs
|
|
5
|
+
the web editor's preview, the `formfeed` CLI and Formfeed's render servers, so what it produces
|
|
6
|
+
locally is what the API renders. It works in browsers and Node 22+ and uses no Node-only APIs.
|
|
7
|
+
|
|
8
|
+
Most projects need the [CLI](https://www.npmjs.com/package/formfeed) and
|
|
9
|
+
[`@formfeed/testing`](https://www.npmjs.com/package/@formfeed/testing) rather than this package. Use
|
|
10
|
+
it to embed template compilation in your own tools, such as a custom preview.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @formfeed/engine
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { getEngine, defaultHelpers, defaultLimits, assembleDocument } from '@formfeed/engine';
|
|
18
|
+
|
|
19
|
+
const engine = getEngine('liquid');
|
|
20
|
+
const compiled = engine.compile('<h1>{{ title | upper }}</h1>', {});
|
|
21
|
+
const analysis = engine.analyze('<h1>{{ title | upper }}</h1>');
|
|
22
|
+
// analysis.variables → [{ path: ['title'], ... }], analysis.diagnostics → []
|
|
23
|
+
|
|
24
|
+
const html = await engine.render(compiled, { title: 'Hello' }, {
|
|
25
|
+
locale: 'de-DE', timezone: 'Europe/Berlin', currency: 'EUR',
|
|
26
|
+
partials: async () => null, helpers: defaultHelpers(), limits: defaultLimits,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const document = assembleDocument({ html, css: '', head: '', settings: { paper: { format: 'A4' } }, kind: 'pdf' });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The supported surface is the `Engine` interface (`compile`, `analyze`, `render`) returned by
|
|
33
|
+
`getEngine`, the `defaultHelpers()` registry and `defaultLimits`, plus `assembleDocument`,
|
|
34
|
+
`renderVersion` and `inferSchema`. `compile` throws `EngineSyntaxError` with `line` and `column`.
|
|
35
|
+
|
|
36
|
+
## What is inside
|
|
37
|
+
|
|
38
|
+
| Module | Contents |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `engines/` | `jinja2` (Nunjucks with a Python compatibility layer), `liquid` (LiquidJS), `handlebars`, each implementing `Engine` |
|
|
41
|
+
| `helpers/` | One helper registry for all three dialects: formatting (`money`, `date`, `number`, `numToWords`, `t`), text, collections, codes (`qrcode`, `barcode`, `epcQr`), document (`asset`, `pageBreak`, `image`, `chart`) |
|
|
42
|
+
| `analysis/` | Block pairing and sample-data checks behind every `analyze()` |
|
|
43
|
+
| `schema.ts` | `inferSchema(sample)` to JSON Schema 2020-12 |
|
|
44
|
+
| `assemble.ts` | Template settings, print reset, `assembleDocument()` and `renderVersion()` (body, header, footer, title) |
|
|
45
|
+
| `import/` | `importApitemplate()`: converts apitemplate.io templates |
|
|
46
|
+
|
|
47
|
+
## Documentation
|
|
48
|
+
|
|
49
|
+
- [Engine package](https://docs.formfeed.dev/devkit/engine-package)
|
|
50
|
+
- [Template languages](https://docs.formfeed.dev/templates/languages) and [helpers](https://docs.formfeed.dev/templates/helpers)
|
|
51
|
+
|
|
52
|
+
## Licence
|
|
53
|
+
|
|
54
|
+
MIT
|