md-spreadsheet-parser 1.1.11 → 1.2.1
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 +16 -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/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "md-spreadsheet-parser",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "A robust Markdown table parser and manipulator, powered by Python and WebAssembly.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "node scripts/build.mjs",
|
|
10
|
-
"test": "node
|
|
10
|
+
"test": "node tests/runner.mjs"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"dist",
|
|
Binary file
|
|
Binary file
|
package/src/app.py
CHANGED
|
@@ -132,6 +132,23 @@ class WitWorld:
|
|
|
132
132
|
kwargs = {}
|
|
133
133
|
if col_idx is not None: kwargs['col_idx'] = col_idx
|
|
134
134
|
return convert_table(real_self.insert_column(**kwargs))
|
|
135
|
+
def table_rename(self, self_obj: Any, new_name: Any = None):
|
|
136
|
+
real_self = unwrap_table(self_obj)
|
|
137
|
+
kwargs = {}
|
|
138
|
+
if new_name is not None: kwargs['new_name'] = new_name
|
|
139
|
+
return convert_table(real_self.rename(**kwargs))
|
|
140
|
+
def table_move_row(self, self_obj: Any, from_index: Any = None, to_index: Any = None):
|
|
141
|
+
real_self = unwrap_table(self_obj)
|
|
142
|
+
kwargs = {}
|
|
143
|
+
if from_index is not None: kwargs['from_index'] = from_index
|
|
144
|
+
if to_index is not None: kwargs['to_index'] = to_index
|
|
145
|
+
return convert_table(real_self.move_row(**kwargs))
|
|
146
|
+
def table_move_column(self, self_obj: Any, from_index: Any = None, to_index: Any = None):
|
|
147
|
+
real_self = unwrap_table(self_obj)
|
|
148
|
+
kwargs = {}
|
|
149
|
+
if from_index is not None: kwargs['from_index'] = from_index
|
|
150
|
+
if to_index is not None: kwargs['to_index'] = to_index
|
|
151
|
+
return convert_table(real_self.move_column(**kwargs))
|
|
135
152
|
def sheet_get_table(self, self_obj: Any, name: Any = None):
|
|
136
153
|
real_self = unwrap_sheet(self_obj)
|
|
137
154
|
kwargs = {}
|
|
@@ -142,6 +159,33 @@ class WitWorld:
|
|
|
142
159
|
kwargs = {}
|
|
143
160
|
if schema is not None: kwargs['schema'] = unwrap_parsing_schema(schema)
|
|
144
161
|
return real_self.to_markdown(**kwargs)
|
|
162
|
+
def sheet_rename(self, self_obj: Any, new_name: Any = None):
|
|
163
|
+
real_self = unwrap_sheet(self_obj)
|
|
164
|
+
kwargs = {}
|
|
165
|
+
if new_name is not None: kwargs['new_name'] = new_name
|
|
166
|
+
return convert_sheet(real_self.rename(**kwargs))
|
|
167
|
+
def sheet_add_table(self, self_obj: Any, name: Any = None):
|
|
168
|
+
real_self = unwrap_sheet(self_obj)
|
|
169
|
+
kwargs = {}
|
|
170
|
+
if name is not None: kwargs['name'] = name
|
|
171
|
+
return convert_sheet(real_self.add_table(**kwargs))
|
|
172
|
+
def sheet_delete_table(self, self_obj: Any, index: Any = None):
|
|
173
|
+
real_self = unwrap_sheet(self_obj)
|
|
174
|
+
kwargs = {}
|
|
175
|
+
if index is not None: kwargs['index'] = index
|
|
176
|
+
return convert_sheet(real_self.delete_table(**kwargs))
|
|
177
|
+
def sheet_replace_table(self, self_obj: Any, index: Any = None, table: Any = None):
|
|
178
|
+
real_self = unwrap_sheet(self_obj)
|
|
179
|
+
kwargs = {}
|
|
180
|
+
if index is not None: kwargs['index'] = index
|
|
181
|
+
if table is not None: kwargs['table'] = unwrap_table(table)
|
|
182
|
+
return convert_sheet(real_self.replace_table(**kwargs))
|
|
183
|
+
def sheet_move_table(self, self_obj: Any, from_index: Any = None, to_index: Any = None):
|
|
184
|
+
real_self = unwrap_sheet(self_obj)
|
|
185
|
+
kwargs = {}
|
|
186
|
+
if from_index is not None: kwargs['from_index'] = from_index
|
|
187
|
+
if to_index is not None: kwargs['to_index'] = to_index
|
|
188
|
+
return convert_sheet(real_self.move_table(**kwargs))
|
|
145
189
|
def workbook_get_sheet(self, self_obj: Any, name: Any = None):
|
|
146
190
|
real_self = unwrap_workbook(self_obj)
|
|
147
191
|
kwargs = {}
|
|
@@ -162,3 +206,21 @@ class WitWorld:
|
|
|
162
206
|
kwargs = {}
|
|
163
207
|
if index is not None: kwargs['index'] = index
|
|
164
208
|
return convert_workbook(real_self.delete_sheet(**kwargs))
|
|
209
|
+
def workbook_move_sheet(self, self_obj: Any, from_index: Any = None, to_index: Any = None):
|
|
210
|
+
real_self = unwrap_workbook(self_obj)
|
|
211
|
+
kwargs = {}
|
|
212
|
+
if from_index is not None: kwargs['from_index'] = from_index
|
|
213
|
+
if to_index is not None: kwargs['to_index'] = to_index
|
|
214
|
+
return convert_workbook(real_self.move_sheet(**kwargs))
|
|
215
|
+
def workbook_replace_sheet(self, self_obj: Any, index: Any = None, sheet: Any = None):
|
|
216
|
+
real_self = unwrap_workbook(self_obj)
|
|
217
|
+
kwargs = {}
|
|
218
|
+
if index is not None: kwargs['index'] = index
|
|
219
|
+
if sheet is not None: kwargs['sheet'] = unwrap_sheet(sheet)
|
|
220
|
+
return convert_workbook(real_self.replace_sheet(**kwargs))
|
|
221
|
+
def workbook_rename_sheet(self, self_obj: Any, index: Any = None, new_name: Any = None):
|
|
222
|
+
real_self = unwrap_workbook(self_obj)
|
|
223
|
+
kwargs = {}
|
|
224
|
+
if index is not None: kwargs['index'] = index
|
|
225
|
+
if new_name is not None: kwargs['new_name'] = new_name
|
|
226
|
+
return convert_workbook(real_self.rename_sheet(**kwargs))
|
package/src/index.ts
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
|
|
|
4
4
|
// Environment detection
|
|
@@ -182,17 +182,19 @@ export class Table {
|
|
|
182
182
|
|
|
183
183
|
toModels(schemaCls: any, conversionSchema?: any): any {
|
|
184
184
|
const dto = this.toDTO();
|
|
185
|
+
const conversionSchemaDto = conversionSchema instanceof ConversionSchema ? conversionSchema.toDTO() : conversionSchema;
|
|
185
186
|
const clientRes = clientSideToModels(this.headers, this.rows || [], schemaCls);
|
|
186
187
|
if (clientRes) {
|
|
187
188
|
return clientRes;
|
|
188
189
|
}
|
|
189
|
-
const res = _tableToModels(dto, schemaCls,
|
|
190
|
+
const res = _tableToModels(dto, schemaCls, conversionSchemaDto);
|
|
190
191
|
return res.map((x: string) => JSON.parse(x));
|
|
191
192
|
}
|
|
192
193
|
|
|
193
194
|
toMarkdown(schema?: any): any {
|
|
194
195
|
const dto = this.toDTO();
|
|
195
|
-
const
|
|
196
|
+
const schemaDto = schema instanceof ParsingSchema ? schema.toDTO() : schema;
|
|
197
|
+
const res = _tableToMarkdown(dto, schemaDto);
|
|
196
198
|
return res;
|
|
197
199
|
}
|
|
198
200
|
|
|
@@ -243,6 +245,30 @@ export class Table {
|
|
|
243
245
|
Object.assign(this, hydrated);
|
|
244
246
|
return this;
|
|
245
247
|
}
|
|
248
|
+
|
|
249
|
+
rename(newName: any): any {
|
|
250
|
+
const dto = this.toDTO();
|
|
251
|
+
const res = _tableRename(dto, newName);
|
|
252
|
+
const hydrated = new Table(res);
|
|
253
|
+
Object.assign(this, hydrated);
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
moveRow(fromIndex: any, toIndex: any): any {
|
|
258
|
+
const dto = this.toDTO();
|
|
259
|
+
const res = _tableMoveRow(dto, fromIndex, toIndex);
|
|
260
|
+
const hydrated = new Table(res);
|
|
261
|
+
Object.assign(this, hydrated);
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
moveColumn(fromIndex: any, toIndex: any): any {
|
|
266
|
+
const dto = this.toDTO();
|
|
267
|
+
const res = _tableMoveColumn(dto, fromIndex, toIndex);
|
|
268
|
+
const hydrated = new Table(res);
|
|
269
|
+
Object.assign(this, hydrated);
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
246
272
|
}
|
|
247
273
|
|
|
248
274
|
export class Sheet {
|
|
@@ -285,9 +311,51 @@ export class Sheet {
|
|
|
285
311
|
|
|
286
312
|
toMarkdown(schema?: any): any {
|
|
287
313
|
const dto = this.toDTO();
|
|
288
|
-
const
|
|
314
|
+
const schemaDto = schema instanceof ParsingSchema ? schema.toDTO() : schema;
|
|
315
|
+
const res = _sheetToMarkdown(dto, schemaDto);
|
|
289
316
|
return res;
|
|
290
317
|
}
|
|
318
|
+
|
|
319
|
+
rename(newName: any): any {
|
|
320
|
+
const dto = this.toDTO();
|
|
321
|
+
const res = _sheetRename(dto, newName);
|
|
322
|
+
const hydrated = new Sheet(res);
|
|
323
|
+
Object.assign(this, hydrated);
|
|
324
|
+
return this;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
addTable(name?: any): any {
|
|
328
|
+
const dto = this.toDTO();
|
|
329
|
+
const res = _sheetAddTable(dto, name);
|
|
330
|
+
const hydrated = new Sheet(res);
|
|
331
|
+
Object.assign(this, hydrated);
|
|
332
|
+
return this;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
deleteTable(index: any): any {
|
|
336
|
+
const dto = this.toDTO();
|
|
337
|
+
const res = _sheetDeleteTable(dto, index);
|
|
338
|
+
const hydrated = new Sheet(res);
|
|
339
|
+
Object.assign(this, hydrated);
|
|
340
|
+
return this;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
replaceTable(index: any, table: any): any {
|
|
344
|
+
const dto = this.toDTO();
|
|
345
|
+
const tableDto = table instanceof Table ? table.toDTO() : table;
|
|
346
|
+
const res = _sheetReplaceTable(dto, index, tableDto);
|
|
347
|
+
const hydrated = new Sheet(res);
|
|
348
|
+
Object.assign(this, hydrated);
|
|
349
|
+
return this;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
moveTable(fromIndex: any, toIndex: any): any {
|
|
353
|
+
const dto = this.toDTO();
|
|
354
|
+
const res = _sheetMoveTable(dto, fromIndex, toIndex);
|
|
355
|
+
const hydrated = new Sheet(res);
|
|
356
|
+
Object.assign(this, hydrated);
|
|
357
|
+
return this;
|
|
358
|
+
}
|
|
291
359
|
}
|
|
292
360
|
|
|
293
361
|
export class Workbook {
|
|
@@ -327,7 +395,8 @@ export class Workbook {
|
|
|
327
395
|
|
|
328
396
|
toMarkdown(schema?: any): any {
|
|
329
397
|
const dto = this.toDTO();
|
|
330
|
-
const
|
|
398
|
+
const schemaDto = schema instanceof MultiTableParsingSchema ? schema.toDTO() : schema;
|
|
399
|
+
const res = _workbookToMarkdown(dto, schemaDto);
|
|
331
400
|
return res;
|
|
332
401
|
}
|
|
333
402
|
|
|
@@ -346,6 +415,31 @@ export class Workbook {
|
|
|
346
415
|
Object.assign(this, hydrated);
|
|
347
416
|
return this;
|
|
348
417
|
}
|
|
418
|
+
|
|
419
|
+
moveSheet(fromIndex: any, toIndex: any): any {
|
|
420
|
+
const dto = this.toDTO();
|
|
421
|
+
const res = _workbookMoveSheet(dto, fromIndex, toIndex);
|
|
422
|
+
const hydrated = new Workbook(res);
|
|
423
|
+
Object.assign(this, hydrated);
|
|
424
|
+
return this;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
replaceSheet(index: any, sheet: any): any {
|
|
428
|
+
const dto = this.toDTO();
|
|
429
|
+
const sheetDto = sheet instanceof Sheet ? sheet.toDTO() : sheet;
|
|
430
|
+
const res = _workbookReplaceSheet(dto, index, sheetDto);
|
|
431
|
+
const hydrated = new Workbook(res);
|
|
432
|
+
Object.assign(this, hydrated);
|
|
433
|
+
return this;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
renameSheet(index: any, newName: any): any {
|
|
437
|
+
const dto = this.toDTO();
|
|
438
|
+
const res = _workbookRenameSheet(dto, index, newName);
|
|
439
|
+
const hydrated = new Workbook(res);
|
|
440
|
+
Object.assign(this, hydrated);
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
349
443
|
}
|
|
350
444
|
|
|
351
445
|
export class ParsingSchema {
|