office-open 0.6.9 → 0.7.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 ADDED
@@ -0,0 +1,134 @@
1
+ # office-open
2
+
3
+ ![npm version](https://img.shields.io/npm/v/office-open)
4
+ ![npm downloads](https://img.shields.io/npm/dw/office-open)
5
+ ![npm license](https://img.shields.io/npm/l/office-open)
6
+
7
+ > Umbrella package for Office Open XML — all packages, CLI, AI SDK tools, and Zod schemas in one install.
8
+
9
+ ## Features
10
+
11
+ - **Unified Re-exports** — Import from `office-open/docx`, `office-open/pptx`, `office-open/xlsx`
12
+ - **CLI** — Generate files from JSON via `npx office-open`
13
+ - **AI SDK Tools** — Vercel AI SDK compatible tools for `generate-docx`, `generate-pptx`, `generate-xlsx`
14
+ - **Zod Schemas** — Input validation for all document types
15
+ - **Generate Function** — Type-agnostic `generate()` for dynamic document creation
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ # Install with npm
21
+ $ npm install office-open
22
+
23
+ # Install with pnpm
24
+ $ pnpm add office-open
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ### Generate from JSON
30
+
31
+ ```typescript
32
+ import { generate, generateToFile } from "office-open/generate";
33
+
34
+ const buffer = await generate({
35
+ type: "docx",
36
+ options: {
37
+ sections: [
38
+ {
39
+ children: [{ paragraph: "Hello World" }],
40
+ },
41
+ ],
42
+ },
43
+ outputType: "nodebuffer",
44
+ });
45
+ ```
46
+
47
+ ### CLI
48
+
49
+ ```bash
50
+ # Generate from a JSON file
51
+ npx office-open docx document.json "output.docx"
52
+ npx office-open pptx slides.json "output.pptx"
53
+ npx office-open xlsx spreadsheet.json "output.xlsx"
54
+ ```
55
+
56
+ ### AI SDK Tools
57
+
58
+ ```typescript
59
+ import { officeOpenTools } from "office-open/ai";
60
+
61
+ // Use with Vercel AI SDK
62
+ const result = await generateText({
63
+ model,
64
+ tools: officeOpenTools,
65
+ prompt: "Create a sales report as a .docx file",
66
+ });
67
+ ```
68
+
69
+ ### Zod Schemas
70
+
71
+ ```typescript
72
+ import { validateDocumentInput } from "office-open/schemas";
73
+
74
+ try {
75
+ const validated = validateDocumentInput("docx", userInput);
76
+ } catch (e) {
77
+ // Structured validation error with path and message
78
+ }
79
+ ```
80
+
81
+ ### Import from Sub-Packages
82
+
83
+ ```typescript
84
+ import { Document, Packer } from "office-open/docx";
85
+ import { Presentation, Packer } from "office-open/pptx";
86
+ import { Workbook, Packer } from "office-open/xlsx";
87
+ import { convertInchesToTwip } from "office-open/core";
88
+ import { xml2js, js2xml } from "office-open/xml";
89
+ ```
90
+
91
+ ## Sub-Exports
92
+
93
+ | Export Path | Description |
94
+ | ---------------------- | ---------------------------------------- |
95
+ | `office-open` | Main entry (re-exports all sub-packages) |
96
+ | `office-open/docx` | @office-open/docx |
97
+ | `office-open/pptx` | @office-open/pptx |
98
+ | `office-open/xlsx` | @office-open/xlsx |
99
+ | `office-open/core` | @office-open/core |
100
+ | `office-open/xml` | @office-open/xml |
101
+ | `office-open/generate` | `generate()` function |
102
+ | `office-open/ai` | Vercel AI SDK tools |
103
+ | `office-open/schemas` | Zod validation schemas |
104
+
105
+ ## JSON Document Structures
106
+
107
+ ### DOCX
108
+
109
+ ```json
110
+ {
111
+ "sections": [{ "children": [{ "paragraph": "Hello World" }] }]
112
+ }
113
+ ```
114
+
115
+ ### PPTX
116
+
117
+ ```json
118
+ {
119
+ "title": "My Deck",
120
+ "slides": [{ "children": [{ "shape": { "textBody": { "text": "Hello" } } }] }]
121
+ }
122
+ ```
123
+
124
+ ### XLSX
125
+
126
+ ```json
127
+ {
128
+ "worksheets": [{ "rows": [{ "cells": [{ "value": "Name" }, { "value": 95 }] }] }]
129
+ }
130
+ ```
131
+
132
+ ## License
133
+
134
+ MIT