documonster 0.0.2 → 0.0.3
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 +41 -44
- package/README_zh.md +39 -39
- package/dist/iife/documonster.archive.iife.js +1 -1
- package/dist/iife/documonster.archive.iife.min.js +1 -1
- package/dist/iife/documonster.csv.iife.js +1 -1
- package/dist/iife/documonster.csv.iife.min.js +1 -1
- package/dist/iife/documonster.excel.iife.js +1 -2
- package/dist/iife/documonster.excel.iife.js.map +1 -1
- package/dist/iife/documonster.excel.iife.min.js +1 -1
- package/dist/iife/documonster.formula.iife.js +1 -1
- package/dist/iife/documonster.formula.iife.min.js +1 -1
- package/dist/iife/documonster.markdown.iife.js +1 -1
- package/dist/iife/documonster.markdown.iife.min.js +1 -1
- package/dist/iife/documonster.pdf.iife.js +1 -1
- package/dist/iife/documonster.pdf.iife.min.js +1 -1
- package/dist/iife/documonster.stream.iife.js +1 -1
- package/dist/iife/documonster.stream.iife.min.js +1 -1
- package/dist/iife/documonster.word.iife.js +1 -1
- package/dist/iife/documonster.word.iife.min.js +1 -1
- package/dist/iife/documonster.xml.iife.js +1 -1
- package/dist/iife/documonster.xml.iife.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ Read, write, and manipulate DOCX files with a full builder, reader, and converte
|
|
|
36
36
|
|
|
37
37
|
### Formula — Excel-Compatible Calculation Engine
|
|
38
38
|
|
|
39
|
-
Standalone 433-function calculation engine with tokenizer, parser, dependency graph, dynamic-array spill, and `LAMBDA`/`LET`/`MAP`/`REDUCE` support. Ships as a separate subpath so it stays out of bundles that only need to read/write XLSX.
|
|
39
|
+
Standalone 433-function calculation engine with tokenizer, parser, dependency graph, dynamic-array spill, and `LAMBDA`/`LET`/`MAP`/`REDUCE` support. Ships as a separate subpath so it stays out of bundles that only need to read/write XLSX. A single pure function, `Formula.calculate()`, evaluates any `WorkbookLike` host in place (including a `Workbook` created by the excel module) — the engine itself has zero excel runtime dependencies.
|
|
40
40
|
|
|
41
41
|
- [Documentation](src/modules/formula/README.md) | [中文](src/modules/formula/README_zh.md)
|
|
42
42
|
- [Examples](src/modules/formula/examples/)
|
|
@@ -98,84 +98,80 @@ Each module is available as a standalone subpath export. All subpaths support `b
|
|
|
98
98
|
## Quick Start
|
|
99
99
|
|
|
100
100
|
```typescript
|
|
101
|
-
import { Workbook } from "documonster";
|
|
101
|
+
import { Workbook, Worksheet, Row } from "documonster/excel";
|
|
102
102
|
|
|
103
103
|
// Create
|
|
104
|
-
const workbook =
|
|
105
|
-
const sheet =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
await
|
|
104
|
+
const workbook = Workbook.create();
|
|
105
|
+
const sheet = Workbook.addWorksheet(workbook, "Sheet1");
|
|
106
|
+
Worksheet.addRow(sheet, ["Name", "Age"]);
|
|
107
|
+
Worksheet.addRow(sheet, ["Alice", 30]);
|
|
108
|
+
await Workbook.writeFile(workbook, "output.xlsx");
|
|
109
109
|
|
|
110
110
|
// Read
|
|
111
|
-
const wb =
|
|
112
|
-
await
|
|
113
|
-
|
|
111
|
+
const wb = Workbook.create();
|
|
112
|
+
await Workbook.readFile(wb, "output.xlsx");
|
|
113
|
+
const readSheet = Workbook.getWorksheet(wb, 1);
|
|
114
|
+
Worksheet.eachRow(readSheet, (_row, n) => console.log(n, Row.getValues(readSheet, n)));
|
|
114
115
|
|
|
115
116
|
// PDF — generate from data, no Workbook needed
|
|
116
|
-
import {
|
|
117
|
-
const pdfBytes = await
|
|
117
|
+
import { Pdf } from "documonster/pdf";
|
|
118
|
+
const pdfBytes = await Pdf.create([
|
|
118
119
|
["Product", "Revenue"],
|
|
119
120
|
["Widget", 1000]
|
|
120
121
|
]);
|
|
121
122
|
|
|
122
123
|
// PDF — read text, images, and metadata from any PDF
|
|
123
|
-
|
|
124
|
-
const result = await readPdf(pdfBytes);
|
|
124
|
+
const result = await Pdf.read(pdfBytes);
|
|
125
125
|
console.log(result.text); // extracted text
|
|
126
126
|
console.log(result.metadata); // title, author, etc.
|
|
127
127
|
|
|
128
128
|
// PDF — build free-form PDFs with text, shapes, SVG paths
|
|
129
|
-
|
|
130
|
-
const doc = new PdfDocumentBuilder();
|
|
129
|
+
const doc = new Pdf.Builder();
|
|
131
130
|
const page = doc.addPage();
|
|
132
131
|
page.drawText("Hello!", { x: 72, y: 770, fontSize: 24 });
|
|
133
132
|
page.drawSvgPath("M10 10 L90 10 L50 80 Z", { fill: { r: 1, g: 0, b: 0 } });
|
|
134
133
|
page.addAnnotation({ type: "Highlight", rect: [72, 765, 150, 785] });
|
|
135
134
|
|
|
136
135
|
// PDF — edit existing PDFs (overlay, merge, fill forms)
|
|
137
|
-
|
|
138
|
-
const editor = PdfEditor.load(existingPdf);
|
|
136
|
+
const editor = Pdf.Editor.load(existingPdf);
|
|
139
137
|
editor.getPage(0).drawText("Stamp", { x: 200, y: 400, fontSize: 36 });
|
|
140
138
|
editor.setFormField("name", "Jane");
|
|
141
139
|
editor.copyPagesFrom(otherPdf);
|
|
142
140
|
|
|
143
141
|
// CSV — parse and format
|
|
144
|
-
import {
|
|
145
|
-
const rows =
|
|
146
|
-
const csv =
|
|
142
|
+
import { Csv } from "documonster/csv";
|
|
143
|
+
const rows = Csv.parse("name,age\nAlice,30", { headers: true });
|
|
144
|
+
const csv = Csv.format([{ name: "Bob", age: 25 }], { headers: true });
|
|
147
145
|
|
|
148
146
|
// XML — parse, query, write
|
|
149
|
-
import {
|
|
150
|
-
const titles = queryAll(
|
|
147
|
+
import { Xml } from "documonster/xml";
|
|
148
|
+
const titles = Xml.queryAll(Xml.parse(xmlString).root, "book/title");
|
|
151
149
|
|
|
152
150
|
// ZIP — create and extract
|
|
153
|
-
import {
|
|
154
|
-
const archive = await zip().add("hello.txt", "Hello!").bytes();
|
|
151
|
+
import { Archive } from "documonster/archive";
|
|
152
|
+
const archive = await Archive.zip().add("hello.txt", "Hello!").bytes();
|
|
155
153
|
|
|
156
154
|
// Markdown — parse and format tables
|
|
157
|
-
import {
|
|
158
|
-
const table =
|
|
155
|
+
import { Markdown } from "documonster/markdown";
|
|
156
|
+
const table = Markdown.parse("| A | B |\n|---|---|\n| 1 | 2 |");
|
|
159
157
|
|
|
160
158
|
// Word — create, read, and convert DOCX
|
|
161
|
-
import { Document,
|
|
159
|
+
import { Document, Io } from "documonster/word";
|
|
162
160
|
const wdoc = Document.create();
|
|
163
161
|
Document.addHeading(wdoc, "Report", 1);
|
|
164
162
|
Document.addParagraph(wdoc, "Generated by Documonster.");
|
|
165
|
-
const docxBytes = await toBuffer(Document.build(wdoc));
|
|
166
|
-
const parsedDocx = await
|
|
163
|
+
const docxBytes = await Io.toBuffer(Document.build(wdoc));
|
|
164
|
+
const parsedDocx = await Io.read(docxBytes); // round-trip read
|
|
167
165
|
|
|
168
166
|
// Formula — opt-in calculation engine (kept out of the base bundle)
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
import {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
import { calculateFormulas } from "documonster/formula";
|
|
178
|
-
calculateFormulas(anyWorkbookLikeObject);
|
|
167
|
+
// Pure function: populates cell results on any WorkbookLike object.
|
|
168
|
+
import { Formula } from "documonster/formula";
|
|
169
|
+
import { Cell } from "documonster/excel";
|
|
170
|
+
Cell.setValue(sheet, "A4", { formula: "SUM(A1:A3)" });
|
|
171
|
+
Formula.calculate(workbook); // now populates cell results
|
|
172
|
+
|
|
173
|
+
// Also works standalone on any WorkbookLike object
|
|
174
|
+
Formula.calculate(anyWorkbookLikeObject);
|
|
179
175
|
```
|
|
180
176
|
|
|
181
177
|
## Browser Support
|
|
@@ -184,8 +180,10 @@ Documonster has native browser support with **zero configuration** for modern bu
|
|
|
184
180
|
|
|
185
181
|
```typescript
|
|
186
182
|
// Bundlers (Vite, Webpack, Rollup, esbuild) — just import
|
|
187
|
-
import { Workbook } from "documonster";
|
|
188
|
-
const
|
|
183
|
+
import { Workbook } from "documonster/excel";
|
|
184
|
+
const wb = Workbook.create();
|
|
185
|
+
Workbook.addWorksheet(wb, "S1");
|
|
186
|
+
const buffer = await Workbook.toBuffer(wb);
|
|
189
187
|
```
|
|
190
188
|
|
|
191
189
|
```html
|
|
@@ -194,8 +192,7 @@ const buffer = await new Workbook().addWorksheet("S1").workbook.xlsx.writeBuffer
|
|
|
194
192
|
```
|
|
195
193
|
|
|
196
194
|
> The IIFE bundle does not include the formula calculation engine. Use
|
|
197
|
-
> ESM + `documonster/formula` if you need
|
|
198
|
-
> `Workbook.calculateFormulas()`.
|
|
195
|
+
> ESM + `documonster/formula` if you need `Formula.calculate()`.
|
|
199
196
|
|
|
200
197
|
For older browsers without native `CompressionStream` API, Documonster automatically uses a built-in pure JavaScript DEFLATE implementation — no polyfills needed.
|
|
201
198
|
|
package/README_zh.md
CHANGED
|
@@ -36,7 +36,7 @@ Documonster 由九个独立模块组成,每个模块都有自己的文档和可
|
|
|
36
36
|
|
|
37
37
|
### Formula — Excel 兼容公式引擎
|
|
38
38
|
|
|
39
|
-
独立的 433 函数计算引擎,包含 tokenizer、parser、依赖图、动态数组 spill,支持 `LAMBDA`/`LET`/`MAP`/`REDUCE`。作为单独的 subpath 发布,不会被打进只读写 XLSX 的 bundle
|
|
39
|
+
独立的 433 函数计算引擎,包含 tokenizer、parser、依赖图、动态数组 spill,支持 `LAMBDA`/`LET`/`MAP`/`REDUCE`。作为单独的 subpath 发布,不会被打进只读写 XLSX 的 bundle。仅需一个纯函数 `Formula.calculate()` 即可就地对任意 `WorkbookLike` 宿主(包括 excel 模块创建的 `Workbook`)求值 — 引擎本身**零 excel 运行时依赖**。
|
|
40
40
|
|
|
41
41
|
- [文档](src/modules/formula/README.md) | [中文](src/modules/formula/README_zh.md)
|
|
42
42
|
- [示例](src/modules/formula/examples/)
|
|
@@ -98,69 +98,67 @@ bun add documonster
|
|
|
98
98
|
## 快速开始
|
|
99
99
|
|
|
100
100
|
```typescript
|
|
101
|
-
import { Workbook } from "documonster";
|
|
101
|
+
import { Workbook, Worksheet, Row } from "documonster/excel";
|
|
102
102
|
|
|
103
103
|
// 创建
|
|
104
|
-
const workbook =
|
|
105
|
-
const sheet =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
await
|
|
104
|
+
const workbook = Workbook.create();
|
|
105
|
+
const sheet = Workbook.addWorksheet(workbook, "Sheet1");
|
|
106
|
+
Worksheet.addRow(sheet, ["姓名", "年龄"]);
|
|
107
|
+
Worksheet.addRow(sheet, ["Alice", 30]);
|
|
108
|
+
await Workbook.writeFile(workbook, "output.xlsx");
|
|
109
109
|
|
|
110
110
|
// 读取
|
|
111
|
-
const wb =
|
|
112
|
-
await
|
|
113
|
-
|
|
111
|
+
const wb = Workbook.create();
|
|
112
|
+
await Workbook.readFile(wb, "output.xlsx");
|
|
113
|
+
const readSheet = Workbook.getWorksheet(wb, 1);
|
|
114
|
+
Worksheet.eachRow(readSheet, (_row, n) => console.log(n, Row.getValues(readSheet, n)));
|
|
114
115
|
|
|
115
116
|
// PDF — 直接从数据生成,无需 Workbook
|
|
116
|
-
import {
|
|
117
|
-
const pdfBytes = await
|
|
117
|
+
import { Pdf } from "documonster/pdf";
|
|
118
|
+
const pdfBytes = await Pdf.create([
|
|
118
119
|
["产品", "收入"],
|
|
119
120
|
["小工具", 1000]
|
|
120
121
|
]);
|
|
121
122
|
|
|
122
123
|
// PDF — 读取任意 PDF 的文本、图片和元数据
|
|
123
|
-
|
|
124
|
-
const result = await readPdf(pdfBytes);
|
|
124
|
+
const result = await Pdf.read(pdfBytes);
|
|
125
125
|
console.log(result.text); // 提取的文本
|
|
126
126
|
console.log(result.metadata); // 标题、作者等
|
|
127
127
|
|
|
128
128
|
// CSV — 解析和格式化
|
|
129
|
-
import {
|
|
130
|
-
const rows =
|
|
131
|
-
const csv =
|
|
129
|
+
import { Csv } from "documonster/csv";
|
|
130
|
+
const rows = Csv.parse("name,age\nAlice,30", { headers: true });
|
|
131
|
+
const csv = Csv.format([{ name: "Bob", age: 25 }], { headers: true });
|
|
132
132
|
|
|
133
133
|
// XML — 解析、查询、写入
|
|
134
|
-
import {
|
|
135
|
-
const titles = queryAll(
|
|
134
|
+
import { Xml } from "documonster/xml";
|
|
135
|
+
const titles = Xml.queryAll(Xml.parse(xmlString).root, "book/title");
|
|
136
136
|
|
|
137
137
|
// ZIP — 创建和解压
|
|
138
|
-
import {
|
|
139
|
-
const archive = await zip().add("hello.txt", "Hello!").bytes();
|
|
138
|
+
import { Archive } from "documonster/archive";
|
|
139
|
+
const archive = await Archive.zip().add("hello.txt", "Hello!").bytes();
|
|
140
140
|
|
|
141
141
|
// Markdown — 解析和格式化表格
|
|
142
|
-
import {
|
|
143
|
-
const table =
|
|
142
|
+
import { Markdown } from "documonster/markdown";
|
|
143
|
+
const table = Markdown.parse("| A | B |\n|---|---|\n| 1 | 2 |");
|
|
144
144
|
|
|
145
145
|
// Word — 创建、读取和转换 DOCX
|
|
146
|
-
import { Document,
|
|
146
|
+
import { Document, Io } from "documonster/word";
|
|
147
147
|
const wdoc = Document.create();
|
|
148
148
|
Document.addHeading(wdoc, "报告", 1);
|
|
149
149
|
Document.addParagraph(wdoc, "由 Documonster 生成。");
|
|
150
|
-
const docxBytes = await toBuffer(Document.build(wdoc));
|
|
151
|
-
const parsedDocx = await
|
|
150
|
+
const docxBytes = await Io.toBuffer(Document.build(wdoc));
|
|
151
|
+
const parsedDocx = await Io.read(docxBytes); // 往返读取
|
|
152
152
|
|
|
153
153
|
// Formula — 可选的公式引擎(默认不打进主 bundle)
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
import {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
import { calculateFormulas } from "documonster/formula";
|
|
163
|
-
calculateFormulas(anyWorkbookLikeObject);
|
|
154
|
+
// 纯函数:为任意 WorkbookLike 对象填充单元格计算结果。
|
|
155
|
+
import { Formula } from "documonster/formula";
|
|
156
|
+
import { Cell } from "documonster/excel";
|
|
157
|
+
Cell.setValue(sheet, "A4", { formula: "SUM(A1:A3)" });
|
|
158
|
+
Formula.calculate(workbook); // 现在能填充单元格计算结果了
|
|
159
|
+
|
|
160
|
+
// 同样可单独作用于任意 WorkbookLike 对象
|
|
161
|
+
Formula.calculate(anyWorkbookLikeObject);
|
|
164
162
|
```
|
|
165
163
|
|
|
166
164
|
## 浏览器支持
|
|
@@ -169,8 +167,10 @@ Documonster 原生支持浏览器,现代打包工具**零配置**即可使用
|
|
|
169
167
|
|
|
170
168
|
```typescript
|
|
171
169
|
// 打包工具(Vite、Webpack、Rollup、esbuild)— 直接导入
|
|
172
|
-
import { Workbook } from "documonster";
|
|
173
|
-
const
|
|
170
|
+
import { Workbook } from "documonster/excel";
|
|
171
|
+
const wb = Workbook.create();
|
|
172
|
+
Workbook.addWorksheet(wb, "S1");
|
|
173
|
+
const buffer = await Workbook.toBuffer(wb);
|
|
174
174
|
```
|
|
175
175
|
|
|
176
176
|
```html
|
|
@@ -179,7 +179,7 @@ const buffer = await new Workbook().addWorksheet("S1").workbook.xlsx.writeBuffer
|
|
|
179
179
|
```
|
|
180
180
|
|
|
181
181
|
> IIFE 打包产物不包含公式计算引擎。如果需要调用
|
|
182
|
-
> `
|
|
182
|
+
> `Formula.calculate()`,请改用 ESM + 导入
|
|
183
183
|
> `documonster/formula`。
|
|
184
184
|
|
|
185
185
|
对于不支持原生 `CompressionStream` API 的旧版浏览器,Documonster 自动使用内置的纯 JavaScript DEFLATE 实现 — 无需 polyfill。
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* documonster v0.0.
|
|
2
|
+
* documonster v0.0.3
|
|
3
3
|
* Zero-dependency TypeScript toolkit for Excel, Word, PDF, CSV, Markdown, XML & ZIP — one API across Node.js, Bun & browsers.
|
|
4
4
|
* (c) 2026 cjnoname
|
|
5
5
|
* Released under the Apache-2.0 License
|
|
@@ -44874,7 +44874,6 @@ self.onmessage = async function(event) {
|
|
|
44874
44874
|
var WRITE_AFTER_END_ERROR, AsyncStreamCodec, BufferedCodec;
|
|
44875
44875
|
var init_streaming_compress_browser = __esmMin((() => {
|
|
44876
44876
|
init_compress_base();
|
|
44877
|
-
init_compress_browser();
|
|
44878
44877
|
init_deflate_fallback();
|
|
44879
44878
|
init_index_browser();
|
|
44880
44879
|
init_defaults();
|