toon-ld 0.1.1 → 0.1.2

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 ADDED
@@ -0,0 +1,333 @@
1
+ # toon-ld
2
+
3
+ [![npm](https://img.shields.io/npm/v/toon-ld)](https://www.npmjs.com/package/toon-ld)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ **Token-Oriented Object Notation for Linked Data** — A compact RDF serialization format that achieves 40-60% token reduction compared to JSON-LD, making it ideal for LLM applications and bandwidth-constrained environments.
7
+
8
+ TOON-LD extends TOON in the same way that JSON-LD extends JSON: **every valid TOON-LD document is also a valid TOON document**. Base TOON parsers can process TOON-LD without modification, while TOON-LD processors interpret `@-prefixed` keys according to JSON-LD semantics.
9
+
10
+ ## Features
11
+
12
+ - **40-60% Token Reduction**: Fewer tokens means lower LLM costs and more data in context windows
13
+ - **Full JSON-LD Compatibility**: Round-trip conversion without data loss
14
+ - **Tabular Arrays**: Serialize arrays of objects as CSV-like rows with shared headers
15
+ - **All JSON-LD 1.1 Keywords**: Complete support for `@context`, `@graph`, `@id`, `@type`, value nodes, etc.
16
+ - **WebAssembly Performance**: Compiled from Rust for near-native speed
17
+ - **TypeScript Support**: Fully typed API with excellent IDE support
18
+ - **Browser & Node.js**: Works in both environments
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install toon-ld
24
+ ```
25
+
26
+ Or with yarn:
27
+
28
+ ```bash
29
+ yarn add toon-ld
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ```javascript
35
+ import { convert_jsonld_to_toon, convert_toon_to_jsonld } from 'toon-ld';
36
+
37
+ // Convert JSON-LD to TOON-LD
38
+ const jsonLd = JSON.stringify({
39
+ "@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
40
+ "foaf:name": "Alice",
41
+ "foaf:age": 30
42
+ });
43
+
44
+ const toon = convert_jsonld_to_toon(jsonLd);
45
+ console.log(toon);
46
+ // Output:
47
+ // @context:
48
+ // foaf: http://xmlns.com/foaf/0.1/
49
+ // foaf:name: Alice
50
+ // foaf:age: 30
51
+
52
+ // Convert back to JSON-LD
53
+ const backToJson = convert_toon_to_jsonld(toon);
54
+ const parsed = JSON.parse(backToJson);
55
+ console.log(parsed);
56
+ ```
57
+
58
+ ## Tabular Arrays - The Key Feature
59
+
60
+ TOON-LD's most powerful feature is efficient serialization of arrays of objects:
61
+
62
+ **JSON-LD (repetitive keys):**
63
+ ```json
64
+ {
65
+ "@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
66
+ "@graph": [
67
+ {"@id": "ex:1", "@type": "foaf:Person", "foaf:name": "Alice", "foaf:age": 30},
68
+ {"@id": "ex:2", "@type": "foaf:Person", "foaf:name": "Bob", "foaf:age": 25},
69
+ {"@id": "ex:3", "@type": "foaf:Person", "foaf:name": "Carol", "foaf:age": 28}
70
+ ]
71
+ }
72
+ ```
73
+
74
+ **TOON-LD (shared headers):**
75
+ ```
76
+ @context:
77
+ foaf: http://xmlns.com/foaf/0.1/
78
+ @graph[3]{@id,@type,foaf:age,foaf:name}:
79
+ ex:1, foaf:Person, 30, Alice
80
+ ex:2, foaf:Person, 25, Bob
81
+ ex:3, foaf:Person, 28, Carol
82
+ ```
83
+
84
+ Notice how object keys appear once in the header instead of repeating for each object.
85
+
86
+ ## API Reference
87
+
88
+ ### `convert_jsonld_to_toon(json: string): string`
89
+
90
+ Convert a JSON-LD string to TOON-LD format.
91
+
92
+ **Parameters:**
93
+ - `json` - A JSON or JSON-LD formatted string
94
+
95
+ **Returns:**
96
+ - TOON-LD formatted string
97
+
98
+ **Throws:**
99
+ - Error with message if the input is invalid JSON
100
+
101
+ **Example:**
102
+ ```javascript
103
+ const jsonLd = '{"@context": {"foaf": "http://xmlns.com/foaf/0.1/"}, "foaf:name": "Alice"}';
104
+ const toon = convert_jsonld_to_toon(jsonLd);
105
+ ```
106
+
107
+ ### `convert_toon_to_jsonld(toon: string): string`
108
+
109
+ Convert a TOON-LD string to JSON-LD format.
110
+
111
+ **Parameters:**
112
+ - `toon` - A TOON-LD formatted string
113
+
114
+ **Returns:**
115
+ - JSON-LD formatted string (pretty-printed)
116
+
117
+ **Throws:**
118
+ - Error with message if the input is invalid TOON-LD
119
+
120
+ **Example:**
121
+ ```javascript
122
+ const toon = `@context:
123
+ foaf: http://xmlns.com/foaf/0.1/
124
+ foaf:name: Alice`;
125
+ const jsonLd = convert_toon_to_jsonld(toon);
126
+ ```
127
+
128
+ ### `validate_json(json: string): boolean`
129
+
130
+ Validate a JSON-LD string.
131
+
132
+ **Parameters:**
133
+ - `json` - A JSON or JSON-LD formatted string
134
+
135
+ **Returns:**
136
+ - `true` if the string is valid JSON, `false` otherwise
137
+
138
+ **Example:**
139
+ ```javascript
140
+ const isValid = validate_json('{"name": "Alice"}');
141
+ console.log(isValid); // true
142
+ ```
143
+
144
+ ### `validate_toon(toon: string): boolean`
145
+
146
+ Validate a TOON-LD string.
147
+
148
+ **Parameters:**
149
+ - `toon` - A TOON-LD formatted string
150
+
151
+ **Returns:**
152
+ - `true` if the string is valid TOON-LD, `false` otherwise
153
+
154
+ **Example:**
155
+ ```javascript
156
+ const isValid = validate_toon('name: Alice');
157
+ console.log(isValid); // true
158
+ ```
159
+
160
+ ### `init(): void`
161
+
162
+ Initialize panic hook for better error messages in the browser console. This is optional but recommended for development.
163
+
164
+ **Example:**
165
+ ```javascript
166
+ import { init } from 'toon-ld';
167
+
168
+ init(); // Call once at app startup
169
+ ```
170
+
171
+ ## TypeScript Support
172
+
173
+ This package includes TypeScript type definitions out of the box:
174
+
175
+ ```typescript
176
+ import {
177
+ convert_jsonld_to_toon,
178
+ convert_toon_to_jsonld,
179
+ validate_json,
180
+ validate_toon
181
+ } from 'toon-ld';
182
+
183
+ const jsonLd: string = '{"name": "Alice"}';
184
+ const toon: string = convert_jsonld_to_toon(jsonLd);
185
+ const isValid: boolean = validate_toon(toon);
186
+ ```
187
+
188
+ ## Usage Examples
189
+
190
+ ### With Express.js
191
+
192
+ ```javascript
193
+ import express from 'express';
194
+ import { convert_jsonld_to_toon, convert_toon_to_jsonld } from 'toon-ld';
195
+
196
+ const app = express();
197
+ app.use(express.text({ type: 'text/toon' }));
198
+
199
+ app.post('/convert/to-toon', (req, res) => {
200
+ try {
201
+ const toon = convert_jsonld_to_toon(req.body);
202
+ res.type('text/toon').send(toon);
203
+ } catch (error) {
204
+ res.status(400).json({ error: error.message });
205
+ }
206
+ });
207
+
208
+ app.post('/convert/to-jsonld', (req, res) => {
209
+ try {
210
+ const jsonLd = convert_toon_to_jsonld(req.body);
211
+ res.json(JSON.parse(jsonLd));
212
+ } catch (error) {
213
+ res.status(400).json({ error: error.message });
214
+ }
215
+ });
216
+ ```
217
+
218
+ ### In the Browser
219
+
220
+ ```html
221
+ <!DOCTYPE html>
222
+ <html>
223
+ <head>
224
+ <title>TOON-LD Converter</title>
225
+ </head>
226
+ <body>
227
+ <script type="module">
228
+ import { convert_jsonld_to_toon, init } from 'https://unpkg.com/toon-ld';
229
+
230
+ init(); // Better error messages
231
+
232
+ const jsonLd = JSON.stringify({
233
+ "@context": {"schema": "http://schema.org/"},
234
+ "schema:name": "Example"
235
+ });
236
+
237
+ const toon = convert_jsonld_to_toon(jsonLd);
238
+ console.log(toon);
239
+ </script>
240
+ </body>
241
+ </html>
242
+ ```
243
+
244
+ ### Value Nodes with Language Tags
245
+
246
+ ```javascript
247
+ const jsonLd = JSON.stringify({
248
+ "@context": {
249
+ "dc": "http://purl.org/dc/terms/"
250
+ },
251
+ "dc:title": [
252
+ {"@value": "Bonjour", "@language": "fr"},
253
+ {"@value": "Hello", "@language": "en"}
254
+ ]
255
+ });
256
+
257
+ const toon = convert_jsonld_to_toon(jsonLd);
258
+ console.log(toon);
259
+ // Output:
260
+ // @context:
261
+ // dc: http://purl.org/dc/terms/
262
+ // dc:title[2]{@value,@language}:
263
+ // Bonjour,fr
264
+ // Hello,en
265
+ ```
266
+
267
+ ### Error Handling
268
+
269
+ ```javascript
270
+ import { convert_toon_to_jsonld } from 'toon-ld';
271
+
272
+ try {
273
+ const result = convert_toon_to_jsonld("invalid: [unclosed");
274
+ } catch (error) {
275
+ console.error("Conversion failed:", error.message);
276
+ // Error message includes line numbers and helpful context
277
+ }
278
+ ```
279
+
280
+ ## Performance & Benchmarks
281
+
282
+ Real-world token savings across different dataset sizes:
283
+
284
+ | Records | JSON-LD Size | TOON-LD Size | Size Saved | Tokens Saved |
285
+ |---------|--------------|--------------|------------|--------------|
286
+ | 10 | 2,249 B | 1,425 B | **36.6%** | **51.6%** |
287
+ | 100 | 20,208 B | 11,375 B | **43.7%** | **57.8%** |
288
+ | 1,000 | 202,497 B | 113,565 B | **43.9%** | **58.5%** |
289
+ | 10,000 | 2,052,356 B | 1,162,425 B | **43.4%** | **58.6%** |
290
+
291
+ Token savings scale well and are especially valuable for LLM context windows.
292
+
293
+ ## Cross-Platform Support
294
+
295
+ TOON-LD is also available for:
296
+ - **Rust**: `cargo add toon-ld` - [crates.io](https://crates.io/crates/toon-ld)
297
+ - **Python**: `pip install toon-ld` - [PyPI](https://pypi.org/project/toon-ld/)
298
+ - **CLI**: `cargo install toon-cli` - Command-line conversion tool
299
+
300
+ ## Documentation
301
+
302
+ - **[Full Specification](https://github.com/argahsuknesib/toon-ld)** - Complete TOON-LD specification
303
+ - **[GitHub Repository](https://github.com/argahsuknesib/toon-ld)** - Source code and examples
304
+ - **[API Documentation](https://github.com/argahsuknesib/toon-ld#readme)** - Detailed guides
305
+
306
+ ## Browser Compatibility
307
+
308
+ This package uses WebAssembly and requires:
309
+ - Chrome/Edge 57+
310
+ - Firefox 52+
311
+ - Safari 11+
312
+ - Node.js 12+
313
+
314
+ ## Contributing
315
+
316
+ Contributions are welcome! Please see the [Contributing Guide](https://github.com/argahsuknesib/toon-ld/blob/main/CONTRIBUTING.md) for details.
317
+
318
+ ## License
319
+
320
+ MIT License - See [LICENSE](https://github.com/argahsuknesib/toon-ld/blob/main/LICENSE) for details.
321
+
322
+ ## Citation
323
+
324
+ If you use TOON-LD in your research, please cite:
325
+
326
+ ```bibtex
327
+ @software{toon-ld,
328
+ title = {TOON-LD: Token-Oriented Object Notation for Linked Data},
329
+ author = {Bisen, Kushagra Singh},
330
+ year = {2025},
331
+ url = {https://github.com/argahsuknesib/toon-ld}
332
+ }
333
+ ```
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "toon-ld",
3
- "version": "0.1.1",
4
- "description": "High-performance serializer/parser for TOON-LD (Token-Oriented Object Notation for Linked Data)",
5
- "main": "toon_wasm.js",
6
- "types": "toon_wasm.d.ts",
7
- "module": "toon_wasm.js",
8
- "sideEffects": false,
3
+ "type": "module",
4
+ "collaborators": [
5
+ "Kush Bisen"
6
+ ],
7
+ "description": "WASM bindings for TOON-LD serializer/parser",
8
+ "version": "0.1.2",
9
+ "license": "MIT",
9
10
  "repository": {
10
11
  "type": "git",
11
- "url": "https://github.com/toon-ld/toon-ld"
12
+ "url": "https://github.com/argahsuknesib/toon-ld"
12
13
  },
14
+ "homepage": "https://github.com/argahsuknesib/toon-ld#readme",
13
15
  "keywords": [
14
16
  "toon",
15
17
  "json-ld",
@@ -17,26 +19,17 @@
17
19
  "linked-data",
18
20
  "serialization",
19
21
  "wasm",
20
- "webassembly",
21
- "rust"
22
+ "webassembly"
22
23
  ],
23
- "author": "TOON-LD Contributors",
24
- "license": "MIT",
25
- "bugs": {
26
- "url": "https://github.com/toon-ld/toon-ld/issues"
27
- },
28
- "homepage": "https://github.com/toon-ld/toon-ld#readme",
29
24
  "files": [
30
25
  "toon_wasm_bg.wasm",
31
- "toon_wasm_bg.wasm.d.ts",
32
26
  "toon_wasm.js",
33
27
  "toon_wasm.d.ts",
34
- "snippets/**/*"
28
+ "README.md"
35
29
  ],
36
- "exports": {
37
- ".": {
38
- "import": "./toon_wasm.js",
39
- "types": "./toon_wasm.d.ts"
40
- }
41
- }
30
+ "main": "toon_wasm.js",
31
+ "types": "toon_wasm.d.ts",
32
+ "sideEffects": [
33
+ "./snippets/*"
34
+ ]
42
35
  }
package/toon_wasm.d.ts ADDED
@@ -0,0 +1,94 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Convert JSON-LD string to TOON-LD format
6
+ *
7
+ * # Arguments
8
+ * * `json` - A JSON or JSON-LD formatted string
9
+ *
10
+ * # Returns
11
+ * * TOON-LD formatted string on success
12
+ * * Error message on failure
13
+ */
14
+ export function convert_jsonld_to_toon(json: string): string;
15
+
16
+ /**
17
+ * Convert TOON-LD string to JSON-LD format
18
+ *
19
+ * # Arguments
20
+ * * `toon` - A TOON-LD formatted string
21
+ *
22
+ * # Returns
23
+ * * JSON-LD formatted string (pretty-printed) on success
24
+ * * Error message on failure
25
+ */
26
+ export function convert_toon_to_jsonld(toon: string): string;
27
+
28
+ /**
29
+ * Initialize panic hook for better error messages in browser console
30
+ */
31
+ export function init(): void;
32
+
33
+ /**
34
+ * Validate a JSON-LD string
35
+ *
36
+ * # Arguments
37
+ * * `json` - A JSON or JSON-LD formatted string
38
+ *
39
+ * # Returns
40
+ * * `true` if the string is valid JSON
41
+ * * `false` otherwise
42
+ */
43
+ export function validate_json(json: string): boolean;
44
+
45
+ /**
46
+ * Validate a TOON-LD string
47
+ *
48
+ * # Arguments
49
+ * * `toon` - A TOON-LD formatted string
50
+ *
51
+ * # Returns
52
+ * * `true` if the string is valid TOON-LD
53
+ * * `false` otherwise
54
+ */
55
+ export function validate_toon(toon: string): boolean;
56
+
57
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
58
+
59
+ export interface InitOutput {
60
+ readonly memory: WebAssembly.Memory;
61
+ readonly init: () => void;
62
+ readonly convert_jsonld_to_toon: (a: number, b: number) => [number, number, number, number];
63
+ readonly convert_toon_to_jsonld: (a: number, b: number) => [number, number, number, number];
64
+ readonly validate_toon: (a: number, b: number) => number;
65
+ readonly validate_json: (a: number, b: number) => number;
66
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
67
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
68
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
69
+ readonly __wbindgen_externrefs: WebAssembly.Table;
70
+ readonly __externref_table_dealloc: (a: number) => void;
71
+ readonly __wbindgen_start: () => void;
72
+ }
73
+
74
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
75
+
76
+ /**
77
+ * Instantiates the given `module`, which can either be bytes or
78
+ * a precompiled `WebAssembly.Module`.
79
+ *
80
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
81
+ *
82
+ * @returns {InitOutput}
83
+ */
84
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
85
+
86
+ /**
87
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
88
+ * for everything else, calls `WebAssembly.instantiate` directly.
89
+ *
90
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
91
+ *
92
+ * @returns {Promise<InitOutput>}
93
+ */
94
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/toon_wasm.js ADDED
@@ -0,0 +1,340 @@
1
+ let wasm;
2
+
3
+ let cachedDataViewMemory0 = null;
4
+ function getDataViewMemory0() {
5
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
6
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
7
+ }
8
+ return cachedDataViewMemory0;
9
+ }
10
+
11
+ function getStringFromWasm0(ptr, len) {
12
+ ptr = ptr >>> 0;
13
+ return decodeText(ptr, len);
14
+ }
15
+
16
+ let cachedUint8ArrayMemory0 = null;
17
+ function getUint8ArrayMemory0() {
18
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
19
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
20
+ }
21
+ return cachedUint8ArrayMemory0;
22
+ }
23
+
24
+ function passStringToWasm0(arg, malloc, realloc) {
25
+ if (realloc === undefined) {
26
+ const buf = cachedTextEncoder.encode(arg);
27
+ const ptr = malloc(buf.length, 1) >>> 0;
28
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
29
+ WASM_VECTOR_LEN = buf.length;
30
+ return ptr;
31
+ }
32
+
33
+ let len = arg.length;
34
+ let ptr = malloc(len, 1) >>> 0;
35
+
36
+ const mem = getUint8ArrayMemory0();
37
+
38
+ let offset = 0;
39
+
40
+ for (; offset < len; offset++) {
41
+ const code = arg.charCodeAt(offset);
42
+ if (code > 0x7F) break;
43
+ mem[ptr + offset] = code;
44
+ }
45
+ if (offset !== len) {
46
+ if (offset !== 0) {
47
+ arg = arg.slice(offset);
48
+ }
49
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
50
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
51
+ const ret = cachedTextEncoder.encodeInto(arg, view);
52
+
53
+ offset += ret.written;
54
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
55
+ }
56
+
57
+ WASM_VECTOR_LEN = offset;
58
+ return ptr;
59
+ }
60
+
61
+ function takeFromExternrefTable0(idx) {
62
+ const value = wasm.__wbindgen_externrefs.get(idx);
63
+ wasm.__externref_table_dealloc(idx);
64
+ return value;
65
+ }
66
+
67
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
68
+ cachedTextDecoder.decode();
69
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
70
+ let numBytesDecoded = 0;
71
+ function decodeText(ptr, len) {
72
+ numBytesDecoded += len;
73
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
74
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
75
+ cachedTextDecoder.decode();
76
+ numBytesDecoded = len;
77
+ }
78
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
79
+ }
80
+
81
+ const cachedTextEncoder = new TextEncoder();
82
+
83
+ if (!('encodeInto' in cachedTextEncoder)) {
84
+ cachedTextEncoder.encodeInto = function (arg, view) {
85
+ const buf = cachedTextEncoder.encode(arg);
86
+ view.set(buf);
87
+ return {
88
+ read: arg.length,
89
+ written: buf.length
90
+ };
91
+ }
92
+ }
93
+
94
+ let WASM_VECTOR_LEN = 0;
95
+
96
+ /**
97
+ * Convert JSON-LD string to TOON-LD format
98
+ *
99
+ * # Arguments
100
+ * * `json` - A JSON or JSON-LD formatted string
101
+ *
102
+ * # Returns
103
+ * * TOON-LD formatted string on success
104
+ * * Error message on failure
105
+ * @param {string} json
106
+ * @returns {string}
107
+ */
108
+ export function convert_jsonld_to_toon(json) {
109
+ let deferred3_0;
110
+ let deferred3_1;
111
+ try {
112
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
113
+ const len0 = WASM_VECTOR_LEN;
114
+ const ret = wasm.convert_jsonld_to_toon(ptr0, len0);
115
+ var ptr2 = ret[0];
116
+ var len2 = ret[1];
117
+ if (ret[3]) {
118
+ ptr2 = 0; len2 = 0;
119
+ throw takeFromExternrefTable0(ret[2]);
120
+ }
121
+ deferred3_0 = ptr2;
122
+ deferred3_1 = len2;
123
+ return getStringFromWasm0(ptr2, len2);
124
+ } finally {
125
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Convert TOON-LD string to JSON-LD format
131
+ *
132
+ * # Arguments
133
+ * * `toon` - A TOON-LD formatted string
134
+ *
135
+ * # Returns
136
+ * * JSON-LD formatted string (pretty-printed) on success
137
+ * * Error message on failure
138
+ * @param {string} toon
139
+ * @returns {string}
140
+ */
141
+ export function convert_toon_to_jsonld(toon) {
142
+ let deferred3_0;
143
+ let deferred3_1;
144
+ try {
145
+ const ptr0 = passStringToWasm0(toon, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
146
+ const len0 = WASM_VECTOR_LEN;
147
+ const ret = wasm.convert_toon_to_jsonld(ptr0, len0);
148
+ var ptr2 = ret[0];
149
+ var len2 = ret[1];
150
+ if (ret[3]) {
151
+ ptr2 = 0; len2 = 0;
152
+ throw takeFromExternrefTable0(ret[2]);
153
+ }
154
+ deferred3_0 = ptr2;
155
+ deferred3_1 = len2;
156
+ return getStringFromWasm0(ptr2, len2);
157
+ } finally {
158
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Initialize panic hook for better error messages in browser console
164
+ */
165
+ export function init() {
166
+ wasm.init();
167
+ }
168
+
169
+ /**
170
+ * Validate a JSON-LD string
171
+ *
172
+ * # Arguments
173
+ * * `json` - A JSON or JSON-LD formatted string
174
+ *
175
+ * # Returns
176
+ * * `true` if the string is valid JSON
177
+ * * `false` otherwise
178
+ * @param {string} json
179
+ * @returns {boolean}
180
+ */
181
+ export function validate_json(json) {
182
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
183
+ const len0 = WASM_VECTOR_LEN;
184
+ const ret = wasm.validate_json(ptr0, len0);
185
+ return ret !== 0;
186
+ }
187
+
188
+ /**
189
+ * Validate a TOON-LD string
190
+ *
191
+ * # Arguments
192
+ * * `toon` - A TOON-LD formatted string
193
+ *
194
+ * # Returns
195
+ * * `true` if the string is valid TOON-LD
196
+ * * `false` otherwise
197
+ * @param {string} toon
198
+ * @returns {boolean}
199
+ */
200
+ export function validate_toon(toon) {
201
+ const ptr0 = passStringToWasm0(toon, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
202
+ const len0 = WASM_VECTOR_LEN;
203
+ const ret = wasm.validate_toon(ptr0, len0);
204
+ return ret !== 0;
205
+ }
206
+
207
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
208
+
209
+ async function __wbg_load(module, imports) {
210
+ if (typeof Response === 'function' && module instanceof Response) {
211
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
212
+ try {
213
+ return await WebAssembly.instantiateStreaming(module, imports);
214
+ } catch (e) {
215
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
216
+
217
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
218
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
219
+
220
+ } else {
221
+ throw e;
222
+ }
223
+ }
224
+ }
225
+
226
+ const bytes = await module.arrayBuffer();
227
+ return await WebAssembly.instantiate(bytes, imports);
228
+ } else {
229
+ const instance = await WebAssembly.instantiate(module, imports);
230
+
231
+ if (instance instanceof WebAssembly.Instance) {
232
+ return { instance, module };
233
+ } else {
234
+ return instance;
235
+ }
236
+ }
237
+ }
238
+
239
+ function __wbg_get_imports() {
240
+ const imports = {};
241
+ imports.wbg = {};
242
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
243
+ let deferred0_0;
244
+ let deferred0_1;
245
+ try {
246
+ deferred0_0 = arg0;
247
+ deferred0_1 = arg1;
248
+ console.error(getStringFromWasm0(arg0, arg1));
249
+ } finally {
250
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
251
+ }
252
+ };
253
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
254
+ const ret = new Error();
255
+ return ret;
256
+ };
257
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
258
+ const ret = arg1.stack;
259
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
260
+ const len1 = WASM_VECTOR_LEN;
261
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
262
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
263
+ };
264
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
265
+ // Cast intrinsic for `Ref(String) -> Externref`.
266
+ const ret = getStringFromWasm0(arg0, arg1);
267
+ return ret;
268
+ };
269
+ imports.wbg.__wbindgen_init_externref_table = function() {
270
+ const table = wasm.__wbindgen_externrefs;
271
+ const offset = table.grow(4);
272
+ table.set(0, undefined);
273
+ table.set(offset + 0, undefined);
274
+ table.set(offset + 1, null);
275
+ table.set(offset + 2, true);
276
+ table.set(offset + 3, false);
277
+ };
278
+
279
+ return imports;
280
+ }
281
+
282
+ function __wbg_finalize_init(instance, module) {
283
+ wasm = instance.exports;
284
+ __wbg_init.__wbindgen_wasm_module = module;
285
+ cachedDataViewMemory0 = null;
286
+ cachedUint8ArrayMemory0 = null;
287
+
288
+
289
+ wasm.__wbindgen_start();
290
+ return wasm;
291
+ }
292
+
293
+ function initSync(module) {
294
+ if (wasm !== undefined) return wasm;
295
+
296
+
297
+ if (typeof module !== 'undefined') {
298
+ if (Object.getPrototypeOf(module) === Object.prototype) {
299
+ ({module} = module)
300
+ } else {
301
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
302
+ }
303
+ }
304
+
305
+ const imports = __wbg_get_imports();
306
+ if (!(module instanceof WebAssembly.Module)) {
307
+ module = new WebAssembly.Module(module);
308
+ }
309
+ const instance = new WebAssembly.Instance(module, imports);
310
+ return __wbg_finalize_init(instance, module);
311
+ }
312
+
313
+ async function __wbg_init(module_or_path) {
314
+ if (wasm !== undefined) return wasm;
315
+
316
+
317
+ if (typeof module_or_path !== 'undefined') {
318
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
319
+ ({module_or_path} = module_or_path)
320
+ } else {
321
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
322
+ }
323
+ }
324
+
325
+ if (typeof module_or_path === 'undefined') {
326
+ module_or_path = new URL('toon_wasm_bg.wasm', import.meta.url);
327
+ }
328
+ const imports = __wbg_get_imports();
329
+
330
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
331
+ module_or_path = fetch(module_or_path);
332
+ }
333
+
334
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
335
+
336
+ return __wbg_finalize_init(instance, module);
337
+ }
338
+
339
+ export { initSync };
340
+ export default __wbg_init;
Binary file