md-spreadsheet-parser 1.1.11 → 1.2.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 +10 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +88 -5
- package/dist/parser.core.wasm +0 -0
- package/dist/parser.core2.wasm +0 -0
- package/dist/parser.core8.wasm +0 -0
- package/dist/parser.d.ts +11 -0
- package/dist/parser.js +5152 -1083
- package/package.json +2 -2
- package/src/__pycache__/app.cpython-314.pyc +0 -0
- package/src/__pycache__/generated_adapter.cpython-314.pyc +0 -0
- package/src/app.py +62 -0
- package/src/index.ts +99 -5
package/README.md
CHANGED
|
@@ -148,6 +148,16 @@ Since this package is a direct wrapper around the Python core, the fundamental c
|
|
|
148
148
|
| `Workbook.get_sheet(name)` | `Workbook.getSheet(name)` | Get sheet by name |
|
|
149
149
|
| `Sheet.get_table(index)` | `Sheet.getTable(index)` | Get table by index |
|
|
150
150
|
|
|
151
|
+
## Limitations
|
|
152
|
+
|
|
153
|
+
The following Python features are **not available** in the NPM package:
|
|
154
|
+
|
|
155
|
+
| Feature | Reason |
|
|
156
|
+
|---------|--------|
|
|
157
|
+
| `parse_excel()` / `parseExcel()` | Excel file parsing requires `openpyxl`, which is not compatible with WASM |
|
|
158
|
+
|
|
159
|
+
For Excel file operations, use the [Python package](https://github.com/f-y/md-spreadsheet-parser) directly.
|
|
160
|
+
|
|
151
161
|
## Architecture
|
|
152
162
|
|
|
153
163
|
This package uses `componentize-py` to bundle the Python library as a WASM Component.
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,9 @@ export declare class Table {
|
|
|
38
38
|
clearColumnData(colIdx: any): any;
|
|
39
39
|
insertRow(rowIdx: any): any;
|
|
40
40
|
insertColumn(colIdx: any): any;
|
|
41
|
+
rename(newName: any): any;
|
|
42
|
+
moveRow(fromIndex: any, toIndex: any): any;
|
|
43
|
+
moveColumn(fromIndex: any, toIndex: any): any;
|
|
41
44
|
}
|
|
42
45
|
export declare class Sheet {
|
|
43
46
|
name: string | undefined;
|
|
@@ -52,6 +55,11 @@ export declare class Sheet {
|
|
|
52
55
|
get json(): any;
|
|
53
56
|
getTable(name: any): any;
|
|
54
57
|
toMarkdown(schema?: any): any;
|
|
58
|
+
rename(newName: any): any;
|
|
59
|
+
addTable(name?: any): any;
|
|
60
|
+
deleteTable(index: any): any;
|
|
61
|
+
replaceTable(index: any, table: any): any;
|
|
62
|
+
moveTable(fromIndex: any, toIndex: any): any;
|
|
55
63
|
}
|
|
56
64
|
export declare class Workbook {
|
|
57
65
|
sheets: any[] | undefined;
|
|
@@ -67,6 +75,9 @@ export declare class Workbook {
|
|
|
67
75
|
toMarkdown(schema?: any): any;
|
|
68
76
|
addSheet(name: any): any;
|
|
69
77
|
deleteSheet(index: any): any;
|
|
78
|
+
moveSheet(fromIndex: any, toIndex: any): any;
|
|
79
|
+
replaceSheet(index: any, sheet: any): any;
|
|
80
|
+
renameSheet(index: any, newName: any): any;
|
|
70
81
|
}
|
|
71
82
|
export declare class ParsingSchema {
|
|
72
83
|
columnSeparator: string | undefined;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cleanCell as _cleanCell, splitRowGfm as _splitRowGfm, parseRow as _parseRow, parseSeparatorRow as _parseSeparatorRow, isSeparatorRow as _isSeparatorRow, parseTable as _parseTable, parseSheet as _parseSheet, parseWorkbook as _parseWorkbook, scanTables as _scanTables, generateTableMarkdown as _generateTableMarkdown, generateSheetMarkdown as _generateSheetMarkdown, generateWorkbookMarkdown as _generateWorkbookMarkdown, parseTableFromFile as _parseTableFromFile, parseWorkbookFromFile as _parseWorkbookFromFile, scanTablesFromFile as _scanTablesFromFile, scanTablesIter as _scanTablesIter, tableToModels as _tableToModels, tableToMarkdown as _tableToMarkdown, tableUpdateCell as _tableUpdateCell, tableDeleteRow as _tableDeleteRow, tableDeleteColumn as _tableDeleteColumn, tableClearColumnData as _tableClearColumnData, tableInsertRow as _tableInsertRow, tableInsertColumn as _tableInsertColumn, sheetGetTable as _sheetGetTable, sheetToMarkdown as _sheetToMarkdown, workbookGetSheet as _workbookGetSheet, workbookToMarkdown as _workbookToMarkdown, workbookAddSheet as _workbookAddSheet, workbookDeleteSheet as _workbookDeleteSheet } from '../dist/parser.js';
|
|
1
|
+
import { cleanCell as _cleanCell, splitRowGfm as _splitRowGfm, parseRow as _parseRow, parseSeparatorRow as _parseSeparatorRow, isSeparatorRow as _isSeparatorRow, parseTable as _parseTable, parseSheet as _parseSheet, parseWorkbook as _parseWorkbook, scanTables as _scanTables, generateTableMarkdown as _generateTableMarkdown, generateSheetMarkdown as _generateSheetMarkdown, generateWorkbookMarkdown as _generateWorkbookMarkdown, parseTableFromFile as _parseTableFromFile, parseWorkbookFromFile as _parseWorkbookFromFile, scanTablesFromFile as _scanTablesFromFile, scanTablesIter as _scanTablesIter, tableToModels as _tableToModels, tableToMarkdown as _tableToMarkdown, tableUpdateCell as _tableUpdateCell, tableDeleteRow as _tableDeleteRow, tableDeleteColumn as _tableDeleteColumn, tableClearColumnData as _tableClearColumnData, tableInsertRow as _tableInsertRow, tableInsertColumn as _tableInsertColumn, tableRename as _tableRename, tableMoveRow as _tableMoveRow, tableMoveColumn as _tableMoveColumn, sheetGetTable as _sheetGetTable, sheetToMarkdown as _sheetToMarkdown, sheetRename as _sheetRename, sheetAddTable as _sheetAddTable, sheetDeleteTable as _sheetDeleteTable, sheetReplaceTable as _sheetReplaceTable, sheetMoveTable as _sheetMoveTable, workbookGetSheet as _workbookGetSheet, workbookToMarkdown as _workbookToMarkdown, workbookAddSheet as _workbookAddSheet, workbookDeleteSheet as _workbookDeleteSheet, workbookMoveSheet as _workbookMoveSheet, workbookReplaceSheet as _workbookReplaceSheet, workbookRenameSheet as _workbookRenameSheet } from '../dist/parser.js';
|
|
2
2
|
import { clientSideToModels } from './client-adapters.js';
|
|
3
3
|
// Environment detection
|
|
4
4
|
// @ts-ignore - process may not be defined in browser
|
|
@@ -146,16 +146,18 @@ export class Table {
|
|
|
146
146
|
}
|
|
147
147
|
toModels(schemaCls, conversionSchema) {
|
|
148
148
|
const dto = this.toDTO();
|
|
149
|
+
const conversionSchemaDto = conversionSchema instanceof ConversionSchema ? conversionSchema.toDTO() : conversionSchema;
|
|
149
150
|
const clientRes = clientSideToModels(this.headers, this.rows || [], schemaCls);
|
|
150
151
|
if (clientRes) {
|
|
151
152
|
return clientRes;
|
|
152
153
|
}
|
|
153
|
-
const res = _tableToModels(dto, schemaCls,
|
|
154
|
+
const res = _tableToModels(dto, schemaCls, conversionSchemaDto);
|
|
154
155
|
return res.map((x) => JSON.parse(x));
|
|
155
156
|
}
|
|
156
157
|
toMarkdown(schema) {
|
|
157
158
|
const dto = this.toDTO();
|
|
158
|
-
const
|
|
159
|
+
const schemaDto = schema instanceof ParsingSchema ? schema.toDTO() : schema;
|
|
160
|
+
const res = _tableToMarkdown(dto, schemaDto);
|
|
159
161
|
return res;
|
|
160
162
|
}
|
|
161
163
|
updateCell(rowIdx, colIdx, value) {
|
|
@@ -200,6 +202,27 @@ export class Table {
|
|
|
200
202
|
Object.assign(this, hydrated);
|
|
201
203
|
return this;
|
|
202
204
|
}
|
|
205
|
+
rename(newName) {
|
|
206
|
+
const dto = this.toDTO();
|
|
207
|
+
const res = _tableRename(dto, newName);
|
|
208
|
+
const hydrated = new Table(res);
|
|
209
|
+
Object.assign(this, hydrated);
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
moveRow(fromIndex, toIndex) {
|
|
213
|
+
const dto = this.toDTO();
|
|
214
|
+
const res = _tableMoveRow(dto, fromIndex, toIndex);
|
|
215
|
+
const hydrated = new Table(res);
|
|
216
|
+
Object.assign(this, hydrated);
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
moveColumn(fromIndex, toIndex) {
|
|
220
|
+
const dto = this.toDTO();
|
|
221
|
+
const res = _tableMoveColumn(dto, fromIndex, toIndex);
|
|
222
|
+
const hydrated = new Table(res);
|
|
223
|
+
Object.assign(this, hydrated);
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
203
226
|
}
|
|
204
227
|
export class Sheet {
|
|
205
228
|
constructor(data) {
|
|
@@ -235,9 +258,46 @@ export class Sheet {
|
|
|
235
258
|
}
|
|
236
259
|
toMarkdown(schema) {
|
|
237
260
|
const dto = this.toDTO();
|
|
238
|
-
const
|
|
261
|
+
const schemaDto = schema instanceof ParsingSchema ? schema.toDTO() : schema;
|
|
262
|
+
const res = _sheetToMarkdown(dto, schemaDto);
|
|
239
263
|
return res;
|
|
240
264
|
}
|
|
265
|
+
rename(newName) {
|
|
266
|
+
const dto = this.toDTO();
|
|
267
|
+
const res = _sheetRename(dto, newName);
|
|
268
|
+
const hydrated = new Sheet(res);
|
|
269
|
+
Object.assign(this, hydrated);
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
addTable(name) {
|
|
273
|
+
const dto = this.toDTO();
|
|
274
|
+
const res = _sheetAddTable(dto, name);
|
|
275
|
+
const hydrated = new Sheet(res);
|
|
276
|
+
Object.assign(this, hydrated);
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
deleteTable(index) {
|
|
280
|
+
const dto = this.toDTO();
|
|
281
|
+
const res = _sheetDeleteTable(dto, index);
|
|
282
|
+
const hydrated = new Sheet(res);
|
|
283
|
+
Object.assign(this, hydrated);
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
replaceTable(index, table) {
|
|
287
|
+
const dto = this.toDTO();
|
|
288
|
+
const tableDto = table instanceof Table ? table.toDTO() : table;
|
|
289
|
+
const res = _sheetReplaceTable(dto, index, tableDto);
|
|
290
|
+
const hydrated = new Sheet(res);
|
|
291
|
+
Object.assign(this, hydrated);
|
|
292
|
+
return this;
|
|
293
|
+
}
|
|
294
|
+
moveTable(fromIndex, toIndex) {
|
|
295
|
+
const dto = this.toDTO();
|
|
296
|
+
const res = _sheetMoveTable(dto, fromIndex, toIndex);
|
|
297
|
+
const hydrated = new Sheet(res);
|
|
298
|
+
Object.assign(this, hydrated);
|
|
299
|
+
return this;
|
|
300
|
+
}
|
|
241
301
|
}
|
|
242
302
|
export class Workbook {
|
|
243
303
|
constructor(data) {
|
|
@@ -271,7 +331,8 @@ export class Workbook {
|
|
|
271
331
|
}
|
|
272
332
|
toMarkdown(schema) {
|
|
273
333
|
const dto = this.toDTO();
|
|
274
|
-
const
|
|
334
|
+
const schemaDto = schema instanceof MultiTableParsingSchema ? schema.toDTO() : schema;
|
|
335
|
+
const res = _workbookToMarkdown(dto, schemaDto);
|
|
275
336
|
return res;
|
|
276
337
|
}
|
|
277
338
|
addSheet(name) {
|
|
@@ -288,6 +349,28 @@ export class Workbook {
|
|
|
288
349
|
Object.assign(this, hydrated);
|
|
289
350
|
return this;
|
|
290
351
|
}
|
|
352
|
+
moveSheet(fromIndex, toIndex) {
|
|
353
|
+
const dto = this.toDTO();
|
|
354
|
+
const res = _workbookMoveSheet(dto, fromIndex, toIndex);
|
|
355
|
+
const hydrated = new Workbook(res);
|
|
356
|
+
Object.assign(this, hydrated);
|
|
357
|
+
return this;
|
|
358
|
+
}
|
|
359
|
+
replaceSheet(index, sheet) {
|
|
360
|
+
const dto = this.toDTO();
|
|
361
|
+
const sheetDto = sheet instanceof Sheet ? sheet.toDTO() : sheet;
|
|
362
|
+
const res = _workbookReplaceSheet(dto, index, sheetDto);
|
|
363
|
+
const hydrated = new Workbook(res);
|
|
364
|
+
Object.assign(this, hydrated);
|
|
365
|
+
return this;
|
|
366
|
+
}
|
|
367
|
+
renameSheet(index, newName) {
|
|
368
|
+
const dto = this.toDTO();
|
|
369
|
+
const res = _workbookRenameSheet(dto, index, newName);
|
|
370
|
+
const hydrated = new Workbook(res);
|
|
371
|
+
Object.assign(this, hydrated);
|
|
372
|
+
return this;
|
|
373
|
+
}
|
|
291
374
|
}
|
|
292
375
|
export class ParsingSchema {
|
|
293
376
|
constructor(data) {
|
package/dist/parser.core.wasm
CHANGED
|
Binary file
|
package/dist/parser.core2.wasm
CHANGED
|
Binary file
|
package/dist/parser.core8.wasm
CHANGED
|
Binary file
|
package/dist/parser.d.ts
CHANGED
|
@@ -60,9 +60,20 @@ export function tableDeleteColumn(selfObj: Table, colIdx: number): Table;
|
|
|
60
60
|
export function tableClearColumnData(selfObj: Table, colIdx: number): Table;
|
|
61
61
|
export function tableInsertRow(selfObj: Table, rowIdx: number): Table;
|
|
62
62
|
export function tableInsertColumn(selfObj: Table, colIdx: number): Table;
|
|
63
|
+
export function tableRename(selfObj: Table, newName: string): Table;
|
|
64
|
+
export function tableMoveRow(selfObj: Table, fromIndex: number, toIndex: number): Table;
|
|
65
|
+
export function tableMoveColumn(selfObj: Table, fromIndex: number, toIndex: number): Table;
|
|
63
66
|
export function sheetGetTable(selfObj: Sheet, name: string): Table | undefined;
|
|
64
67
|
export function sheetToMarkdown(selfObj: Sheet, schema: ParsingSchema | undefined): string;
|
|
68
|
+
export function sheetRename(selfObj: Sheet, newName: string): Sheet;
|
|
69
|
+
export function sheetAddTable(selfObj: Sheet, name: string | undefined): Sheet;
|
|
70
|
+
export function sheetDeleteTable(selfObj: Sheet, index: number): Sheet;
|
|
71
|
+
export function sheetReplaceTable(selfObj: Sheet, index: number, table: Table): Sheet;
|
|
72
|
+
export function sheetMoveTable(selfObj: Sheet, fromIndex: number, toIndex: number): Sheet;
|
|
65
73
|
export function workbookGetSheet(selfObj: Workbook, name: string): Sheet | undefined;
|
|
66
74
|
export function workbookToMarkdown(selfObj: Workbook, schema: MultiTableParsingSchema | undefined): string;
|
|
67
75
|
export function workbookAddSheet(selfObj: Workbook, name: string): Workbook;
|
|
68
76
|
export function workbookDeleteSheet(selfObj: Workbook, index: number): Workbook;
|
|
77
|
+
export function workbookMoveSheet(selfObj: Workbook, fromIndex: number, toIndex: number): Workbook;
|
|
78
|
+
export function workbookReplaceSheet(selfObj: Workbook, index: number, sheet: Sheet): Workbook;
|
|
79
|
+
export function workbookRenameSheet(selfObj: Workbook, index: number, newName: string): Workbook;
|