md-spreadsheet-parser 1.0.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 +158 -0
- package/dist/interfaces/example-spreadsheet-types.d.ts +50 -0
- package/dist/interfaces/exports.d.ts +100 -0
- package/dist/interfaces/wasi-cli-environment.d.ts +4 -0
- package/dist/interfaces/wasi-cli-exit.d.ts +3 -0
- package/dist/interfaces/wasi-cli-stderr.d.ts +3 -0
- package/dist/interfaces/wasi-cli-stdin.d.ts +3 -0
- package/dist/interfaces/wasi-cli-stdout.d.ts +3 -0
- package/dist/interfaces/wasi-cli-terminal-input.d.ts +8 -0
- package/dist/interfaces/wasi-cli-terminal-output.d.ts +8 -0
- package/dist/interfaces/wasi-cli-terminal-stderr.d.ts +3 -0
- package/dist/interfaces/wasi-cli-terminal-stdin.d.ts +3 -0
- package/dist/interfaces/wasi-cli-terminal-stdout.d.ts +3 -0
- package/dist/interfaces/wasi-clocks-monotonic-clock.d.ts +8 -0
- package/dist/interfaces/wasi-clocks-wall-clock.d.ts +7 -0
- package/dist/interfaces/wasi-filesystem-preopens.d.ts +3 -0
- package/dist/interfaces/wasi-filesystem-types.d.ts +208 -0
- package/dist/interfaces/wasi-io-error.d.ts +9 -0
- package/dist/interfaces/wasi-io-poll.d.ts +11 -0
- package/dist/interfaces/wasi-io-streams.d.ts +40 -0
- package/dist/interfaces/wasi-random-insecure-seed.d.ts +2 -0
- package/dist/interfaces/wasi-random-insecure.d.ts +3 -0
- package/dist/interfaces/wasi-random-random.d.ts +3 -0
- package/dist/interfaces/wasi-sockets-instance-network.d.ts +3 -0
- package/dist/interfaces/wasi-sockets-ip-name-lookup.d.ts +15 -0
- package/dist/interfaces/wasi-sockets-network.d.ts +92 -0
- package/dist/interfaces/wasi-sockets-tcp-create-socket.d.ts +5 -0
- package/dist/interfaces/wasi-sockets-tcp.d.ts +54 -0
- package/dist/interfaces/wasi-sockets-udp-create-socket.d.ts +5 -0
- package/dist/interfaces/wasi-sockets-udp.d.ts +53 -0
- package/dist/parser.core.wasm +0 -0
- package/dist/parser.core2.wasm +0 -0
- package/dist/parser.core3.wasm +0 -0
- package/dist/parser.core4.wasm +0 -0
- package/dist/parser.core5.wasm +0 -0
- package/dist/parser.core6.wasm +0 -0
- package/dist/parser.core7.wasm +0 -0
- package/dist/parser.core8.wasm +0 -0
- package/dist/parser.core9.wasm +0 -0
- package/dist/parser.d.ts +68 -0
- package/dist/parser.js +28872 -0
- package/dist/parser.wasm +0 -0
- package/package.json +36 -0
- package/src/__pycache__/app.cpython-314.pyc +0 -0
- package/src/__pycache__/generated_adapter.cpython-314.pyc +0 -0
- package/src/app.py +164 -0
- package/src/client-adapters.ts +40 -0
- package/src/generated_adapter.py +247 -0
- package/src/index.ts +317 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
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';
|
|
2
|
+
import { clientSideToModels } from './client-adapters.js';
|
|
3
|
+
|
|
4
|
+
export function cleanCell(cell: any, schema: any): any {
|
|
5
|
+
const res = _cleanCell(cell, schema);
|
|
6
|
+
return res;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function splitRowGfm(line: any, separator: any): any {
|
|
10
|
+
const res = _splitRowGfm(line, separator);
|
|
11
|
+
return res;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function parseRow(line: any, schema: any): any {
|
|
15
|
+
const res = _parseRow(line, schema);
|
|
16
|
+
return res;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function parseSeparatorRow(row: any, schema: any): any {
|
|
20
|
+
const res = _parseSeparatorRow(row, schema);
|
|
21
|
+
return res;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function isSeparatorRow(row: any, schema: any): any {
|
|
25
|
+
const res = _isSeparatorRow(row, schema);
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function parseTable(markdown: any, schema?: any): any {
|
|
30
|
+
const res = _parseTable(markdown, schema);
|
|
31
|
+
return new Table(res);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function parseSheet(markdown: any, name: any, schema: any, startLineOffset?: any): any {
|
|
35
|
+
const res = _parseSheet(markdown, name, schema, startLineOffset);
|
|
36
|
+
return new Sheet(res);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function parseWorkbook(markdown: any, schema?: any): any {
|
|
40
|
+
const res = _parseWorkbook(markdown, schema);
|
|
41
|
+
return new Workbook(res);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function scanTables(markdown: any, schema?: any): any {
|
|
45
|
+
const res = _scanTables(markdown, schema);
|
|
46
|
+
return res.map((x: any) => new Table(x));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function generateTableMarkdown(table: any, schema?: any): any {
|
|
50
|
+
const res = _generateTableMarkdown(table, schema);
|
|
51
|
+
return res;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function generateSheetMarkdown(sheet: any, schema?: any): any {
|
|
55
|
+
const res = _generateSheetMarkdown(sheet, schema);
|
|
56
|
+
return res;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function generateWorkbookMarkdown(workbook: any, schema: any): any {
|
|
60
|
+
const res = _generateWorkbookMarkdown(workbook, schema);
|
|
61
|
+
return res;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function parseTableFromFile(source: any, schema?: any): any {
|
|
65
|
+
const res = _parseTableFromFile(source, schema);
|
|
66
|
+
return new Table(res);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function parseWorkbookFromFile(source: any, schema?: any): any {
|
|
70
|
+
const res = _parseWorkbookFromFile(source, schema);
|
|
71
|
+
return new Workbook(res);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function scanTablesFromFile(source: any, schema?: any): any {
|
|
75
|
+
const res = _scanTablesFromFile(source, schema);
|
|
76
|
+
return res.map((x: any) => new Table(x));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function scanTablesIter(source: any, schema?: any): any {
|
|
80
|
+
const res = _scanTablesIter(source, schema);
|
|
81
|
+
return res;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
export class Table {
|
|
86
|
+
headers: any | undefined;
|
|
87
|
+
rows: any[] | undefined;
|
|
88
|
+
alignments: any | undefined;
|
|
89
|
+
name: any | undefined;
|
|
90
|
+
description: any | undefined;
|
|
91
|
+
metadata: any | undefined;
|
|
92
|
+
startLine: number | undefined;
|
|
93
|
+
endLine: number | undefined;
|
|
94
|
+
|
|
95
|
+
constructor(data?: Partial<Table>) {
|
|
96
|
+
if (data) {
|
|
97
|
+
this.headers = data.headers;
|
|
98
|
+
this.rows = data.rows;
|
|
99
|
+
this.alignments = data.alignments;
|
|
100
|
+
this.name = data.name;
|
|
101
|
+
this.description = data.description;
|
|
102
|
+
this.metadata = (typeof data.metadata === 'string') ? JSON.parse(data.metadata) : data.metadata;
|
|
103
|
+
this.startLine = data.startLine;
|
|
104
|
+
this.endLine = data.endLine;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
toModels(schemaCls: any, conversionSchema?: any): any {
|
|
109
|
+
const dto = { ...this } as any;
|
|
110
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
111
|
+
const clientRes = clientSideToModels(this.headers, this.rows || [], schemaCls);
|
|
112
|
+
if (clientRes) {
|
|
113
|
+
return clientRes;
|
|
114
|
+
}
|
|
115
|
+
const res = _tableToModels(dto, schemaCls, conversionSchema);
|
|
116
|
+
return res.map((x: string) => JSON.parse(x));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
toMarkdown(schema?: any): any {
|
|
120
|
+
const dto = { ...this } as any;
|
|
121
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
122
|
+
const res = _tableToMarkdown(dto, schema);
|
|
123
|
+
return res;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
updateCell(rowIdx: any, colIdx: any, value: any): any {
|
|
127
|
+
const dto = { ...this } as any;
|
|
128
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
129
|
+
const res = _tableUpdateCell(dto, rowIdx, colIdx, value);
|
|
130
|
+
Object.assign(this, res);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
deleteRow(rowIdx: any): any {
|
|
135
|
+
const dto = { ...this } as any;
|
|
136
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
137
|
+
const res = _tableDeleteRow(dto, rowIdx);
|
|
138
|
+
Object.assign(this, res);
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
deleteColumn(colIdx: any): any {
|
|
143
|
+
const dto = { ...this } as any;
|
|
144
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
145
|
+
const res = _tableDeleteColumn(dto, colIdx);
|
|
146
|
+
Object.assign(this, res);
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
clearColumnData(colIdx: any): any {
|
|
151
|
+
const dto = { ...this } as any;
|
|
152
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
153
|
+
const res = _tableClearColumnData(dto, colIdx);
|
|
154
|
+
Object.assign(this, res);
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
insertRow(rowIdx: any): any {
|
|
159
|
+
const dto = { ...this } as any;
|
|
160
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
161
|
+
const res = _tableInsertRow(dto, rowIdx);
|
|
162
|
+
Object.assign(this, res);
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
insertColumn(colIdx: any): any {
|
|
167
|
+
const dto = { ...this } as any;
|
|
168
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
169
|
+
const res = _tableInsertColumn(dto, colIdx);
|
|
170
|
+
Object.assign(this, res);
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export class Sheet {
|
|
176
|
+
name: string | undefined;
|
|
177
|
+
tables: any[] | undefined;
|
|
178
|
+
metadata: any | undefined;
|
|
179
|
+
|
|
180
|
+
constructor(data?: Partial<Sheet>) {
|
|
181
|
+
if (data) {
|
|
182
|
+
this.name = data.name;
|
|
183
|
+
this.tables = data.tables;
|
|
184
|
+
this.metadata = (typeof data.metadata === 'string') ? JSON.parse(data.metadata) : data.metadata;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
getTable(name: any): any {
|
|
189
|
+
const dto = { ...this } as any;
|
|
190
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
191
|
+
const res = _sheetGetTable(dto, name);
|
|
192
|
+
return res;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
toMarkdown(schema?: any): any {
|
|
196
|
+
const dto = { ...this } as any;
|
|
197
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
198
|
+
const res = _sheetToMarkdown(dto, schema);
|
|
199
|
+
return res;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export class Workbook {
|
|
204
|
+
sheets: any[] | undefined;
|
|
205
|
+
metadata: any | undefined;
|
|
206
|
+
|
|
207
|
+
constructor(data?: Partial<Workbook>) {
|
|
208
|
+
if (data) {
|
|
209
|
+
this.sheets = data.sheets;
|
|
210
|
+
this.metadata = (typeof data.metadata === 'string') ? JSON.parse(data.metadata) : data.metadata;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
getSheet(name: any): any {
|
|
215
|
+
const dto = { ...this } as any;
|
|
216
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
217
|
+
const res = _workbookGetSheet(dto, name);
|
|
218
|
+
return res;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
toMarkdown(schema: any): any {
|
|
222
|
+
const dto = { ...this } as any;
|
|
223
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
224
|
+
const res = _workbookToMarkdown(dto, schema);
|
|
225
|
+
return res;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
addSheet(name: any): any {
|
|
229
|
+
const dto = { ...this } as any;
|
|
230
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
231
|
+
const res = _workbookAddSheet(dto, name);
|
|
232
|
+
Object.assign(this, res);
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
deleteSheet(index: any): any {
|
|
237
|
+
const dto = { ...this } as any;
|
|
238
|
+
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
239
|
+
const res = _workbookDeleteSheet(dto, index);
|
|
240
|
+
Object.assign(this, res);
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export class ParsingSchema {
|
|
246
|
+
columnSeparator: string | undefined;
|
|
247
|
+
headerSeparatorChar: string | undefined;
|
|
248
|
+
requireOuterPipes: boolean | undefined;
|
|
249
|
+
stripWhitespace: boolean | undefined;
|
|
250
|
+
convertBrToNewline: boolean | undefined;
|
|
251
|
+
|
|
252
|
+
constructor(data?: Partial<ParsingSchema>) {
|
|
253
|
+
if (data) {
|
|
254
|
+
this.columnSeparator = data.columnSeparator;
|
|
255
|
+
this.headerSeparatorChar = data.headerSeparatorChar;
|
|
256
|
+
this.requireOuterPipes = data.requireOuterPipes;
|
|
257
|
+
this.stripWhitespace = data.stripWhitespace;
|
|
258
|
+
this.convertBrToNewline = data.convertBrToNewline;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export class MultiTableParsingSchema {
|
|
264
|
+
columnSeparator: string | undefined;
|
|
265
|
+
headerSeparatorChar: string | undefined;
|
|
266
|
+
requireOuterPipes: boolean | undefined;
|
|
267
|
+
stripWhitespace: boolean | undefined;
|
|
268
|
+
convertBrToNewline: boolean | undefined;
|
|
269
|
+
rootMarker: string | undefined;
|
|
270
|
+
sheetHeaderLevel: number | undefined;
|
|
271
|
+
tableHeaderLevel: number | undefined;
|
|
272
|
+
captureDescription: boolean | undefined;
|
|
273
|
+
|
|
274
|
+
constructor(data?: Partial<MultiTableParsingSchema>) {
|
|
275
|
+
if (data) {
|
|
276
|
+
this.columnSeparator = data.columnSeparator;
|
|
277
|
+
this.headerSeparatorChar = data.headerSeparatorChar;
|
|
278
|
+
this.requireOuterPipes = data.requireOuterPipes;
|
|
279
|
+
this.stripWhitespace = data.stripWhitespace;
|
|
280
|
+
this.convertBrToNewline = data.convertBrToNewline;
|
|
281
|
+
this.rootMarker = data.rootMarker;
|
|
282
|
+
this.sheetHeaderLevel = data.sheetHeaderLevel;
|
|
283
|
+
this.tableHeaderLevel = data.tableHeaderLevel;
|
|
284
|
+
this.captureDescription = data.captureDescription;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export class ConversionSchema {
|
|
290
|
+
booleanPairs: string | undefined;
|
|
291
|
+
customConverters: string | undefined;
|
|
292
|
+
fieldConverters: string | undefined;
|
|
293
|
+
|
|
294
|
+
constructor(data?: Partial<ConversionSchema>) {
|
|
295
|
+
if (data) {
|
|
296
|
+
this.booleanPairs = data.booleanPairs;
|
|
297
|
+
this.customConverters = (typeof data.customConverters === 'string') ? JSON.parse(data.customConverters) : data.customConverters;
|
|
298
|
+
this.fieldConverters = (typeof data.fieldConverters === 'string') ? JSON.parse(data.fieldConverters) : data.fieldConverters;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export class ExcelParsingSchema {
|
|
304
|
+
headerRows: number | undefined;
|
|
305
|
+
fillMergedHeaders: boolean | undefined;
|
|
306
|
+
delimiter: string | undefined;
|
|
307
|
+
headerSeparator: string | undefined;
|
|
308
|
+
|
|
309
|
+
constructor(data?: Partial<ExcelParsingSchema>) {
|
|
310
|
+
if (data) {
|
|
311
|
+
this.headerRows = data.headerRows;
|
|
312
|
+
this.fillMergedHeaders = data.fillMergedHeaders;
|
|
313
|
+
this.delimiter = data.delimiter;
|
|
314
|
+
this.headerSeparator = data.headerSeparator;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|