md-spreadsheet-parser 1.1.1 → 1.1.3

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
@@ -77,10 +77,14 @@ export class Table {
77
77
  this.endLine = data.endLine;
78
78
  }
79
79
  }
80
- toModels(schemaCls, conversionSchema) {
80
+ toDTO() {
81
81
  const dto = { ...this };
82
82
  if (dto.metadata)
83
83
  dto.metadata = JSON.stringify(dto.metadata);
84
+ return dto;
85
+ }
86
+ toModels(schemaCls, conversionSchema) {
87
+ const dto = this.toDTO();
84
88
  const clientRes = clientSideToModels(this.headers, this.rows || [], schemaCls);
85
89
  if (clientRes) {
86
90
  return clientRes;
@@ -89,56 +93,42 @@ export class Table {
89
93
  return res.map((x) => JSON.parse(x));
90
94
  }
91
95
  toMarkdown(schema) {
92
- const dto = { ...this };
93
- if (dto.metadata)
94
- dto.metadata = JSON.stringify(dto.metadata);
96
+ const dto = this.toDTO();
95
97
  const res = _tableToMarkdown(dto, schema);
96
98
  return res;
97
99
  }
98
100
  updateCell(rowIdx, colIdx, value) {
99
- const dto = { ...this };
100
- if (dto.metadata)
101
- dto.metadata = JSON.stringify(dto.metadata);
101
+ const dto = this.toDTO();
102
102
  const res = _tableUpdateCell(dto, rowIdx, colIdx, value);
103
103
  Object.assign(this, res);
104
104
  return this;
105
105
  }
106
106
  deleteRow(rowIdx) {
107
- const dto = { ...this };
108
- if (dto.metadata)
109
- dto.metadata = JSON.stringify(dto.metadata);
107
+ const dto = this.toDTO();
110
108
  const res = _tableDeleteRow(dto, rowIdx);
111
109
  Object.assign(this, res);
112
110
  return this;
113
111
  }
114
112
  deleteColumn(colIdx) {
115
- const dto = { ...this };
116
- if (dto.metadata)
117
- dto.metadata = JSON.stringify(dto.metadata);
113
+ const dto = this.toDTO();
118
114
  const res = _tableDeleteColumn(dto, colIdx);
119
115
  Object.assign(this, res);
120
116
  return this;
121
117
  }
122
118
  clearColumnData(colIdx) {
123
- const dto = { ...this };
124
- if (dto.metadata)
125
- dto.metadata = JSON.stringify(dto.metadata);
119
+ const dto = this.toDTO();
126
120
  const res = _tableClearColumnData(dto, colIdx);
127
121
  Object.assign(this, res);
128
122
  return this;
129
123
  }
130
124
  insertRow(rowIdx) {
131
- const dto = { ...this };
132
- if (dto.metadata)
133
- dto.metadata = JSON.stringify(dto.metadata);
125
+ const dto = this.toDTO();
134
126
  const res = _tableInsertRow(dto, rowIdx);
135
127
  Object.assign(this, res);
136
128
  return this;
137
129
  }
138
130
  insertColumn(colIdx) {
139
- const dto = { ...this };
140
- if (dto.metadata)
141
- dto.metadata = JSON.stringify(dto.metadata);
131
+ const dto = this.toDTO();
142
132
  const res = _tableInsertColumn(dto, colIdx);
143
133
  Object.assign(this, res);
144
134
  return this;
@@ -152,17 +142,21 @@ export class Sheet {
152
142
  this.metadata = (typeof data.metadata === 'string') ? JSON.parse(data.metadata) : data.metadata;
153
143
  }
154
144
  }
155
- getTable(name) {
145
+ toDTO() {
156
146
  const dto = { ...this };
147
+ if (dto.tables)
148
+ dto.tables = dto.tables.map((x) => x.toDTO ? x.toDTO() : x);
157
149
  if (dto.metadata)
158
150
  dto.metadata = JSON.stringify(dto.metadata);
151
+ return dto;
152
+ }
153
+ getTable(name) {
154
+ const dto = this.toDTO();
159
155
  const res = _sheetGetTable(dto, name);
160
- return res;
156
+ return res ? new Table(res) : undefined;
161
157
  }
162
158
  toMarkdown(schema) {
163
- const dto = { ...this };
164
- if (dto.metadata)
165
- dto.metadata = JSON.stringify(dto.metadata);
159
+ const dto = this.toDTO();
166
160
  const res = _sheetToMarkdown(dto, schema);
167
161
  return res;
168
162
  }
@@ -174,32 +168,32 @@ export class Workbook {
174
168
  this.metadata = (typeof data.metadata === 'string') ? JSON.parse(data.metadata) : data.metadata;
175
169
  }
176
170
  }
177
- getSheet(name) {
171
+ toDTO() {
178
172
  const dto = { ...this };
173
+ if (dto.sheets)
174
+ dto.sheets = dto.sheets.map((x) => x.toDTO ? x.toDTO() : x);
179
175
  if (dto.metadata)
180
176
  dto.metadata = JSON.stringify(dto.metadata);
177
+ return dto;
178
+ }
179
+ getSheet(name) {
180
+ const dto = this.toDTO();
181
181
  const res = _workbookGetSheet(dto, name);
182
- return res;
182
+ return res ? new Sheet(res) : undefined;
183
183
  }
184
184
  toMarkdown(schema) {
185
- const dto = { ...this };
186
- if (dto.metadata)
187
- dto.metadata = JSON.stringify(dto.metadata);
185
+ const dto = this.toDTO();
188
186
  const res = _workbookToMarkdown(dto, schema);
189
187
  return res;
190
188
  }
191
189
  addSheet(name) {
192
- const dto = { ...this };
193
- if (dto.metadata)
194
- dto.metadata = JSON.stringify(dto.metadata);
190
+ const dto = this.toDTO();
195
191
  const res = _workbookAddSheet(dto, name);
196
192
  Object.assign(this, res);
197
193
  return this;
198
194
  }
199
195
  deleteSheet(index) {
200
- const dto = { ...this };
201
- if (dto.metadata)
202
- dto.metadata = JSON.stringify(dto.metadata);
196
+ const dto = this.toDTO();
203
197
  const res = _workbookDeleteSheet(dto, index);
204
198
  Object.assign(this, res);
205
199
  return this;
@@ -215,6 +209,10 @@ export class ParsingSchema {
215
209
  this.convertBrToNewline = data.convertBrToNewline;
216
210
  }
217
211
  }
212
+ toDTO() {
213
+ const dto = { ...this };
214
+ return dto;
215
+ }
218
216
  }
219
217
  export class MultiTableParsingSchema {
220
218
  constructor(data) {
@@ -230,6 +228,10 @@ export class MultiTableParsingSchema {
230
228
  this.captureDescription = data.captureDescription;
231
229
  }
232
230
  }
231
+ toDTO() {
232
+ const dto = { ...this };
233
+ return dto;
234
+ }
233
235
  }
234
236
  export class ConversionSchema {
235
237
  constructor(data) {
@@ -239,6 +241,14 @@ export class ConversionSchema {
239
241
  this.fieldConverters = (typeof data.fieldConverters === 'string') ? JSON.parse(data.fieldConverters) : data.fieldConverters;
240
242
  }
241
243
  }
244
+ toDTO() {
245
+ const dto = { ...this };
246
+ if (dto.customConverters)
247
+ dto.customConverters = JSON.stringify(dto.customConverters);
248
+ if (dto.fieldConverters)
249
+ dto.fieldConverters = JSON.stringify(dto.fieldConverters);
250
+ return dto;
251
+ }
242
252
  }
243
253
  export class ExcelParsingSchema {
244
254
  constructor(data) {
@@ -249,4 +259,8 @@ export class ExcelParsingSchema {
249
259
  this.headerSeparator = data.headerSeparator;
250
260
  }
251
261
  }
262
+ toDTO() {
263
+ const dto = { ...this };
264
+ return dto;
265
+ }
252
266
  }
Binary file
package/dist/parser.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "md-spreadsheet-parser",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
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",
@@ -29,12 +29,12 @@
29
29
  "license": "MIT",
30
30
  "devDependencies": {
31
31
  "@bytecodealliance/jco": "^1.0.0",
32
- "@bytecodealliance/preview2-shim": "^0.17.0",
33
32
  "typescript": "^5.9.3",
34
33
  "zod": "^4.3.4"
35
34
  },
36
35
  "dependencies": {
36
+ "@bytecodealliance/preview2-shim": "^0.17.0",
37
37
  "execa": "^9.6.1",
38
38
  "shelljs": "^0.10.0"
39
39
  }
40
- }
40
+ }
Binary file
package/src/index.ts CHANGED
@@ -105,9 +105,14 @@ export class Table {
105
105
  }
106
106
  }
