md-spreadsheet-parser 1.2.0 → 1.2.2
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.ja.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# md-spreadsheet-parser (NPM)
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://img.shields.io/badge/wasm-powered-purple.svg" alt="WASM Powered" />
|
|
5
|
+
<a href="https://github.com/f-y/md-spreadsheet-parser/blob/main/LICENSE">
|
|
6
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" />
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/md-spreadsheet-parser">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/md-spreadsheet-parser.svg" alt="npm" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://pypi.org/project/md-spreadsheet-parser/">
|
|
12
|
+
<img src="https://img.shields.io/pypi/v/md-spreadsheet-parser.svg" alt="PyPI" />
|
|
13
|
+
</a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
**md-spreadsheet-parser** は、Node.js用の堅牢なMarkdownテーブルパーサーおよび操作ライブラリです。
|
|
17
|
+
[Pythonコア](https://github.com/f-y/md-spreadsheet-parser) をWebAssemblyにコンパイルして使用しており、Node.jsでネイティブに動作します。
|
|
18
|
+
|
|
19
|
+
> **🎉 公式GUIエディタが登場: [PengSheets](https://marketplace.visualstudio.com/items?itemName=f-y.peng-sheets)**
|
|
20
|
+
>
|
|
21
|
+
> このライブラリのパワーをそのままに、VS Code上でExcelライクな操作感を実現しました。ソート、フィルタ、快適なナビゲーションなどをGUIで直感的に扱えます。
|
|
22
|
+
>
|
|
23
|
+
> [](https://marketplace.visualstudio.com/items?itemName=f-y.peng-sheets)
|
|
24
|
+
|
|
25
|
+
## 機能
|
|
26
|
+
|
|
27
|
+
- **🚀 高パフォーマンス**: プリコンパイルされたWASMバイナリ(約160msで初期化)。
|
|
28
|
+
- **💪 堅牢な解析**: GFMテーブル、列の欠落、エスケープされたパイプを正しく処理します。
|
|
29
|
+
- **🛠️ スプレッドシート操作**: セルの編集、行の追加/削除、Markdownの再生成をプログラムで行えます。
|
|
30
|
+
- **🛡️ 型安全な検証**: スキーマ(Plain Object または Zod)に対してテーブルデータを検証します。
|
|
31
|
+
- **📂 ファイルシステムサポート**: 直接ファイルを読み込む機能を提供します。
|
|
32
|
+
|
|
33
|
+
## インストール
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install md-spreadsheet-parser
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 使い方ガイド
|
|
40
|
+
|
|
41
|
+
### 1. 基本的な解析 (文字列)
|
|
42
|
+
|
|
43
|
+
Markdownテーブルの文字列を構造化された `Table` オブジェクトに解析します。
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
import { parseTable } from 'md-spreadsheet-parser';
|
|
47
|
+
|
|
48
|
+
const markdown = `
|
|
49
|
+
| Name | Age |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| Alice | 30 |
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
const table = parseTable(markdown);
|
|
55
|
+
console.log(table.rows); // [ [ 'Alice', '30' ] ]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2. ファイルシステムの使用
|
|
59
|
+
|
|
60
|
+
文字列に読み込むことなく、ファイルを直接解析できます。
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import { parseWorkbookFromFile, scanTablesFromFile } from 'md-spreadsheet-parser';
|
|
64
|
+
|
|
65
|
+
// ワークブック全体(複数のシート)を解析
|
|
66
|
+
const workbook = parseWorkbookFromFile('./data.md');
|
|
67
|
+
console.log(`Parsed ${workbook.sheets.length} sheets`);
|
|
68
|
+
|
|
69
|
+
// Lookup APIを使用して内容を検証
|
|
70
|
+
const sheet = workbook.getSheet('Sheet1');
|
|
71
|
+
if (sheet) {
|
|
72
|
+
const table = sheet.getTable(0); // 最初のテーブルを取得
|
|
73
|
+
console.log(table.headers);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// または、ファイル内のすべてのテーブルをスキャン
|
|
77
|
+
const tables = scanTablesFromFile('./readme.md');
|
|
78
|
+
console.log(`Found ${tables.length} tables`);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 3. プログラムによる編集
|
|
82
|
+
|
|
83
|
+
テーブルオブジェクトは可変です(内部的にはCoWのような動作)。変更してMarkdownにエクスポートし直すことができます。
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
import { parseTable } from 'md-spreadsheet-parser';
|
|
87
|
+
|
|
88
|
+
const table = parseTable("| Item | Price |\n|---|---|\n| Apple | 100 |");
|
|
89
|
+
|
|
90
|
+
// セルを更新 (行 0, 列 1)
|
|
91
|
+
table.updateCell(0, 1, "150");
|
|
92
|
+
|
|
93
|
+
// Markdownに戻す
|
|
94
|
+
console.log(table.toMarkdown());
|
|
95
|
+
// | Item | Price |
|
|
96
|
+
// | --- | --- |
|
|
97
|
+
// | Apple | 150 |
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 4. 型安全な検証 (toModels)
|
|
101
|
+
|
|
102
|
+
文字列ベースのテーブルデータを、型付きオブジェクトに変換できます。
|
|
103
|
+
|
|
104
|
+
#### 基本的な使用法 (Plain Object Schema)
|
|
105
|
+
コンバータ関数を持つ単純なスキーマオブジェクトを提供できます。
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
const markdown = `
|
|
109
|
+
| id | active |
|
|
110
|
+
| -- | ------ |
|
|
111
|
+
| 1 | yes |
|
|
112
|
+
`;
|
|
113
|
+
const table = parseTable(markdown);
|
|
114
|
+
|
|
115
|
+
// スキーマ定義
|
|
116
|
+
const UserSchema = {
|
|
117
|
+
id: (val) => Number(val),
|
|
118
|
+
active: (val) => val === 'yes'
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const users = table.toModels(UserSchema);
|
|
122
|
+
console.log(users);
|
|
123
|
+
// [ { id: 1, active: true } ]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### 高度な使用法 (Zod)
|
|
127
|
+
より堅牢な検証には、[Zod](https://zod.dev/) を使用してください。
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
import { z } from 'zod';
|
|
131
|
+
|
|
132
|
+
const UserZodSchema = z.object({
|
|
133
|
+
id: z.coerce.number(),
|
|
134
|
+
active: z.string().transform(v => v === 'yes')
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const users = table.toModels(UserZodSchema);
|
|
138
|
+
// [ { id: 1, active: true } ]
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## API ドキュメント
|
|
142
|
+
|
|
143
|
+
このパッケージはPythonコアの直接的なラッパーであるため、基本的な概念は同一です。APIの命名規則はJavaScript用に(snake_caseではなくcamelCaseに)適合されています。
|
|
144
|
+
|
|
145
|
+
- **コアドキュメント**: [Python ユーザーガイド](https://github.com/f-y/md-spreadsheet-parser/blob/main/README.ja.md#使い方)
|
|
146
|
+
- **クックブック**: [一般的なレシピ (日本語)](https://github.com/f-y/md-spreadsheet-parser/blob/main/COOKBOOK.ja.md)
|
|
147
|
+
|
|
148
|
+
### 主な関数の対応
|
|
149
|
+
|
|
150
|
+
| Python (Core) | JavaScript (NPM) | 説明 |
|
|
151
|
+
|---|---|---|
|
|
152
|
+
| `parse_table(md)` | `parseTable(md)` | 単一のテーブル文字列を解析 |
|
|
153
|
+
| `parse_workbook(md)` | `parseWorkbook(md)` | ワークブック全体の文字列を解析 |
|
|
154
|
+
| `scan_tables(md)` | `scanTables(md)` | 文字列からすべてのテーブルを抽出 |
|
|
155
|
+
| `parse_workbook_from_file(path)` | `parseWorkbookFromFile(path)` | ファイルをワークブックに解析 |
|
|
156
|
+
| `scan_tables_from_file(path)` | `scanTablesFromFile(path)` | ファイルからテーブルを抽出 |
|
|
157
|
+
| `Table.to_markdown()` | `Table.toMarkdown()` | Markdownを生成 |
|
|
158
|
+
| `Table.update_cell(r, c, v)` | `Table.updateCell(r, c, v)` | 特定のセルを更新 |
|
|
159
|
+
| `Table.to_models(schema)` | `Table.toModels(schema)` | 型付きオブジェクトに変換 |
|
|
160
|
+
| `Workbook.get_sheet(name)` | `Workbook.getSheet(name)` | 名前でシートを取得 |
|
|
161
|
+
| `Sheet.get_table(index)` | `Sheet.getTable(index)` | インデックスでテーブルを取得 |
|
|
162
|
+
|
|
163
|
+
## 制限事項
|
|
164
|
+
|
|
165
|
+
以下のPython機能は、NPMパッケージでは **利用できません**:
|
|
166
|
+
|
|
167
|
+
| 機能 | 理由 |
|
|
168
|
+
|---------|--------|
|
|
169
|
+
| `parse_excel()` / `parseExcel()` | Excelファイルの解析には `openpyxl` が必要ですが、これはWASMと互換性がありません |
|
|
170
|
+
|
|
171
|
+
Excelファイル操作については、[Pythonパッケージ](https://github.com/f-y/md-spreadsheet-parser) を直接使用するか、COOKBOOKにあるようなテキストベース(CSV/TSV)の操作を使ってください。
|
|
172
|
+
|
|
173
|
+
## アーキテクチャ
|
|
174
|
+
|
|
175
|
+
このパッケージは、PythonライブラリをWASMコンポーネントとしてバンドルするために `componentize-py` を使用しています。
|
|
176
|
+
詳細については、[ARCHITECTURE.md](./ARCHITECTURE.md) を参照してください。
|
|
177
|
+
|
|
178
|
+
## ライセンス
|
|
179
|
+
|
|
180
|
+
MIT
|
package/README.md
CHANGED
|
@@ -5,10 +5,27 @@
|
|
|
5
5
|
<a href="https://github.com/f-y/md-spreadsheet-parser/blob/main/LICENSE">
|
|
6
6
|
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" />
|
|
7
7
|
</a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/md-spreadsheet-parser">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/md-spreadsheet-parser.svg" alt="npm" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://pypi.org/project/md-spreadsheet-parser/">
|
|
12
|
+
<img src="https://img.shields.io/pypi/v/md-spreadsheet-parser.svg" alt="PyPI" />
|
|
13
|
+
</a>
|
|
8
14
|
</p>
|
|
9
15
|
|
|
10
16
|
**md-spreadsheet-parser** is a robust Markdown table parser and manipulator for Node.js.
|
|
11
|
-
It is powered by the [Python Core](https://github.com/f-y/md-spreadsheet-parser) compiled to WebAssembly,
|
|
17
|
+
It is powered by the [Python Core](https://github.com/f-y/md-spreadsheet-parser) compiled to WebAssembly, while running natively in Node.js.
|
|
18
|
+
|
|
19
|
+
> **🎉 Official GUI Editor Released: [PengSheets](https://marketplace.visualstudio.com/items?itemName=f-y.peng-sheets)**
|
|
20
|
+
>
|
|
21
|
+
> We have transformed this library into an Excel-like interface for VS Code. Edit Markdown tables with sort, filter, and easy navigation directly in your editor.
|
|
22
|
+
>
|
|
23
|
+
> [](https://marketplace.visualstudio.com/items?itemName=f-y.peng-sheets)
|
|
24
|
+
|
|
25
|
+
Read in Japanese: 日本語版はこちら(
|
|
26
|
+
<a href="https://github.com/f-y/md-spreadsheet-parser/blob/main/packages/npm/README.ja.md">README</a>
|
|
27
|
+
)
|
|
28
|
+
|
|
12
29
|
|
|
13
30
|
## Features
|
|
14
31
|
|
|
@@ -156,7 +173,7 @@ The following Python features are **not available** in the NPM package:
|
|
|
156
173
|
|---------|--------|
|
|
157
174
|
| `parse_excel()` / `parseExcel()` | Excel file parsing requires `openpyxl`, which is not compatible with WASM |
|
|
158
175
|
|
|
159
|
-
For Excel file operations, use the [Python package](https://github.com/f-y/md-spreadsheet-parser) directly.
|
|
176
|
+
For Excel file operations, use the [Python package](https://github.com/f-y/md-spreadsheet-parser) directly, or use text-based operations (like TSV/CSV) as described in the COOKBOOK.
|
|
160
177
|
|
|
161
178
|
## Architecture
|
|
162
179
|
|
package/dist/parser.core.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|