md-spreadsheet-parser 1.1.2 → 1.1.4
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/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare class Table {
|
|
|
24
24
|
startLine: number | undefined;
|
|
25
25
|
endLine: number | undefined;
|
|
26
26
|
constructor(data?: Partial<Table>);
|
|
27
|
+
toDTO(): any;
|
|
27
28
|
toModels(schemaCls: any, conversionSchema?: any): any;
|
|
28
29
|
toMarkdown(schema?: any): any;
|
|
29
30
|
updateCell(rowIdx: any, colIdx: any, value: any): any;
|
|
@@ -38,6 +39,7 @@ export declare class Sheet {
|
|
|
38
39
|
tables: any[] | undefined;
|
|
39
40
|
metadata: any | undefined;
|
|
40
41
|
constructor(data?: Partial<Sheet>);
|
|
42
|
+
toDTO(): any;
|
|
41
43
|
getTable(name: any): any;
|
|
42
44
|
toMarkdown(schema?: any): any;
|
|
43
45
|
}
|
|
@@ -45,6 +47,7 @@ export declare class Workbook {
|
|
|
45
47
|
sheets: any[] | undefined;
|
|
46
48
|
metadata: any | undefined;
|
|
47
49
|
constructor(data?: Partial<Workbook>);
|
|
50
|
+
toDTO(): any;
|
|
48
51
|
getSheet(name: any): any;
|
|
49
52
|
toMarkdown(schema: any): any;
|
|
50
53
|
addSheet(name: any): any;
|
|
@@ -57,6 +60,7 @@ export declare class ParsingSchema {
|
|
|
57
60
|
stripWhitespace: boolean | undefined;
|
|
58
61
|
convertBrToNewline: boolean | undefined;
|
|
59
62
|
constructor(data?: Partial<ParsingSchema>);
|
|
63
|
+
toDTO(): any;
|
|
60
64
|
}
|
|
61
65
|
export declare class MultiTableParsingSchema {
|
|
62
66
|
columnSeparator: string | undefined;
|
|
@@ -69,12 +73,14 @@ export declare class MultiTableParsingSchema {
|
|
|
69
73
|
tableHeaderLevel: number | undefined;
|
|
70
74
|
captureDescription: boolean | undefined;
|
|
71
75
|
constructor(data?: Partial<MultiTableParsingSchema>);
|
|
76
|
+
toDTO(): any;
|
|
72
77
|
}
|
|
73
78
|
export declare class ConversionSchema {
|
|
74
79
|
booleanPairs: string | undefined;
|
|
75
80
|
customConverters: string | undefined;
|
|
76
81
|
fieldConverters: string | undefined;
|
|
77
82
|
constructor(data?: Partial<ConversionSchema>);
|
|
83
|
+
toDTO(): any;
|
|
78
84
|
}
|
|
79
85
|
export declare class ExcelParsingSchema {
|
|
80
86
|
headerRows: number | undefined;
|
|
@@ -82,4 +88,5 @@ export declare class ExcelParsingSchema {
|
|
|
82
88
|
delimiter: string | undefined;
|
|
83
89
|
headerSeparator: string | undefined;
|
|
84
90
|
constructor(data?: Partial<ExcelParsingSchema>);
|
|
91
|
+
toDTO(): any;
|
|
85
92
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
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
|
+
// @ts-ignore
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import { _addPreopen } from '@bytecodealliance/preview2-shim/filesystem';
|
|
2
8
|
import { clientSideToModels } from './client-adapters.js';
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
_addPreopen('/', path.parse(process.cwd()).root);
|
|
11
|
+
function resolveToVirtualPath(p) {
|
|
12
|
+
return path.resolve(p);
|
|
13
|
+
}
|
|
3
14
|
export function cleanCell(cell, schema) {
|
|
4
15
|
const res = _cleanCell(cell, schema);
|
|
5
16
|
return res;
|
|
@@ -49,15 +60,18 @@ export function generateWorkbookMarkdown(workbook, schema) {
|
|
|
49
60
|
return res;
|
|
50
61
|
}
|
|
51
62
|
export function parseTableFromFile(source, schema) {
|
|
52
|
-
const
|
|
63
|
+
const source_resolved = resolveToVirtualPath(source);
|
|
64
|
+
const res = _parseTableFromFile(source_resolved, schema);
|
|
53
65
|
return new Table(res);
|
|
54
66
|
}
|
|
55
67
|
export function parseWorkbookFromFile(source, schema) {
|
|
56
|
-
const
|
|
68
|
+
const source_resolved = resolveToVirtualPath(source);
|
|
69
|
+
const res = _parseWorkbookFromFile(source_resolved, schema);
|
|
57
70
|
return new Workbook(res);
|
|
58
71
|
}
|
|
59
72
|
export function scanTablesFromFile(source, schema) {
|
|
60
|
-
const
|
|
73
|
+
const source_resolved = resolveToVirtualPath(source);
|
|
74
|
+
const res = _scanTablesFromFile(source_resolved, schema);
|
|
61
75
|
return res.map((x) => new Table(x));
|
|
62
76
|
}
|
|
63
77
|
export function scanTablesIter(source, schema) {
|
|
@@ -77,10 +91,14 @@ export class Table {
|
|
|
77
91
|
this.endLine = data.endLine;
|
|
78
92
|
}
|
|
79
93
|
}
|
|
80
|
-
|
|
94
|
+
toDTO() {
|
|
81
95
|
const dto = { ...this };
|
|
82
96
|
if (dto.metadata)
|
|
83
97
|
dto.metadata = JSON.stringify(dto.metadata);
|
|
98
|
+
return dto;
|
|
99
|
+
}
|
|
100
|
+
toModels(schemaCls, conversionSchema) {
|
|
101
|
+
const dto = this.toDTO();
|
|
84
102
|
const clientRes = clientSideToModels(this.headers, this.rows || [], schemaCls);
|
|
85
103
|
if (clientRes) {
|
|
86
104
|
return clientRes;
|
|
@@ -89,56 +107,42 @@ export class Table {
|
|
|
89
107
|
return res.map((x) => JSON.parse(x));
|
|
90
108
|
}
|
|
91
109
|
toMarkdown(schema) {
|
|
92
|
-
const dto =
|
|
93
|
-
if (dto.metadata)
|
|
94
|
-
dto.metadata = JSON.stringify(dto.metadata);
|
|
110
|
+
const dto = this.toDTO();
|
|
95
111
|
const res = _tableToMarkdown(dto, schema);
|
|
96
112
|
return res;
|
|
97
113
|
}
|
|
98
114
|
updateCell(rowIdx, colIdx, value) {
|
|
99
|
-
const dto =
|
|
100
|
-
if (dto.metadata)
|
|
101
|
-
dto.metadata = JSON.stringify(dto.metadata);
|
|
115
|
+
const dto = this.toDTO();
|
|
102
116
|
const res = _tableUpdateCell(dto, rowIdx, colIdx, value);
|
|
103
117
|
Object.assign(this, res);
|
|
104
118
|
return this;
|
|
105
119
|
}
|
|
106
120
|
deleteRow(rowIdx) {
|
|
107
|
-
const dto =
|
|
108
|
-
if (dto.metadata)
|
|
109
|
-
dto.metadata = JSON.stringify(dto.metadata);
|
|
121
|
+
const dto = this.toDTO();
|
|
110
122
|
const res = _tableDeleteRow(dto, rowIdx);
|
|
111
123
|
Object.assign(this, res);
|
|
112
124
|
return this;
|
|
113
125
|
}
|
|
114
126
|
deleteColumn(colIdx) {
|
|
115
|
-
const dto =
|
|
116
|
-
if (dto.metadata)
|
|
117
|
-
dto.metadata = JSON.stringify(dto.metadata);
|
|
127
|
+
const dto = this.toDTO();
|
|
118
128
|
const res = _tableDeleteColumn(dto, colIdx);
|
|
119
129
|
Object.assign(this, res);
|
|
120
130
|
return this;
|
|
121
131
|
}
|
|
122
132
|
clearColumnData(colIdx) {
|
|
123
|
-
const dto =
|
|
124
|
-
if (dto.metadata)
|
|
125
|
-
dto.metadata = JSON.stringify(dto.metadata);
|
|
133
|
+
const dto = this.toDTO();
|
|
126
134
|
const res = _tableClearColumnData(dto, colIdx);
|
|
127
135
|
Object.assign(this, res);
|
|
128
136
|
return this;
|
|
129
137
|
}
|
|
130
138
|
insertRow(rowIdx) {
|
|
131
|
-
const dto =
|
|
132
|
-
if (dto.metadata)
|
|
133
|
-
dto.metadata = JSON.stringify(dto.metadata);
|
|
139
|
+
const dto = this.toDTO();
|
|
134
140
|
const res = _tableInsertRow(dto, rowIdx);
|
|
135
141
|
Object.assign(this, res);
|
|
136
142
|
return this;
|
|
137
143
|
}
|
|
138
144
|
insertColumn(colIdx) {
|
|
139
|
-
const dto =
|
|
140
|
-
if (dto.metadata)
|
|
141
|
-
dto.metadata = JSON.stringify(dto.metadata);
|
|
145
|
+
const dto = this.toDTO();
|
|
142
146
|
const res = _tableInsertColumn(dto, colIdx);
|
|
143
147
|
Object.assign(this, res);
|
|
144
148
|
return this;
|
|
@@ -152,17 +156,21 @@ export class Sheet {
|
|
|
152
156
|
this.metadata = (typeof data.metadata === 'string') ? JSON.parse(data.metadata) : data.metadata;
|
|
153
157
|
}
|
|
154
158
|
}
|
|
155
|
-
|
|
159
|
+
toDTO() {
|
|
156
160
|
const dto = { ...this };
|
|
161
|
+
if (dto.tables)
|
|
162
|
+
dto.tables = dto.tables.map((x) => x.toDTO ? x.toDTO() : x);
|
|
157
163
|
if (dto.metadata)
|
|
158
164
|
dto.metadata = JSON.stringify(dto.metadata);
|
|
165
|
+
return dto;
|
|
166
|
+
}
|
|
167
|
+
getTable(name) {
|
|
168
|
+
const dto = this.toDTO();
|
|
159
169
|
const res = _sheetGetTable(dto, name);
|
|
160
|
-
return res;
|
|
170
|
+
return res ? new Table(res) : undefined;
|
|
161
171
|
}
|
|
162
172
|
toMarkdown(schema) {
|
|
163
|
-
const dto =
|
|
164
|
-
if (dto.metadata)
|
|
165
|
-
dto.metadata = JSON.stringify(dto.metadata);
|
|
173
|
+
const dto = this.toDTO();
|
|
166
174
|
const res = _sheetToMarkdown(dto, schema);
|
|
167
175
|
return res;
|
|
168
176
|
}
|
|
@@ -174,32 +182,32 @@ export class Workbook {
|
|
|
174
182
|
this.metadata = (typeof data.metadata === 'string') ? JSON.parse(data.metadata) : data.metadata;
|
|
175
183
|
}
|
|
176
184
|
}
|
|
177
|
-
|
|
185
|
+
toDTO() {
|
|
178
186
|
const dto = { ...this };
|
|
187
|
+
if (dto.sheets)
|
|
188
|
+
dto.sheets = dto.sheets.map((x) => x.toDTO ? x.toDTO() : x);
|
|
179
189
|
if (dto.metadata)
|
|
180
190
|
dto.metadata = JSON.stringify(dto.metadata);
|
|
191
|
+
return dto;
|
|
192
|
+
}
|
|
193
|
+
getSheet(name) {
|
|
194
|
+
const dto = this.toDTO();
|
|
181
195
|
const res = _workbookGetSheet(dto, name);
|
|
182
|
-
return res;
|
|
196
|
+
return res ? new Sheet(res) : undefined;
|
|
183
197
|
}
|
|
184
198
|
toMarkdown(schema) {
|
|
185
|
-
const dto =
|
|
186
|
-
if (dto.metadata)
|
|
187
|
-
dto.metadata = JSON.stringify(dto.metadata);
|
|
199
|
+
const dto = this.toDTO();
|
|
188
200
|
const res = _workbookToMarkdown(dto, schema);
|
|
189
201
|
return res;
|
|
190
202
|
}
|
|
191
203
|
addSheet(name) {
|
|
192
|
-
const dto =
|
|
193
|
-
if (dto.metadata)
|
|
194
|
-
dto.metadata = JSON.stringify(dto.metadata);
|
|
204
|
+
const dto = this.toDTO();
|
|
195
205
|
const res = _workbookAddSheet(dto, name);
|
|
196
206
|
Object.assign(this, res);
|
|
197
207
|
return this;
|
|
198
208
|
}
|
|
199
209
|
deleteSheet(index) {
|
|
200
|
-
const dto =
|
|
201
|
-
if (dto.metadata)
|
|
202
|
-
dto.metadata = JSON.stringify(dto.metadata);
|
|
210
|
+
const dto = this.toDTO();
|
|
203
211
|
const res = _workbookDeleteSheet(dto, index);
|
|
204
212
|
Object.assign(this, res);
|
|
205
213
|
return this;
|
|
@@ -215,6 +223,10 @@ export class ParsingSchema {
|
|
|
215
223
|
this.convertBrToNewline = data.convertBrToNewline;
|
|
216
224
|
}
|
|
217
225
|
}
|
|
226
|
+
toDTO() {
|
|
227
|
+
const dto = { ...this };
|
|
228
|
+
return dto;
|
|
229
|
+
}
|
|
218
230
|
}
|
|
219
231
|
export class MultiTableParsingSchema {
|
|
220
232
|
constructor(data) {
|
|
@@ -230,6 +242,10 @@ export class MultiTableParsingSchema {
|
|
|
230
242
|
this.captureDescription = data.captureDescription;
|
|
231
243
|
}
|
|
232
244
|
}
|
|
245
|
+
toDTO() {
|
|
246
|
+
const dto = { ...this };
|
|
247
|
+
return dto;
|
|
248
|
+
}
|
|
233
249
|
}
|
|
234
250
|
export class ConversionSchema {
|
|
235
251
|
constructor(data) {
|
|
@@ -239,6 +255,14 @@ export class ConversionSchema {
|
|
|
239
255
|
this.fieldConverters = (typeof data.fieldConverters === 'string') ? JSON.parse(data.fieldConverters) : data.fieldConverters;
|
|
240
256
|
}
|
|
241
257
|
}
|
|
258
|
+
toDTO() {
|
|
259
|
+
const dto = { ...this };
|
|
260
|
+
if (dto.customConverters)
|
|
261
|
+
dto.customConverters = JSON.stringify(dto.customConverters);
|
|
262
|
+
if (dto.fieldConverters)
|
|
263
|
+
dto.fieldConverters = JSON.stringify(dto.fieldConverters);
|
|
264
|
+
return dto;
|
|
265
|
+
}
|
|
242
266
|
}
|
|
243
267
|
export class ExcelParsingSchema {
|
|
244
268
|
constructor(data) {
|
|
@@ -249,4 +273,8 @@ export class ExcelParsingSchema {
|
|
|
249
273
|
this.headerSeparator = data.headerSeparator;
|
|
250
274
|
}
|
|
251
275
|
}
|
|
276
|
+
toDTO() {
|
|
277
|
+
const dto = { ...this };
|
|
278
|
+
return dto;
|
|
279
|
+
}
|
|
252
280
|
}
|
package/dist/parser.core.wasm
CHANGED
|
Binary file
|
package/dist/parser.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
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
|
+
// @ts-ignore
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import { _addPreopen } from '@bytecodealliance/preview2-shim/filesystem';
|
|
2
8
|
import { clientSideToModels } from './client-adapters.js';
|
|
3
9
|
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
_addPreopen('/', path.parse(process.cwd()).root);
|
|
12
|
+
|
|
13
|
+
function resolveToVirtualPath(p: string) {
|
|
14
|
+
return path.resolve(p);
|
|
15
|
+
}
|
|
16
|
+
|
|
4
17
|
export function cleanCell(cell: any, schema: any): any {
|
|
5
18
|
const res = _cleanCell(cell, schema);
|
|
6
19
|
return res;
|
|
@@ -62,17 +75,20 @@ export function generateWorkbookMarkdown(workbook: any, schema: any): any {
|
|
|
62
75
|
}
|
|
63
76
|
|
|
64
77
|
export function parseTableFromFile(source: any, schema?: any): any {
|
|
65
|
-
const
|
|
78
|
+
const source_resolved = resolveToVirtualPath(source);
|
|
79
|
+
const res = _parseTableFromFile(source_resolved, schema);
|
|
66
80
|
return new Table(res);
|
|
67
81
|
}
|
|
68
82
|
|
|
69
83
|
export function parseWorkbookFromFile(source: any, schema?: any): any {
|
|
70
|
-
const
|
|
84
|
+
const source_resolved = resolveToVirtualPath(source);
|
|
85
|
+
const res = _parseWorkbookFromFile(source_resolved, schema);
|
|
71
86
|
return new Workbook(res);
|
|
72
87
|
}
|
|
73
88
|
|
|
74
89
|
export function scanTablesFromFile(source: any, schema?: any): any {
|
|
75
|
-
const
|
|
90
|
+
const source_resolved = resolveToVirtualPath(source);
|
|
91
|
+
const res = _scanTablesFromFile(source_resolved, schema);
|
|
76
92
|
return res.map((x: any) => new Table(x));
|
|
77
93
|
}
|
|
78
94
|
|
|
@@ -105,9 +121,14 @@ export class Table {
|
|
|
105
121
|
}
|
|
106
122
|
}
|
|
107
123
|
|
|
108
|
-
|
|
124
|
+
toDTO(): any {
|
|
109
125
|
const dto = { ...this } as any;
|
|
110
126
|
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
127
|
+
return dto;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
toModels(schemaCls: any, conversionSchema?: any): any {
|
|
131
|
+
const dto = this.toDTO();
|
|
111
132
|
const clientRes = clientSideToModels(this.headers, this.rows || [], schemaCls);
|
|
112
133
|
if (clientRes) {
|
|
113
134
|
return clientRes;
|
|
@@ -117,55 +138,48 @@ export class Table {
|
|
|
117
138
|
}
|
|
118
139
|
|
|
119
140
|
toMarkdown(schema?: any): any {
|
|
120
|
-
const dto =
|
|
121
|
-
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
141
|
+
const dto = this.toDTO();
|
|
122
142
|
const res = _tableToMarkdown(dto, schema);
|
|
123
143
|
return res;
|
|
124
144
|
}
|
|
125
145
|
|
|
126
146
|
updateCell(rowIdx: any, colIdx: any, value: any): any {
|
|
127
|
-
const dto =
|
|
128
|
-
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
147
|
+
const dto = this.toDTO();
|
|
129
148
|
const res = _tableUpdateCell(dto, rowIdx, colIdx, value);
|
|
130
149
|
Object.assign(this, res);
|
|
131
150
|
return this;
|
|
132
151
|
}
|
|
133
152
|
|
|
134
153
|
deleteRow(rowIdx: any): any {
|
|
135
|
-
const dto =
|
|
136
|
-
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
154
|
+
const dto = this.toDTO();
|
|
137
155
|
const res = _tableDeleteRow(dto, rowIdx);
|
|
138
156
|
Object.assign(this, res);
|
|
139
157
|
return this;
|
|
140
158
|
}
|
|
141
159
|
|
|
142
160
|
deleteColumn(colIdx: any): any {
|
|
143
|
-
const dto =
|
|
144
|
-
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
161
|
+
const dto = this.toDTO();
|
|
145
162
|
const res = _tableDeleteColumn(dto, colIdx);
|
|
146
163
|
Object.assign(this, res);
|
|
147
164
|
return this;
|
|
148
165
|
}
|
|
149
166
|
|
|
150
167
|
clearColumnData(colIdx: any): any {
|
|
151
|
-
const dto =
|
|
152
|
-
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
168
|
+
const dto = this.toDTO();
|
|
153
169
|
const res = _tableClearColumnData(dto, colIdx);
|
|
154
170
|
Object.assign(this, res);
|
|
155
171
|
return this;
|
|
156
172
|
}
|
|
157
173
|
|
|
158
174
|
insertRow(rowIdx: any): any {
|
|
159
|
-
const dto =
|
|
160
|
-
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
175
|
+
const dto = this.toDTO();
|
|
161
176
|
const res = _tableInsertRow(dto, rowIdx);
|
|
162
177
|
Object.assign(this, res);
|
|
163
178
|
return this;
|
|
164
179
|
}
|
|
165
180
|
|
|
166
181
|
insertColumn(colIdx: any): any {
|
|
167
|
-
const dto =
|
|
168
|
-
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
182
|
+
const dto = this.toDTO();
|
|
169
183
|
const res = _tableInsertColumn(dto, colIdx);
|
|
170
184
|
Object.assign(this, res);
|
|
171
185
|
return this;
|
|
@@ -185,16 +199,21 @@ export class Sheet {
|
|
|
185
199
|
}
|
|
186
200
|
}
|
|
187
201
|
|
|
188
|
-
|
|
202
|
+
toDTO(): any {
|
|
189
203
|
const dto = { ...this } as any;
|
|
204
|
+
if (dto.tables) dto.tables = dto.tables.map((x: any) => x.toDTO ? x.toDTO() : x);
|
|
190
205
|
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
206
|
+
return dto;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
getTable(name: any): any {
|
|
210
|
+
const dto = this.toDTO();
|
|
191
211
|
const res = _sheetGetTable(dto, name);
|
|
192
|
-
return res;
|
|
212
|
+
return res ? new Table(res) : undefined;
|
|
193
213
|
}
|
|
194
214
|
|
|
195
215
|
toMarkdown(schema?: any): any {
|
|
196
|
-
const dto =
|
|
197
|
-
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
216
|
+
const dto = this.toDTO();
|
|
198
217
|
const res = _sheetToMarkdown(dto, schema);
|
|
199
218
|
return res;
|
|
200
219
|
}
|
|
@@ -211,31 +230,34 @@ export class Workbook {
|
|
|
211
230
|
}
|
|
212
231
|
}
|
|
213
232
|
|
|
214
|
-
|
|
233
|
+
toDTO(): any {
|
|
215
234
|
const dto = { ...this } as any;
|
|
235
|
+
if (dto.sheets) dto.sheets = dto.sheets.map((x: any) => x.toDTO ? x.toDTO() : x);
|
|
216
236
|
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
237
|
+
return dto;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
getSheet(name: any): any {
|
|
241
|
+
const dto = this.toDTO();
|
|
217
242
|
const res = _workbookGetSheet(dto, name);
|
|
218
|
-
return res;
|
|
243
|
+
return res ? new Sheet(res) : undefined;
|
|
219
244
|
}
|
|
220
245
|
|
|
221
246
|
toMarkdown(schema: any): any {
|
|
222
|
-
const dto =
|
|
223
|
-
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
247
|
+
const dto = this.toDTO();
|
|
224
248
|
const res = _workbookToMarkdown(dto, schema);
|
|
225
249
|
return res;
|
|
226
250
|
}
|
|
227
251
|
|
|
228
252
|
addSheet(name: any): any {
|
|
229
|
-
const dto =
|
|
230
|
-
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
253
|
+
const dto = this.toDTO();
|
|
231
254
|
const res = _workbookAddSheet(dto, name);
|
|
232
255
|
Object.assign(this, res);
|
|
233
256
|
return this;
|
|
234
257
|
}
|
|
235
258
|
|
|
236
259
|
deleteSheet(index: any): any {
|
|
237
|
-
const dto =
|
|
238
|
-
if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
|
|
260
|
+
const dto = this.toDTO();
|
|
239
261
|
const res = _workbookDeleteSheet(dto, index);
|
|
240
262
|
Object.assign(this, res);
|
|
241
263
|
return this;
|
|
@@ -258,6 +280,11 @@ export class ParsingSchema {
|
|
|
258
280
|
this.convertBrToNewline = data.convertBrToNewline;
|
|
259
281
|
}
|
|
260
282
|
}
|
|
283
|
+
|
|
284
|
+
toDTO(): any {
|
|
285
|
+
const dto = { ...this } as any;
|
|
286
|
+
return dto;
|
|
287
|
+
}
|
|
261
288
|
}
|
|
262
289
|
|
|
263
290
|
export class MultiTableParsingSchema {
|
|
@@ -284,6 +311,11 @@ export class MultiTableParsingSchema {
|
|
|
284
311
|
this.captureDescription = data.captureDescription;
|
|
285
312
|
}
|
|
286
313
|
}
|
|
314
|
+
|
|
315
|
+
toDTO(): any {
|
|
316
|
+
const dto = { ...this } as any;
|
|
317
|
+
return dto;
|
|
318
|
+
}
|
|
287
319
|
}
|
|
288
320
|
|
|
289
321
|
export class ConversionSchema {
|
|
@@ -298,6 +330,13 @@ export class ConversionSchema {
|
|
|
298
330
|
this.fieldConverters = (typeof data.fieldConverters === 'string') ? JSON.parse(data.fieldConverters) : data.fieldConverters;
|
|
299
331
|
}
|
|
300
332
|
}
|
|
333
|
+
|
|
334
|
+
toDTO(): any {
|
|
335
|
+
const dto = { ...this } as any;
|
|
336
|
+
if (dto.customConverters) dto.customConverters = JSON.stringify(dto.customConverters);
|
|
337
|
+
if (dto.fieldConverters) dto.fieldConverters = JSON.stringify(dto.fieldConverters);
|
|
338
|
+
return dto;
|
|
339
|
+
}
|
|
301
340
|
}
|
|
302
341
|
|
|
303
342
|
export class ExcelParsingSchema {
|
|
@@ -314,4 +353,9 @@ export class ExcelParsingSchema {
|
|
|
314
353
|
this.headerSeparator = data.headerSeparator;
|
|
315
354
|
}
|
|
316
355
|
}
|
|
356
|
+
|
|
357
|
+
toDTO(): any {
|
|
358
|
+
const dto = { ...this } as any;
|
|
359
|
+
return dto;
|
|
360
|
+
}
|
|
317
361
|
}
|