@iyulab/m3l-napi 0.4.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/index.d.ts +27 -0
- package/index.js +123 -0
- package/package.json +31 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parse a single M3L file and return the AST as JSON.
|
|
5
|
+
*
|
|
6
|
+
* @param content - M3L markdown text
|
|
7
|
+
* @param filename - Source filename for error reporting
|
|
8
|
+
* @returns JSON string with `{ success: boolean, data?: AST, error?: string }`
|
|
9
|
+
*/
|
|
10
|
+
export function parse(content: string, filename: string): string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Parse multiple M3L files and return the merged AST as JSON.
|
|
14
|
+
*
|
|
15
|
+
* @param filesJson - JSON array of `{ content: string, filename: string }` objects
|
|
16
|
+
* @returns JSON string with `{ success: boolean, data?: AST, error?: string }`
|
|
17
|
+
*/
|
|
18
|
+
export function parseMulti(filesJson: string): string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Validate M3L content and return diagnostics as JSON.
|
|
22
|
+
*
|
|
23
|
+
* @param content - M3L markdown text
|
|
24
|
+
* @param optionsJson - JSON options `{ strict?: boolean, filename?: string }`
|
|
25
|
+
* @returns JSON string with `{ success: boolean, data?: ValidateResult, error?: string }`
|
|
26
|
+
*/
|
|
27
|
+
export function validate(content: string, optionsJson: string): string;
|
package/index.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* auto-generated napi binding loader */
|
|
3
|
+
|
|
4
|
+
const { existsSync, readFileSync } = require('fs');
|
|
5
|
+
const { join } = require('path');
|
|
6
|
+
|
|
7
|
+
const { platform, arch } = process;
|
|
8
|
+
|
|
9
|
+
let nativeBinding = null;
|
|
10
|
+
let localFileExisted = false;
|
|
11
|
+
let loadError = null;
|
|
12
|
+
|
|
13
|
+
function isMusl() {
|
|
14
|
+
// Check if we're running on musl libc
|
|
15
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
16
|
+
try {
|
|
17
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim();
|
|
18
|
+
return readFileSync(lddPath, 'utf8').includes('musl');
|
|
19
|
+
} catch {
|
|
20
|
+
return true; // Default to musl if we can't check
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
const { glibcVersionRuntime } = process.report.getReport().header;
|
|
24
|
+
return !glibcVersionRuntime;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
switch (platform) {
|
|
29
|
+
case 'win32':
|
|
30
|
+
switch (arch) {
|
|
31
|
+
case 'x64':
|
|
32
|
+
localFileExisted = existsSync(join(__dirname, 'm3l-napi.win32-x64-msvc.node'));
|
|
33
|
+
try {
|
|
34
|
+
if (localFileExisted) {
|
|
35
|
+
nativeBinding = require('./m3l-napi.win32-x64-msvc.node');
|
|
36
|
+
} else {
|
|
37
|
+
nativeBinding = require('@iyulab/m3l-napi-win32-x64-msvc');
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
loadError = e;
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`);
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
case 'darwin':
|
|
48
|
+
switch (arch) {
|
|
49
|
+
case 'x64':
|
|
50
|
+
localFileExisted = existsSync(join(__dirname, 'm3l-napi.darwin-x64.node'));
|
|
51
|
+
try {
|
|
52
|
+
if (localFileExisted) {
|
|
53
|
+
nativeBinding = require('./m3l-napi.darwin-x64.node');
|
|
54
|
+
} else {
|
|
55
|
+
nativeBinding = require('@iyulab/m3l-napi-darwin-x64');
|
|
56
|
+
}
|
|
57
|
+
} catch (e) {
|
|
58
|
+
loadError = e;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
case 'arm64':
|
|
62
|
+
localFileExisted = existsSync(join(__dirname, 'm3l-napi.darwin-arm64.node'));
|
|
63
|
+
try {
|
|
64
|
+
if (localFileExisted) {
|
|
65
|
+
nativeBinding = require('./m3l-napi.darwin-arm64.node');
|
|
66
|
+
} else {
|
|
67
|
+
nativeBinding = require('@iyulab/m3l-napi-darwin-arm64');
|
|
68
|
+
}
|
|
69
|
+
} catch (e) {
|
|
70
|
+
loadError = e;
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`);
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case 'linux':
|
|
78
|
+
switch (arch) {
|
|
79
|
+
case 'x64':
|
|
80
|
+
if (isMusl()) {
|
|
81
|
+
localFileExisted = existsSync(join(__dirname, 'm3l-napi.linux-x64-musl.node'));
|
|
82
|
+
try {
|
|
83
|
+
if (localFileExisted) {
|
|
84
|
+
nativeBinding = require('./m3l-napi.linux-x64-musl.node');
|
|
85
|
+
} else {
|
|
86
|
+
nativeBinding = require('@iyulab/m3l-napi-linux-x64-musl');
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
loadError = e;
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
localFileExisted = existsSync(join(__dirname, 'm3l-napi.linux-x64-gnu.node'));
|
|
93
|
+
try {
|
|
94
|
+
if (localFileExisted) {
|
|
95
|
+
nativeBinding = require('./m3l-napi.linux-x64-gnu.node');
|
|
96
|
+
} else {
|
|
97
|
+
nativeBinding = require('@iyulab/m3l-napi-linux-x64-gnu');
|
|
98
|
+
}
|
|
99
|
+
} catch (e) {
|
|
100
|
+
loadError = e;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`);
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!nativeBinding) {
|
|
113
|
+
if (loadError) {
|
|
114
|
+
throw loadError;
|
|
115
|
+
}
|
|
116
|
+
throw new Error('Failed to load native binding');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const { parse, parseMulti, validate } = nativeBinding;
|
|
120
|
+
|
|
121
|
+
module.exports.parse = parse;
|
|
122
|
+
module.exports.parseMulti = parseMulti;
|
|
123
|
+
module.exports.validate = validate;
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@iyulab/m3l-napi",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "M3L parser Node.js native addon via napi-rs",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"napi": {
|
|
9
|
+
"binaryName": "m3l-napi",
|
|
10
|
+
"targets": [
|
|
11
|
+
"x86_64-pc-windows-msvc",
|
|
12
|
+
"x86_64-unknown-linux-gnu",
|
|
13
|
+
"x86_64-apple-darwin",
|
|
14
|
+
"aarch64-apple-darwin"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"index.js",
|
|
19
|
+
"index.d.ts"
|
|
20
|
+
],
|
|
21
|
+
"optionalDependencies": {
|
|
22
|
+
"@iyulab/m3l-napi-win32-x64-msvc": "0.4.1",
|
|
23
|
+
"@iyulab/m3l-napi-linux-x64-gnu": "0.4.1",
|
|
24
|
+
"@iyulab/m3l-napi-darwin-x64": "0.4.1",
|
|
25
|
+
"@iyulab/m3l-napi-darwin-arm64": "0.4.1"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/iyulab/m3l"
|
|
30
|
+
}
|
|
31
|
+
}
|