md-spreadsheet-parser 1.1.10 → 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 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,52 +146,81 @@ 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, conversionSchema);
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 res = _tableToMarkdown(dto, schema);
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) {
162
164
  const dto = this.toDTO();
163
165
  const res = _tableUpdateCell(dto, rowIdx, colIdx, value);
164
- Object.assign(this, res);
166
+ const hydrated = new Table(res);
167
+ Object.assign(this, hydrated);
165
168
  return this;
166
169
  }
167
170
  deleteRow(rowIdx) {
168
171
  const dto = this.toDTO();
169
172
  const res = _tableDeleteRow(dto, rowIdx);
170
- Object.assign(this, res);
173
+ const hydrated = new Table(res);
174
+ Object.assign(this, hydrated);
171
175
  return this;
172
176
  }
173
177
  deleteColumn(colIdx) {
174
178
  const dto = this.toDTO();
175
179
  const res = _tableDeleteColumn(dto, colIdx);
176
- Object.assign(this, res);
180
+ const hydrated = new Table(res);
181
+ Object.assign(this, hydrated);
177
182
  return this;
178
183
  }
179
184
  clearColumnData(colIdx) {
180
185
  const dto = this.toDTO();
181
186
  const res = _tableClearColumnData(dto, colIdx);
182
- Object.assign(this, res);
187
+ const hydrated = new Table(res);
188
+ Object.assign(this, hydrated);
183
189
  return this;
184
190
  }
185
191
  insertRow(rowIdx) {
186
192
  const dto = this.toDTO();
187
193
  const res = _tableInsertRow(dto, rowIdx);
188
- Object.assign(this, res);
194
+ const hydrated = new Table(res);
195
+ Object.assign(this, hydrated);
189
196
  return this;
190
197
  }
191
198
  insertColumn(colIdx) {
192
199
  const dto = this.toDTO();
193
200
  const res = _tableInsertColumn(dto, colIdx);
194
- Object.assign(this, res);
201
+ const hydrated = new Table(res);
202
+ Object.assign(this, hydrated);
203
+ return this;
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);
195
224
  return this;
196
225
  }
197
226
  }
@@ -229,9 +258,46 @@ export class Sheet {
229
258
  }
230
259
  toMarkdown(schema) {
231
260
  const dto = this.toDTO();
232
- const res = _sheetToMarkdown(dto, schema);
261
+ const schemaDto = schema instanceof ParsingSchema ? schema.toDTO() : schema;
262
+ const res = _sheetToMarkdown(dto, schemaDto);
233
263
  return res;
234
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
+ }
235
301
  }
236
302
  export class Workbook {
237
303
  constructor(data) {
@@ -265,19 +331,44 @@ export class Workbook {
265
331
  }
266
332
  toMarkdown(schema) {
267
333
  const dto = this.toDTO();
268
- const res = _workbookToMarkdown(dto, schema);
334
+ const schemaDto = schema instanceof MultiTableParsingSchema ? schema.toDTO() : schema;
335
+ const res = _workbookToMarkdown(dto, schemaDto);
269
336
  return res;
270
337
  }
271
338
  addSheet(name) {
272
339
  const dto = this.toDTO();
273
340
  const res = _workbookAddSheet(dto, name);
274
- Object.assign(this, res);
341
+ const hydrated = new Workbook(res);
342
+ Object.assign(this, hydrated);
275
343
  return this;
276
344
  }
277
345
  deleteSheet(index) {
278
346
  const dto = this.toDTO();
279
347
  const res = _workbookDeleteSheet(dto, index);
280
- Object.assign(this, res);
348
+ const hydrated = new Workbook(res);
349
+ Object.assign(this, hydrated);
350
+ return this;
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);
281
372
  return this;
282
373
  }
283
374
  }
Binary file
Binary file
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;