@turbodocx/html-to-docx 1.12.0 → 1.13.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
@@ -22,6 +22,115 @@ Use the npm to install the project.
22
22
  npm install @turbodocx/html-to-docx
23
23
  ```
24
24
 
25
+ ### TypeScript Support
26
+
27
+ This package includes TypeScript typings. No additional installation is required to use it with TypeScript projects.
28
+
29
+ ### TypeScript Example
30
+
31
+ ```typescript
32
+ import HtmlToDocx from "@turbodocx/html-to-docx";
33
+
34
+ const htmlString = `<!DOCTYPE html>
35
+ <html lang="en">
36
+ <head>
37
+ <meta charset="UTF-8" />
38
+ <title>Document</title>
39
+ </head>
40
+ <body>
41
+ <h1>Hello world</h1>
42
+ </body>
43
+ </html>`;
44
+
45
+ // Basic usage
46
+ async function basicExample() {
47
+ const docx = await HtmlToDocx(htmlString);
48
+ // docx is ArrayBuffer in Node.js or Blob in browser environments
49
+ }
50
+
51
+ // With header
52
+ async function withHeader() {
53
+ const headerHtml = "<p>Document Header</p>";
54
+ const docx = await HtmlToDocx(htmlString, headerHtml);
55
+ }
56
+
57
+ // With document options
58
+ async function withOptions() {
59
+ const docx = await HtmlToDocx(htmlString, null, {
60
+ orientation: "landscape",
61
+ title: "TypeScript Example",
62
+ creator: "TurboDocx",
63
+ table: {
64
+ row: {
65
+ cantSplit: true,
66
+ },
67
+ borderOptions: {
68
+ size: 1,
69
+ color: "000000"
70
+ }
71
+ },
72
+ pageNumber: true,
73
+ footer: true
74
+ });
75
+ }
76
+
77
+ // With all parameters
78
+ async function complete() {
79
+ const headerHtml = "<p>Document Header</p>";
80
+ const footerHtml = "<p>Page Footer</p>";
81
+
82
+ const docx = await HtmlToDocx(
83
+ htmlString,
84
+ headerHtml,
85
+ {
86
+ orientation: "landscape",
87
+ pageSize: {
88
+ width: 12240,
89
+ height: 15840
90
+ },
91
+ margins: {
92
+ top: 1440,
93
+ right: 1800,
94
+ bottom: 1440,
95
+ left: 1800
96
+ },
97
+ title: "Complete Example",
98
+ creator: "TurboDocx",
99
+ },
100
+ footerHtml
101
+ );
102
+ }
103
+ ```
104
+
105
+ For more comprehensive TypeScript examples, check out the following files in the `example/typescript` directory:
106
+
107
+ - `typescript-example.ts` - A complete example showing how to generate and save DOCX files using TypeScript
108
+ - `type-test.ts` - Demonstrates the type checking capabilities provided by the TypeScript definitions
109
+
110
+ ### Running the TypeScript Examples
111
+
112
+ To run the TypeScript examples:
113
+
114
+ ```bash
115
+ # Navigate to the example directory
116
+ cd example/typescript
117
+
118
+ # Install ts-node globally (if not already installed)
119
+ npm install -g ts-node typescript
120
+
121
+ # Ensure @turbodocx/html-to-docx is built and accessible
122
+ # From the root directory of the project:
123
+ # npm install
124
+ # npm run build
125
+
126
+ # Run the TypeScript example directly
127
+ ts-node typescript-example.ts
128
+ ```
129
+
130
+ This will generate two DOCX files in the `example/typescript` directory:
131
+ - `basic-example.docx` - A simple document with minimal configuration
132
+ - `advanced-example.docx` - A document with headers, footers, and advanced formatting options
133
+
25
134
  ## Usage
26
135
 
27
136
  ```js