md-spreadsheet-parser 1.1.6 → 1.1.7
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
|
@@ -10,9 +10,9 @@ export declare function scanTables(markdown: any, schema?: any): any;
|
|
|
10
10
|
export declare function generateTableMarkdown(table: any, schema?: any): any;
|
|
11
11
|
export declare function generateSheetMarkdown(sheet: any, schema?: any): any;
|
|
12
12
|
export declare function generateWorkbookMarkdown(workbook: any, schema: any): any;
|
|
13
|
-
export declare function parseTableFromFile(source: any, schema?: any): any
|
|
14
|
-
export declare function parseWorkbookFromFile(source: any, schema?: any): any
|
|
15
|
-
export declare function scanTablesFromFile(source: any, schema?: any): any
|
|
13
|
+
export declare function parseTableFromFile(source: any, schema?: any): Promise<any>;
|
|
14
|
+
export declare function parseWorkbookFromFile(source: any, schema?: any): Promise<any>;
|
|
15
|
+
export declare function scanTablesFromFile(source: any, schema?: any): Promise<any>;
|
|
16
16
|
export declare function scanTablesIter(source: any, schema?: any): any;
|
|
17
17
|
export declare class Table {
|
|
18
18
|
headers: any | undefined;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,43 @@
|
|
|
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';
|
|
8
2
|
import { clientSideToModels } from './client-adapters.js';
|
|
9
|
-
//
|
|
10
|
-
|
|
3
|
+
// Environment detection
|
|
4
|
+
// @ts-ignore - process may not be defined in browser
|
|
5
|
+
const isNode = typeof process !== 'undefined'
|
|
6
|
+
&& typeof process.versions !== 'undefined'
|
|
7
|
+
&& typeof process.versions.node !== 'undefined';
|
|
8
|
+
// Lazily loaded Node.js modules (only in Node.js environment)
|
|
9
|
+
let _pathModule = null;
|
|
10
|
+
let _nodeInitialized = false;
|
|
11
|
+
/**
|
|
12
|
+
* Ensures Node.js environment is initialized for file system operations.
|
|
13
|
+
* Throws an error in browser environments.
|
|
14
|
+
*/
|
|
15
|
+
async function ensureNodeEnvironment() {
|
|
16
|
+
if (!isNode) {
|
|
17
|
+
throw new Error('File system operations (parseTableFromFile, parseWorkbookFromFile, scanTablesFromFile) ' +
|
|
18
|
+
'are not supported in browser environments. ' +
|
|
19
|
+
'Use parseTable(), parseWorkbook(), or scanTables() with string content instead.');
|
|
20
|
+
}
|
|
21
|
+
if (_nodeInitialized)
|
|
22
|
+
return;
|
|
23
|
+
// Dynamic imports for Node.js only
|
|
24
|
+
const [pathModule, processModule, fsShim] = await Promise.all([
|
|
25
|
+
import('node:path'),
|
|
26
|
+
import('node:process'),
|
|
27
|
+
import('@bytecodealliance/preview2-shim/filesystem')
|
|
28
|
+
]);
|
|
29
|
+
_pathModule = pathModule.default || pathModule;
|
|
30
|
+
const proc = processModule.default || processModule;
|
|
31
|
+
const root = _pathModule.parse(proc.cwd()).root;
|
|
32
|
+
// @ts-ignore - _addPreopen is an internal function
|
|
33
|
+
fsShim._addPreopen('/', root);
|
|
34
|
+
_nodeInitialized = true;
|
|
35
|
+
}
|
|
11
36
|
function resolveToVirtualPath(p) {
|
|
12
|
-
|
|
37
|
+
if (!_pathModule) {
|
|
38
|
+
throw new Error('Node.js modules not initialized. Call ensureNodeEnvironment() first.');
|
|
39
|
+
}
|
|
40
|
+
return _pathModule.resolve(p);
|
|
13
41
|
}
|
|
14
42
|
export function cleanCell(cell, schema) {
|
|
15
43
|
const res = _cleanCell(cell, schema);
|
|
@@ -59,17 +87,20 @@ export function generateWorkbookMarkdown(workbook, schema) {
|
|
|
59
87
|
const res = _generateWorkbookMarkdown(workbook, schema);
|
|
60
88
|
return res;
|
|
61
89
|
}
|
|
62
|
-
export function parseTableFromFile(source, schema) {
|
|
90
|
+
export async function parseTableFromFile(source, schema) {
|
|
91
|
+
await ensureNodeEnvironment();
|
|
63
92
|
const source_resolved = resolveToVirtualPath(source);
|
|
64
93
|
const res = _parseTableFromFile(source_resolved, schema);
|
|
65
94
|
return new Table(res);
|
|
66
95
|
}
|
|
67
|
-
export function parseWorkbookFromFile(source, schema) {
|
|
96
|
+
export async function parseWorkbookFromFile(source, schema) {
|
|
97
|
+
await ensureNodeEnvironment();
|
|
68
98
|
const source_resolved = resolveToVirtualPath(source);
|
|
69
99
|
const res = _parseWorkbookFromFile(source_resolved, schema);
|
|
70
100
|
return new Workbook(res);
|
|
71
101
|
}
|
|
72
|
-
export function scanTablesFromFile(source, schema) {
|
|
102
|
+
export async function scanTablesFromFile(source, schema) {
|
|
103
|
+
await ensureNodeEnvironment();
|
|
73
104
|
const source_resolved = resolveToVirtualPath(source);
|
|
74
105
|
const res = _scanTablesFromFile(source_resolved, schema);
|
|
75
106
|
return res.map((x) => new Table(x));
|
package/dist/parser.core.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "md-spreadsheet-parser",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
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,6 +29,7 @@
|
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@bytecodealliance/jco": "^1.0.0",
|
|
32
|
+
"@types/node": "^25.0.3",
|
|
32
33
|
"typescript": "^5.9.3",
|
|
33
34
|
"zod": "^4.3.4"
|
|
34
35
|
},
|
|
Binary file
|
|
Binary file
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,50 @@
|
|
|
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';
|
|
8
2
|
import { clientSideToModels } from './client-adapters.js';
|
|
9
3
|
|
|
10
|
-
//
|
|
11
|
-
|
|
4
|
+
// Environment detection
|
|
5
|
+
// @ts-ignore - process may not be defined in browser
|
|
6
|
+
const isNode = typeof process !== 'undefined'
|
|
7
|
+
&& typeof process.versions !== 'undefined'
|
|
8
|
+
&& typeof process.versions.node !== 'undefined';
|
|
9
|
+
|
|
10
|
+
// Lazily loaded Node.js modules (only in Node.js environment)
|
|
11
|
+
let _pathModule: any = null;
|
|
12
|
+
let _nodeInitialized = false;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Ensures Node.js environment is initialized for file system operations.
|
|
16
|
+
* Throws an error in browser environments.
|
|
17
|
+
*/
|
|
18
|
+
async function ensureNodeEnvironment(): Promise<void> {
|
|
19
|
+
if (!isNode) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
'File system operations (parseTableFromFile, parseWorkbookFromFile, scanTablesFromFile) ' +
|
|
22
|
+
'are not supported in browser environments. ' +
|
|
23
|
+
'Use parseTable(), parseWorkbook(), or scanTables() with string content instead.'
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
if (_nodeInitialized) return;
|
|
27
|
+
|
|
28
|
+
// Dynamic imports for Node.js only
|
|
29
|
+
const [pathModule, processModule, fsShim] = await Promise.all([
|
|
30
|
+
import('node:path'),
|
|
31
|
+
import('node:process'),
|
|
32
|
+
import('@bytecodealliance/preview2-shim/filesystem')
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
_pathModule = pathModule.default || pathModule;
|
|
36
|
+
const proc = processModule.default || processModule;
|
|
37
|
+
const root = _pathModule.parse(proc.cwd()).root;
|
|
38
|
+
// @ts-ignore - _addPreopen is an internal function
|
|
39
|
+
(fsShim as any)._addPreopen('/', root);
|
|
40
|
+
_nodeInitialized = true;
|
|
41
|
+
}
|
|
12
42
|
|
|
13
|
-
function resolveToVirtualPath(p: string) {
|
|
14
|
-
|
|
43
|
+
function resolveToVirtualPath(p: string): string {
|
|
44
|
+
if (!_pathModule) {
|
|
45
|
+
throw new Error('Node.js modules not initialized. Call ensureNodeEnvironment() first.');
|
|
46
|
+
}
|
|
47
|
+
return _pathModule.resolve(p);
|
|
15
48
|
}
|
|
16
49
|
|
|
17
50
|
export function cleanCell(cell: any, schema: any): any {
|
|
@@ -74,19 +107,22 @@ export function generateWorkbookMarkdown(workbook: any, schema: any): any {
|
|
|
74
107
|
return res;
|
|
75
108
|
}
|
|
76
109
|
|
|
77
|
-
export function parseTableFromFile(source: any, schema?: any): any {
|
|
110
|
+
export async function parseTableFromFile(source: any, schema?: any): Promise<any> {
|
|
111
|
+
await ensureNodeEnvironment();
|
|
78
112
|
const source_resolved = resolveToVirtualPath(source);
|
|
79
113
|
const res = _parseTableFromFile(source_resolved, schema);
|
|
80
114
|
return new Table(res);
|
|
81
115
|
}
|
|
82
116
|
|
|
83
|
-
export function parseWorkbookFromFile(source: any, schema?: any): any {
|
|
117
|
+
export async function parseWorkbookFromFile(source: any, schema?: any): Promise<any> {
|
|
118
|
+
await ensureNodeEnvironment();
|
|
84
119
|
const source_resolved = resolveToVirtualPath(source);
|
|
85
120
|
const res = _parseWorkbookFromFile(source_resolved, schema);
|
|
86
121
|
return new Workbook(res);
|
|
87
122
|
}
|
|
88
123
|
|
|
89
|
-
export function scanTablesFromFile(source: any, schema?: any): any {
|
|
124
|
+
export async function scanTablesFromFile(source: any, schema?: any): Promise<any> {
|
|
125
|
+
await ensureNodeEnvironment();
|
|
90
126
|
const source_resolved = resolveToVirtualPath(source);
|
|
91
127
|
const res = _scanTablesFromFile(source_resolved, schema);
|
|
92
128
|
return res.map((x: any) => new Table(x));
|