107
107
 
108
- toModels(schemaCls: any, conversionSchema?: any): any {
108
+ toDTO(): any {
109
109
  const dto = { ...this } as any;
110
110
  if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
111
+ return dto;
112
+ }
113
+
114
+ toModels(schemaCls: any, conversionSchema?: any): any {
115
+ const dto = this.toDTO();
111
116
  const clientRes = clientSideToModels(this.headers, this.rows || [], schemaCls);
112
117
  if (clientRes) {
113
118
  return clientRes;
@@ -117,55 +122,48 @@ export class Table {
117
122
  }
118
123
 
119
124
  toMarkdown(schema?: any): any {
120
- const dto = { ...this } as any;
121
- if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
125
+ const dto = this.toDTO();
122
126
  const res = _tableToMarkdown(dto, schema);
123
127
  return res;
124
128
  }
125
129
 
126
130
  updateCell(rowIdx: any, colIdx: any, value: any): any {
127
- const dto = { ...this } as any;
128
- if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
131
+ const dto = this.toDTO();
129
132
  const res = _tableUpdateCell(dto, rowIdx, colIdx, value);
130
133
  Object.assign(this, res);
131
134
  return this;
132
135
  }
133
136
 
134
137
  deleteRow(rowIdx: any): any {
135
- const dto = { ...this } as any;
136
- if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
138
+ const dto = this.toDTO();
137
139
  const res = _tableDeleteRow(dto, rowIdx);
138
140
  Object.assign(this, res);
139
141
  return this;
140
142
  }
141
143
 
142
144
  deleteColumn(colIdx: any): any {
143
- const dto = { ...this } as any;
144
- if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
145
+ const dto = this.toDTO();
145
146
  const res = _tableDeleteColumn(dto, colIdx);
146
147
  Object.assign(this, res);
147
148
  return this;
148
149
  }
149
150
 
150
151
  clearColumnData(colIdx: any): any {
151
- const dto = { ...this } as any;
152
- if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
152
+ const dto = this.toDTO();
153
153
  const res = _tableClearColumnData(dto, colIdx);
154
154
  Object.assign(this, res);
155
155
  return this;
156
156
  }
157
157
 
158
158
  insertRow(rowIdx: any): any {
159
- const dto = { ...this } as any;
160
- if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
159
+ const dto = this.toDTO();
161
160
  const res = _tableInsertRow(dto, rowIdx);
162
161
  Object.assign(this, res);
163
162
  return this;
164
163
  }
165
164
 
166
165
  insertColumn(colIdx: any): any {
167
- const dto = { ...this } as any;
168
- if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
166
+ const dto = this.toDTO();
169
167
  const res = _tableInsertColumn(dto, colIdx);
170
168
  Object.assign(this, res);
171
169
  return this;
@@ -185,16 +183,21 @@ export class Sheet {
185
183
  }
186
184
  }
187
185
 
188
- getTable(name: any): any {
186
+ toDTO(): any {
189
187
  const dto = { ...this } as any;
188
+ if (dto.tables) dto.tables = dto.tables.map((x: any) => x.toDTO ? x.toDTO() : x);
190
189
  if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
190
+ return dto;
191
+ }
192
+
193
+ getTable(name: any): any {
194
+ const dto = this.toDTO();
191
195
  const res = _sheetGetTable(dto, name);
192
- return res;
196
+ return res ? new Table(res) : undefined;
193
197
  }
194
198
 
195
199
  toMarkdown(schema?: any): any {
196
- const dto = { ...this } as any;
197
- if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
200
+ const dto = this.toDTO();
198
201
  const res = _sheetToMarkdown(dto, schema);
199
202
  return res;
200
203
  }
@@ -211,31 +214,34 @@ export class Workbook {
211
214
  }
212
215
  }
213
216
 
214
- getSheet(name: any): any {
217
+ toDTO(): any {
215
218
  const dto = { ...this } as any;
219
+ if (dto.sheets) dto.sheets = dto.sheets.map((x: any) => x.toDTO ? x.toDTO() : x);
216
220
  if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
221
+ return dto;
222
+ }
223
+
224
+ getSheet(name: any): any {
225
+ const dto = this.toDTO();
217
226
  const res = _workbookGetSheet(dto, name);
218
- return res;
227
+ return res ? new Sheet(res) : undefined;
219
228
  }
220
229
 
221
230
  toMarkdown(schema: any): any {
222
- const dto = { ...this } as any;
223
- if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
231
+ const dto = this.toDTO();
224
232
  const res = _workbookToMarkdown(dto, schema);
225
233
  return res;
226
234
  }
227
235
 
228
236
  addSheet(name: any): any {
229
- const dto = { ...this } as any;
230
- if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
237
+ const dto = this.toDTO();
231
238
  const res = _workbookAddSheet(dto, name);
232
239
  Object.assign(this, res);
233
240
  return this;
234
241
  }
235
242
 
236
243
  deleteSheet(index: any): any {
237
- const dto = { ...this } as any;
238
- if (dto.metadata) dto.metadata = JSON.stringify(dto.metadata);
244
+ const dto = this.toDTO();
239
245
  const res = _workbookDeleteSheet(dto, index);
240
246
  Object.assign(this, res);
241
247
  return this;
@@ -258,6 +264,11 @@ export class ParsingSchema {
258
264
  this.convertBrToNewline = data.convertBrToNewline;
259
265
  }
260
266
  }
267
+
268
+ toDTO(): any {
269
+ const dto = { ...this } as any;
270
+ return dto;
271
+ }
261
272
  }
262
273
 
263
274
  export class MultiTableParsingSchema {
@@ -284,6 +295,11 @@ export class MultiTableParsingSchema {
284
295
  this.captureDescription = data.captureDescription;
285
296
  }
286
297
  }
298
+
299
+ toDTO(): any {
300
+ const dto = { ...this } as any;
301
+ return dto;
302
+ }
287
303
  }
288
304
 
289
305
  export class ConversionSchema {
@@ -298,6 +314,13 @@ export class ConversionSchema {
298
314
  this.fieldConverters = (typeof data.fieldConverters === 'string') ? JSON.parse(data.fieldConverters) : data.fieldConverters;
299
315
  }
300
316
  }
317
+
318
+ toDTO(): any {
319
+ const dto = { ...this } as any;
320
+ if (dto.customConverters) dto.customConverters = JSON.stringify(dto.customConverters);
321
+ if (dto.fieldConverters) dto.fieldConverters = JSON.stringify(dto.fieldConverters);
322
+ return dto;
323
+ }
301
324
  }
302
325
 
303
326
  export class ExcelParsingSchema {
@@ -314,4 +337,9 @@ export class ExcelParsingSchema {
314
337
  this.headerSeparator = data.headerSeparator;
315
338
  }
316
339
  }
340
+
341
+ toDTO(): any {
342
+ const dto = { ...this } as any;
343
+ return dto;
344
+ }
317
345
  }