@office-open/docx 0.8.1 → 0.9.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 CHANGED
@@ -51,28 +51,23 @@ bun add @office-open/docx
51
51
  ## Quick Start
52
52
 
53
53
  ```typescript
54
- import { Document, Paragraph, TextRun, Packer } from "@office-open/docx";
54
+ import { generateDocument } from "@office-open/docx";
55
55
  import { writeFileSync } from "node:fs";
56
56
 
57
- const doc = new Document({
57
+ const buffer = await generateDocument({
58
58
  sections: [
59
59
  {
60
60
  children: [
61
- new Paragraph({
62
- children: [
63
- new TextRun("Hello World"),
64
- new TextRun({
65
- text: " - Bold text",
66
- bold: true,
67
- }),
68
- ],
69
- }),
61
+ {
62
+ paragraph: {
63
+ children: ["Hello World", { text: " - Bold text", bold: true }],
64
+ },
65
+ },
70
66
  ],
71
67
  },
72
68
  ],
73
69
  });
74
70
 
75
- const buffer = await Packer.toBuffer(doc);
76
71
  writeFileSync("My Document.docx", buffer);
77
72
  ```
78
73
 
@@ -82,44 +77,42 @@ Check the [demo folder](./demo) for 100+ working examples covering every feature
82
77
 
83
78
  ## Benchmark
84
79
 
85
- Performance comparison against original `docx` (9.6.1) package (higher ops/s is better, Windows 11 / Node 24).
80
+ Performance vs original `docx` (9.6.1) package (higher ops/s is better, Windows 11 / Node 24).
86
81
 
87
- **Default** = XML DEFLATE level 1 (SuperFast, matching MS Office) + media STORE. **All STORE** = no compression (`{ compression: { xml: 0 } }`). **docx** (async) always uses DEFLATE for ALL entries including images (via JSZip, hardcoded, no STORE option).
82
+ **Default** = XML DEFLATE level 1 (SuperFast, matching MS Office) + media STORE. **All STORE** = no compression (`{ compression: { xml: 0 } }`). **docx** (async only) always uses DEFLATE for ALL entries including images (via JSZip, hardcoded, no STORE option).
88
83
 
89
84
  ```typescript
90
85
  // Default (matches MS Office)
91
- await Packer.toBuffer(doc);
86
+ await generateDocument(options);
92
87
  // All STORE (no compression)
93
- await Packer.toBuffer(doc, { compression: { xml: 0 } });
88
+ await generateDocument(options, { compression: { xml: 0 } });
94
89
  ```
95
90
 
96
91
  **Create + toBuffer (end-to-end)**
97
92
 
98
93
  | Scenario | Default sync | Default async | All STORE sync | All STORE async | docx |
99
94
  | ------------------------------ | -----------: | ------------: | -------------: | --------------: | --------: |
100
- | Simple (2p + 1 img) | 174 ops/s | 155 ops/s | 202 ops/s | 203 ops/s | 82 ops/s |
101
- | Styled paragraphs (20) + 1 img | 179 ops/s | 146 ops/s | 198 ops/s | 198 ops/s | 86 ops/s |
102
- | Table (10x5) | 949 ops/s | 565 ops/s | 1,830 ops/s | 1,867 ops/s | 190 ops/s |
103
- | Full featured + 2 imgs | 94 ops/s | 89 ops/s | 102 ops/s | 100 ops/s | 57 ops/s |
95
+ | Simple (2p + 1 img) | 827 ops/s | 493 ops/s | 1,392 ops/s | 1,483 ops/s | 89 ops/s |
96
+ | Styled paragraphs (20) + 1 img | 856 ops/s | 497 ops/s | 1,558 ops/s | 1,574 ops/s | 95 ops/s |
97
+ | Table (10x5) | 1,390 ops/s | 647 ops/s | 3,786 ops/s | 3,707 ops/s | 217 ops/s |
98
+ | Full featured + 2 imgs | 547 ops/s | 364 ops/s | 851 ops/s | 819 ops/s | 56 ops/s |
104
99
 
105
100
  **Large Files — Create + toBuffer**
106
101
 
107
102
  | Scenario | Default sync | Default async | All STORE sync | All STORE async | docx |
108
103
  | ------------------------------ | -----------: | ------------: | -------------: | --------------: | ---------: |
109
- | 2000 paragraphs + 20 images | 4.68 ops/s | 3.13 ops/s | 3.50 ops/s | 3.08 ops/s | 2.07 ops/s |
110
- | 200x10 table | 64.9 ops/s | 62.6 ops/s | 69.7 ops/s | 72.6 ops/s | 19.5 ops/s |
111
- | 20 sections x 100p + 40 images | 1.58 ops/s | 1.69 ops/s | 1.79 ops/s | 1.65 ops/s | 1.16 ops/s |
104
+ | 2000 paragraphs + 20 images | 29.4 ops/s | 31.5 ops/s | 27.5 ops/s | 32.2 ops/s | 2.7 ops/s |
105
+ | 200x10 table | 298 ops/s | 233 ops/s | 313 ops/s | 317 ops/s | 39.6 ops/s |
106
+ | 20 sections x 100p + 40 images | 18.1 ops/s | 17.3 ops/s | 17.4 ops/s | 18.4 ops/s | 1.7 ops/s |
112
107
 
113
108
  **Large File (~100MB) — Mixed Content**
114
109
 
115
- 500 styled paragraphs + 38 mixed-size images (1-5MB, 100MB total) + 50x10 table. Speedup is vs docx.
110
+ 500 styled paragraphs + 38 mixed-size images (1-5MB, 100MB total) + 50x10 table.
116
111
 
117
- | Method | Speed | Speedup |
118
- | --------- | ---------: | -------: |
119
- | All STORE | 0.42 ops/s | **1.4x** |
120
- | Default | 0.31 ops/s | 1.1x |
121
- | docx | 0.29 ops/s | |
112
+ | Scenario | Default sync | Default async | All STORE sync | All STORE async | docx |
113
+ | ------------------------ | -----------: | ------------: | -------------: | --------------: | ---------: |
114
+ | Mixed (500p+38img+50x10) | 3.9 ops/s | 3.9 ops/s | 4.4 ops/s | 4.0 ops/s | 0.31 ops/s |
122
115
 
123
116
  ## License
124
117
 
125
- - [MIT](LICENSE) © [Demo Macro](https://imst.xyz/)
118
+ - [MIT](LICENSE) © [Demo Macro](https://www.demomacro.com/)