@mmobeus/luadata-wasm 0.1.13
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 +40 -0
- package/index.js +39 -0
- package/package.json +30 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for string length transformation.
|
|
3
|
+
*/
|
|
4
|
+
export interface StringTransformOptions {
|
|
5
|
+
/** Maximum string length before the transform is applied. */
|
|
6
|
+
maxLen: number;
|
|
7
|
+
/** Transform mode. Default: "truncate". */
|
|
8
|
+
mode?: "truncate" | "empty" | "redact" | "replace";
|
|
9
|
+
/** Replacement string (only used with mode "replace"). */
|
|
10
|
+
replacement?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Options for the convert function.
|
|
15
|
+
*/
|
|
16
|
+
export interface ConvertOptions {
|
|
17
|
+
/** How to render empty Lua tables. Default: "null". */
|
|
18
|
+
emptyTable?: "null" | "omit" | "array" | "object";
|
|
19
|
+
/** Array detection mode. Default: "sparse". */
|
|
20
|
+
arrayMode?: "none" | "index-only" | "sparse";
|
|
21
|
+
/** Maximum gap between integer keys for sparse array detection. Default: 20. */
|
|
22
|
+
arrayMaxGap?: number;
|
|
23
|
+
/** String length transformation options. */
|
|
24
|
+
stringTransform?: StringTransformOptions;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Initialize the WASM module. Must be called once before using convert().
|
|
29
|
+
*/
|
|
30
|
+
export function init(): Promise<void>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Convert a Lua data string to a JSON string.
|
|
34
|
+
*
|
|
35
|
+
* @param input - Lua data source text
|
|
36
|
+
* @param opts - Conversion options
|
|
37
|
+
* @returns JSON string
|
|
38
|
+
* @throws If the WASM module is not initialized or parsing fails
|
|
39
|
+
*/
|
|
40
|
+
export function convert(input: string, opts?: ConvertOptions): string;
|
package/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// mmobeus-luadata — Parse Lua data files and convert to JSON.
|
|
2
|
+
//
|
|
3
|
+
// Usage:
|
|
4
|
+
// import { init, convert } from "mmobeus-luadata";
|
|
5
|
+
// await init();
|
|
6
|
+
// const json = convert('playerName = "Thrall"');
|
|
7
|
+
|
|
8
|
+
import wasmInit, { convertLuaDataToJson } from "./wasm/luadata_wasm.js";
|
|
9
|
+
|
|
10
|
+
let initialized = false;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Initialize the WASM module. Must be called once before using convert().
|
|
14
|
+
*/
|
|
15
|
+
export async function init() {
|
|
16
|
+
if (initialized) return;
|
|
17
|
+
await wasmInit();
|
|
18
|
+
initialized = true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Convert a Lua data string to a JSON string.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} input - Lua data source text
|
|
25
|
+
* @param {ConvertOptions} [opts] - Conversion options
|
|
26
|
+
* @returns {string} JSON string
|
|
27
|
+
* @throws {Error} If the WASM module is not initialized or parsing fails
|
|
28
|
+
*/
|
|
29
|
+
export function convert(input, opts) {
|
|
30
|
+
if (!initialized) throw new Error("luadata WASM not initialized — call init() first");
|
|
31
|
+
|
|
32
|
+
const hasOpts = opts && Object.keys(opts).length > 0;
|
|
33
|
+
const res = hasOpts
|
|
34
|
+
? convertLuaDataToJson(input, opts)
|
|
35
|
+
: convertLuaDataToJson(input);
|
|
36
|
+
|
|
37
|
+
if (res.error) throw new Error(res.error);
|
|
38
|
+
return res.result;
|
|
39
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mmobeus/luadata-wasm",
|
|
3
|
+
"version": "0.1.13",
|
|
4
|
+
"description": "Parse Lua data files and convert to JSON (WebAssembly)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js",
|
|
10
|
+
"index.d.ts",
|
|
11
|
+
"wasm/luadata_wasm_bg.wasm",
|
|
12
|
+
"wasm/luadata_wasm.js",
|
|
13
|
+
"wasm/luadata_wasm.d.ts"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"lua",
|
|
17
|
+
"json",
|
|
18
|
+
"parser",
|
|
19
|
+
"wow",
|
|
20
|
+
"savedvariables",
|
|
21
|
+
"wasm",
|
|
22
|
+
"webassembly"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/mmobeus/luadata"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://mmobeus.github.io/luadata/"
|
|
30
|
+
}
|