@mmobeus/luadata-wasm 0.1.13 → 0.1.15
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/README.md +53 -0
- package/index.js +2 -2
- package/package.json +3 -2
- package/wasm/luadata_wasm.d.ts +10 -0
- package/wasm/luadata_wasm.js +9 -0
- package/wasm/luadata_wasm_bg.wasm +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @mmobeus/luadata-wasm
|
|
2
|
+
|
|
3
|
+
WebAssembly build of luadata for parsing Lua data files and converting to JSON. Designed for browser projects using a bundler (webpack, vite, etc.).
|
|
4
|
+
|
|
5
|
+
For Node.js usage without a bundler, use [`@mmobeus/luadata`](https://www.npmjs.com/package/@mmobeus/luadata) instead.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install @mmobeus/luadata-wasm
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { init, convert } from "@mmobeus/luadata-wasm";
|
|
17
|
+
|
|
18
|
+
// Initialize the WASM module (call once before convert)
|
|
19
|
+
await init();
|
|
20
|
+
|
|
21
|
+
// Convert Lua data to a JSON string
|
|
22
|
+
const json = convert('playerName = "Thrall"');
|
|
23
|
+
|
|
24
|
+
// Parse into an object
|
|
25
|
+
const data = JSON.parse(convert(luaString));
|
|
26
|
+
|
|
27
|
+
// With options
|
|
28
|
+
const json = convert(luaString, {
|
|
29
|
+
emptyTable: "array",
|
|
30
|
+
arrayMode: "sparse",
|
|
31
|
+
arrayMaxGap: 10,
|
|
32
|
+
stringTransform: { maxLen: 1024, mode: "truncate" },
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`init()` must be called once before `convert()` — it loads the WASM module. TypeScript type definitions are included.
|
|
37
|
+
|
|
38
|
+
## Options
|
|
39
|
+
|
|
40
|
+
The `convert` function accepts an optional options object with four groups:
|
|
41
|
+
|
|
42
|
+
- **Schema** (`schema`, `unknownFields`) — provide a JSON Schema string to guide type decisions, overriding heuristics
|
|
43
|
+
- **String transform** — limit string length during parsing (`truncate`, `empty`, `redact`, `replace`)
|
|
44
|
+
- **Array detection** — control how integer-keyed Lua tables map to JSON arrays (`sparse`, `index-only`, `none`)
|
|
45
|
+
- **Empty tables** — choose how empty Lua tables render in JSON (`null`, `omit`, `array`, `object`)
|
|
46
|
+
|
|
47
|
+
See the [full options documentation](https://github.com/mmobeus/luadata#options) for details and examples.
|
|
48
|
+
|
|
49
|
+
## Links
|
|
50
|
+
|
|
51
|
+
- [Luadata by Example](https://mmobeus.github.io/luadata/docs/) — guided tour with interactive examples
|
|
52
|
+
- [Live Converter](https://mmobeus.github.io/luadata/) — try it in your browser
|
|
53
|
+
- [GitHub](https://github.com/mmobeus/luadata)
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// mmobeus-
|
|
1
|
+
// @mmobeus/luadata-wasm — Parse Lua data files and convert to JSON.
|
|
2
2
|
//
|
|
3
3
|
// Usage:
|
|
4
|
-
// import { init, convert } from "mmobeus-
|
|
4
|
+
// import { init, convert } from "@mmobeus/luadata-wasm";
|
|
5
5
|
// await init();
|
|
6
6
|
// const json = convert('playerName = "Thrall"');
|
|
7
7
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mmobeus/luadata-wasm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Parse Lua data files and convert to JSON (WebAssembly)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"index.d.ts",
|
|
11
11
|
"wasm/luadata_wasm_bg.wasm",
|
|
12
12
|
"wasm/luadata_wasm.js",
|
|
13
|
-
"wasm/luadata_wasm.d.ts"
|
|
13
|
+
"wasm/luadata_wasm.d.ts",
|
|
14
|
+
"README.md"
|
|
14
15
|
],
|
|
15
16
|
"keywords": [
|
|
16
17
|
"lua",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert Lua data to JSON.
|
|
6
|
+
*
|
|
7
|
+
* Takes a Lua data string and an optional options object.
|
|
8
|
+
* Returns a JS object with either `result` (JSON string) or `error` (message).
|
|
9
|
+
*/
|
|
10
|
+
export function convertLuaDataToJson(input: string, opts: any): any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./luadata_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
import * as wasm from "./luadata_wasm_bg.wasm";
|
|
4
|
+
import { __wbg_set_wasm } from "./luadata_wasm_bg.js";
|
|
5
|
+
__wbg_set_wasm(wasm);
|
|
6
|
+
wasm.__wbindgen_start();
|
|
7
|
+
export {
|
|
8
|
+
convertLuaDataToJson
|
|
9
|
+
} from "./luadata_wasm_bg.js";
|
|
Binary file
|