@json-to-office/json-to-docx 0.1.0 → 0.2.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/README.md +59 -6
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# @json-to-office/json-to-docx
|
|
2
2
|
|
|
3
|
-
Generate professional
|
|
3
|
+
**Documents as data, not code.** Generate professional `.docx` files from JSON definitions — serializable, schema-validated, LLM-friendly.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@json-to-office/json-to-docx)
|
|
6
|
+
[](https://github.com/Wiseair-srl/json-to-office/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Part of the [json-to-office](https://github.com/Wiseair-srl/json-to-office) monorepo.
|
|
4
9
|
|
|
5
10
|
## Install
|
|
6
11
|
|
|
@@ -11,17 +16,65 @@ npm install @json-to-office/json-to-docx docx
|
|
|
11
16
|
## Usage
|
|
12
17
|
|
|
13
18
|
```ts
|
|
14
|
-
import {
|
|
19
|
+
import { generateDocument } from '@json-to-office/json-to-docx';
|
|
20
|
+
import { Packer } from 'docx';
|
|
21
|
+
import { writeFileSync } from 'fs';
|
|
15
22
|
|
|
16
|
-
const
|
|
17
|
-
|
|
23
|
+
const doc = await generateDocument({
|
|
24
|
+
name: 'docx',
|
|
25
|
+
props: { theme: 'minimal' },
|
|
26
|
+
children: [
|
|
27
|
+
{ name: 'heading', props: { text: 'Q1 Report', level: 1 } },
|
|
28
|
+
{
|
|
29
|
+
name: 'paragraph',
|
|
30
|
+
props: { text: 'Revenue grew **32%** quarter-over-quarter.' },
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'table',
|
|
34
|
+
props: {
|
|
35
|
+
columns: [
|
|
36
|
+
{
|
|
37
|
+
header: { content: 'Region' },
|
|
38
|
+
cells: [
|
|
39
|
+
{ content: 'North America' },
|
|
40
|
+
{ content: 'Europe' },
|
|
41
|
+
{ content: 'APAC' },
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
header: { content: 'Revenue' },
|
|
46
|
+
cells: [
|
|
47
|
+
{ content: '$4.2M' },
|
|
48
|
+
{ content: '$2.8M' },
|
|
49
|
+
{ content: '$1.6M' },
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
18
55
|
{
|
|
19
|
-
|
|
56
|
+
name: 'image',
|
|
57
|
+
props: { path: 'https://example.com/chart.png', width: '80%' },
|
|
20
58
|
},
|
|
21
59
|
],
|
|
22
60
|
});
|
|
61
|
+
|
|
62
|
+
const buffer = await Packer.toBuffer(doc);
|
|
63
|
+
writeFileSync('report.docx', buffer);
|
|
23
64
|
```
|
|
24
65
|
|
|
66
|
+
## Components
|
|
67
|
+
|
|
68
|
+
13 component types: **paragraph**, **heading** (h1-h6), **table** (column-based, borders, nested content, repeat header on page break), **image** (URL/file/base64, contain/cover/crop, captions, floating), **list** (57 numbering formats, 9 nesting levels), **columns**, **text-box**, **statistic** (number display with trend indicators), **highcharts**, **header/footer**, **table of contents**, and **sections** with independent page config.
|
|
69
|
+
|
|
70
|
+
## Highlights
|
|
71
|
+
|
|
72
|
+
- **Theme system** — Colors, fonts, spacing, component defaults. 3 built-in themes (minimal, modern, corporate) or define your own.
|
|
73
|
+
- **Schema validation** — TypeBox schemas as both TypeScript types and runtime validators.
|
|
74
|
+
- **Plugin architecture** — Create versioned custom components with `createComponent()`, chainable API, schema generation.
|
|
75
|
+
- **Rich text** — Markdown formatting (**bold**, _italic_) in paragraphs, headings, and captions.
|
|
76
|
+
- **Peer dependency** — Uses [docx](https://github.com/dolanmedia/docx) as the rendering backend. You control the version.
|
|
77
|
+
|
|
25
78
|
## License
|
|
26
79
|
|
|
27
|
-
[MIT](
|
|
80
|
+
[MIT](https://github.com/Wiseair-srl/json-to-office/blob/main/LICENSE) — Wiseair srl
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@json-to-office/json-to-docx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Professional .docx document generation from JSON - Public API package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"LICENSE"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@json-to-office/core-docx": "^0.
|
|
28
|
-
"@json-to-office/shared": "^0.
|
|
29
|
-
"@json-to-office/shared-docx": "^0.
|
|
27
|
+
"@json-to-office/core-docx": "^0.2.0",
|
|
28
|
+
"@json-to-office/shared": "^0.2.0",
|
|
29
|
+
"@json-to-office/shared-docx": "^0.2.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"docx": "9.5.1",
|