@senlinz/import-export-wasm 0.1.0-beta.8 → 0.1.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/LICENSE CHANGED
@@ -1,33 +1,33 @@
1
- MIT License
2
-
3
- Copyright (c) 2024, senlinz
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
23
- ---
24
-
25
- This project includes third-party software licensed under the MIT License and the Apache License 2.0:
26
-
27
- ## rust_xlsxwriter
28
-
29
- MIT License (MIT) or Apache License, Version 2.0
30
-
31
- ## calamine
32
-
1
+ MIT License
2
+
3
+ Copyright (c) 2024, senlinz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ This project includes third-party software licensed under the MIT License and the Apache License 2.0:
26
+
27
+ ## rust_xlsxwriter
28
+
29
+ MIT License (MIT) or Apache License, Version 2.0
30
+
31
+ ## calamine
32
+
33
33
  MIT License
package/README.md CHANGED
@@ -1,13 +1,87 @@
1
- # @senlinz/import-export-wasm
2
- **@senlinz/import-export-wasm** is the Rust WebAssembly core library for the **@senlinz/import-export** library. It provides the core logic for handling Excel data in browser environments.
3
-
4
- > **Note:** This library is currently in beta. Features and APIs may change.
5
-
6
- ## Features
7
- - Rust WebAssembly core for efficient Excel data handling.
8
- - Read using [calamine](https://docs.rs/calamine/).
9
- - Write using [rust_xlsxwriter](https://docs.rs/rust_xlsxwriter/).
10
-
11
- ## Usage
12
- Directly use WebAssembly in browser environments.
13
- [Example](./tests/index.html)
1
+ # @senlinz/import-export-wasm
2
+
3
+ Direct Rust/WebAssembly bindings for importing, exporting, and templating Excel workbooks.
4
+
5
+ [中文文档](./README.zh.md)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @senlinz/import-export-wasm
11
+ ```
12
+
13
+ ## Initialization
14
+
15
+ Build the package and load the generated module in the browser:
16
+
17
+ ```ts
18
+ import init, {
19
+ createTemplate,
20
+ exportData,
21
+ importData,
22
+ ExcelInfo,
23
+ ExcelColumnInfo,
24
+ ExcelData,
25
+ ExcelRowData,
26
+ ExcelColumnData,
27
+ } from '@senlinz/import-export-wasm';
28
+
29
+ await init();
30
+ ```
31
+
32
+ ## Direct WASM usage
33
+
34
+ ```ts
35
+ const info = new ExcelInfo(
36
+ 'TomAndJerry',
37
+ 'sheet1',
38
+ [
39
+ new ExcelColumnInfo('name', 'Name'),
40
+ new ExcelColumnInfo('age', 'Age').withDataType('number'),
41
+ new ExcelColumnInfo('category', 'Category').withAllowedValues(['Cat', 'Mouse']),
42
+ ],
43
+ 'senlinz',
44
+ '2024-11-01T08:00:00',
45
+ );
46
+
47
+ const template = createTemplate(info);
48
+
49
+ const data = new ExcelData([
50
+ new ExcelRowData([
51
+ new ExcelColumnData('name', 'Tom'),
52
+ new ExcelColumnData('age', '12'),
53
+ new ExcelColumnData('category', 'Cat'),
54
+ ]),
55
+ ]);
56
+
57
+ const workbook = await exportData(info, data);
58
+ const imported = importData(info, workbook);
59
+ ```
60
+
61
+ ## Supported schema rules
62
+
63
+ - Column keys must be unique.
64
+ - Header names must be non-empty.
65
+ - Supported `dataType` values are `text`, `number`, `date`, and `image`.
66
+ - Parent columns must be declared before child columns.
67
+ - `dataGroupParent` values must refer to a previously declared `dataGroup`.
68
+
69
+ ## Direct WASM examples
70
+
71
+ - [Browser example](./examples/direct-browser.html)
72
+
73
+ The browser example is covered by Playwright tests in [`./tests/wasm.test.js`](./tests/wasm.test.js).
74
+
75
+ ## Runtime notes
76
+
77
+ - Browser usage requires the generated JS/WASM assets from `wasm-pack build`.
78
+ - Image export requires `.withImageFetcher(...)`.
79
+ - Invalid schemas and invalid exported number/date values now fail with explicit errors.
80
+
81
+ ## Development
82
+
83
+ ```bash
84
+ cargo test --lib
85
+ wasm-pack build --release --target web
86
+ pnpm e2e-test
87
+ ```
package/README.zh.md ADDED
@@ -0,0 +1,87 @@
1
+ # @senlinz/import-export-wasm
2
+
3
+ 用于导入、导出和生成 Excel 工作簿的 Rust / WebAssembly 直接绑定。
4
+
5
+ [English](./README.md)
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pnpm add @senlinz/import-export-wasm
11
+ ```
12
+
13
+ ## 初始化
14
+
15
+ 先构建包,再在浏览器中加载生成的模块:
16
+
17
+ ```ts
18
+ import init, {
19
+ createTemplate,
20
+ exportData,
21
+ importData,
22
+ ExcelInfo,
23
+ ExcelColumnInfo,
24
+ ExcelData,
25
+ ExcelRowData,
26
+ ExcelColumnData,
27
+ } from '@senlinz/import-export-wasm';
28
+
29
+ await init();
30
+ ```
31
+
32
+ ## 直接使用 WASM
33
+
34
+ ```ts
35
+ const info = new ExcelInfo(
36
+ 'TomAndJerry',
37
+ 'sheet1',
38
+ [
39
+ new ExcelColumnInfo('name', 'Name'),
40
+ new ExcelColumnInfo('age', 'Age').withDataType('number'),
41
+ new ExcelColumnInfo('category', 'Category').withAllowedValues(['Cat', 'Mouse']),
42
+ ],
43
+ 'senlinz',
44
+ '2024-11-01T08:00:00',
45
+ );
46
+
47
+ const template = createTemplate(info);
48
+
49
+ const data = new ExcelData([
50
+ new ExcelRowData([
51
+ new ExcelColumnData('name', 'Tom'),
52
+ new ExcelColumnData('age', '12'),
53
+ new ExcelColumnData('category', 'Cat'),
54
+ ]),
55
+ ]);
56
+
57
+ const workbook = await exportData(info, data);
58
+ const imported = importData(info, workbook);
59
+ ```
60
+
61
+ ## 支持的 Schema 规则
62
+
63
+ - 列 key 必须唯一。
64
+ - 表头名称不能为空。
65
+ - `dataType` 仅支持 `text`、`number`、`date`、`image`。
66
+ - 父级列必须先于子级列声明。
67
+ - `dataGroupParent` 必须引用已声明的 `dataGroup`。
68
+
69
+ ## 直接 WASM 示例
70
+
71
+ - [浏览器示例](./examples/direct-browser.html)
72
+
73
+ 该浏览器示例由 [`./tests/wasm.test.js`](./tests/wasm.test.js) 中的 Playwright 用例覆盖。
74
+
75
+ ## 运行时说明
76
+
77
+ - 浏览器使用前需要通过 `wasm-pack build` 生成 JS / WASM 产物。
78
+ - 图片导出需要 `.withImageFetcher(...)`。
79
+ - 非法 schema、非法数字值、非法日期值都会返回明确错误。
80
+
81
+ ## 开发
82
+
83
+ ```bash
84
+ cargo test --lib
85
+ wasm-pack build --release --target web
86
+ pnpm e2e-test
87
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senlinz/import-export-wasm",
3
- "version": "0.1.0-beta.8",
3
+ "version": "0.1.0",
4
4
  "description": "Rust WebAssembly for import/export excel files",
5
5
  "main": "pkg/imexport_wasm.js",
6
6
  "types": "pkg/imexport_wasm.d.ts",
@@ -9,7 +9,8 @@
9
9
  "pkg/imexport_wasm.bg.wasm.d.ts",
10
10
  "pkg/imexport_wasm.js",
11
11
  "pkg/imexport_wasm.d.ts",
12
- "README.md"
12
+ "README.md",
13
+ "README.zh.md"
13
14
  ],
14
15
  "author": "senlin",
15
16
  "license": "MIT",
@@ -34,7 +35,7 @@
34
35
  "build": "wasm-pack build --release --target web",
35
36
  "publish-dry-run": "pnpm publish --dry-run --no-git-checks",
36
37
  "cargo-test": "cargo test --lib",
37
- "e2e-serve": "wasm-pack build --release --target web -d tests/dist && serve -l 8080 ./tests",
38
+ "e2e-serve": "wasm-pack build --release --target web -d tests/dist && serve -l 8080 .",
38
39
  "e2e-test": "playwright test"
39
40
  }
40
41
  }