mini-yaml-rs 0.2.2 → 0.2.4

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 CHANGED
@@ -15,7 +15,7 @@ A minimalist, zero-copy YAML parser for Rust. Supports sequences, mappings, and
15
15
 
16
16
  ```toml
17
17
  [dependencies]
18
- mini-yaml-rs = "0.1"
18
+ mini-yaml-rs = "0.2"
19
19
  ```
20
20
 
21
21
  ### JavaScript/TypeScript (npm)
@@ -154,6 +154,8 @@ on/off # → true/false (as boolean)
154
154
 
155
155
  ### JavaScript/TypeScript (WASM)
156
156
 
157
+ All functions return plain JavaScript objects (not `Map` objects), making them easy to use with standard JS object syntax.
158
+
157
159
  ```typescript
158
160
  import init, { parseYaml, parseYamlToMx, printYaml } from 'mini-yaml-rs';
159
161
 
package/mini_yaml_rs.d.ts CHANGED
@@ -18,3 +18,42 @@ export function parseYamlToMx(input: string): any;
18
18
  * Takes a JavaScript object/array and returns a YAML string representation.
19
19
  */
20
20
  export function printYaml(input: any): string;
21
+
22
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
23
+
24
+ export interface InitOutput {
25
+ readonly memory: WebAssembly.Memory;
26
+ readonly parseYaml: (a: number, b: number) => [number, number, number];
27
+ readonly parseYamlToMx: (a: number, b: number) => [number, number, number];
28
+ readonly printYaml: (a: any) => [number, number, number, number];
29
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
30
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
31
+ readonly __wbindgen_exn_store: (a: number) => void;
32
+ readonly __externref_table_alloc: () => number;
33
+ readonly __wbindgen_externrefs: WebAssembly.Table;
34
+ readonly __externref_table_dealloc: (a: number) => void;
35
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
36
+ readonly __wbindgen_start: () => void;
37
+ }
38
+
39
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
40
+
41
+ /**
42
+ * Instantiates the given `module`, which can either be bytes or
43
+ * a precompiled `WebAssembly.Module`.
44
+ *
45
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
46
+ *
47
+ * @returns {InitOutput}
48
+ */
49
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
50
+
51
+ /**
52
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
53
+ * for everything else, calls `WebAssembly.instantiate` directly.
54
+ *
55
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
56
+ *
57
+ * @returns {Promise<InitOutput>}
58
+ */
59
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/mini_yaml_rs.js CHANGED
@@ -1,9 +1,558 @@
1
1
  /* @ts-self-types="./mini_yaml_rs.d.ts" */
2
2
 
3
- import * as wasm from "./mini_yaml_rs_bg.wasm";
4
- import { __wbg_set_wasm } from "./mini_yaml_rs_bg.js";
5
- __wbg_set_wasm(wasm);
6
- wasm.__wbindgen_start();
7
- export {
8
- parseYaml, parseYamlToMx, printYaml
9
- } from "./mini_yaml_rs_bg.js";
3
+ /**
4
+ * Parse YAML string and return JSON object directly.
5
+ * Returns a JavaScript object/array on success, or throws an error on parse failure.
6
+ * @param {string} input
7
+ * @returns {any}
8
+ */
9
+ export function parseYaml(input) {
10
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
11
+ const len0 = WASM_VECTOR_LEN;
12
+ const ret = wasm.parseYaml(ptr0, len0);
13
+ if (ret[2]) {
14
+ throw takeFromExternrefTable0(ret[1]);
15
+ }
16
+ return takeFromExternrefTable0(ret[0]);
17
+ }
18
+
19
+ /**
20
+ * Parse YAML string and return mx-formatted JSON object directly.
21
+ * Returns a JavaScript object with mx transformation on success, or throws an error on parse failure.
22
+ * @param {string} input
23
+ * @returns {any}
24
+ */
25
+ export function parseYamlToMx(input) {
26
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
27
+ const len0 = WASM_VECTOR_LEN;
28
+ const ret = wasm.parseYamlToMx(ptr0, len0);
29
+ if (ret[2]) {
30
+ throw takeFromExternrefTable0(ret[1]);
31
+ }
32
+ return takeFromExternrefTable0(ret[0]);
33
+ }
34
+
35
+ /**
36
+ * Convert JSON to YAML string.
37
+ * Takes a JavaScript object/array and returns a YAML string representation.
38
+ * @param {any} input
39
+ * @returns {string}
40
+ */
41
+ export function printYaml(input) {
42
+ let deferred2_0;
43
+ let deferred2_1;
44
+ try {
45
+ const ret = wasm.printYaml(input);
46
+ var ptr1 = ret[0];
47
+ var len1 = ret[1];
48
+ if (ret[3]) {
49
+ ptr1 = 0; len1 = 0;
50
+ throw takeFromExternrefTable0(ret[2]);
51
+ }
52
+ deferred2_0 = ptr1;
53
+ deferred2_1 = len1;
54
+ return getStringFromWasm0(ptr1, len1);
55
+ } finally {
56
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
57
+ }
58
+ }
59
+
60
+ function __wbg_get_imports() {
61
+ const import0 = {
62
+ __proto__: null,
63
+ __wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
64
+ const ret = Error(getStringFromWasm0(arg0, arg1));
65
+ return ret;
66
+ },
67
+ __wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
68
+ const ret = String(arg1);
69
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
70
+ const len1 = WASM_VECTOR_LEN;
71
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
72
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
73
+ },
74
+ __wbg___wbindgen_bigint_get_as_i64_8fcf4ce7f1ca72a2: function(arg0, arg1) {
75
+ const v = arg1;
76
+ const ret = typeof(v) === 'bigint' ? v : undefined;
77
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
78
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
79
+ },
80
+ __wbg___wbindgen_boolean_get_bbbb1c18aa2f5e25: function(arg0) {
81
+ const v = arg0;
82
+ const ret = typeof(v) === 'boolean' ? v : undefined;
83
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
84
+ },
85
+ __wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
86
+ const ret = debugString(arg1);
87
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
88
+ const len1 = WASM_VECTOR_LEN;
89
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
90
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
91
+ },
92
+ __wbg___wbindgen_in_47fa6863be6f2f25: function(arg0, arg1) {
93
+ const ret = arg0 in arg1;
94
+ return ret;
95
+ },
96
+ __wbg___wbindgen_is_bigint_31b12575b56f32fc: function(arg0) {
97
+ const ret = typeof(arg0) === 'bigint';
98
+ return ret;
99
+ },
100
+ __wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
101
+ const ret = typeof(arg0) === 'function';
102
+ return ret;
103
+ },
104
+ __wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function(arg0) {
105
+ const val = arg0;
106
+ const ret = typeof(val) === 'object' && val !== null;
107
+ return ret;
108
+ },
109
+ __wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
110
+ const ret = typeof(arg0) === 'string';
111
+ return ret;
112
+ },
113
+ __wbg___wbindgen_jsval_eq_11888390b0186270: function(arg0, arg1) {
114
+ const ret = arg0 === arg1;
115
+ return ret;
116
+ },
117
+ __wbg___wbindgen_jsval_loose_eq_9dd77d8cd6671811: function(arg0, arg1) {
118
+ const ret = arg0 == arg1;
119
+ return ret;
120
+ },
121
+ __wbg___wbindgen_number_get_8ff4255516ccad3e: function(arg0, arg1) {
122
+ const obj = arg1;
123
+ const ret = typeof(obj) === 'number' ? obj : undefined;
124
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
125
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
126
+ },
127
+ __wbg___wbindgen_string_get_72fb696202c56729: function(arg0, arg1) {
128
+ const obj = arg1;
129
+ const ret = typeof(obj) === 'string' ? obj : undefined;
130
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
131
+ var len1 = WASM_VECTOR_LEN;
132
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
133
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
134
+ },
135
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
136
+ throw new Error(getStringFromWasm0(arg0, arg1));
137
+ },
138
+ __wbg_call_389efe28435a9388: function() { return handleError(function (arg0, arg1) {
139
+ const ret = arg0.call(arg1);
140
+ return ret;
141
+ }, arguments); },
142
+ __wbg_done_57b39ecd9addfe81: function(arg0) {
143
+ const ret = arg0.done;
144
+ return ret;
145
+ },
146
+ __wbg_entries_58c7934c745daac7: function(arg0) {
147
+ const ret = Object.entries(arg0);
148
+ return ret;
149
+ },
150
+ __wbg_get_9b94d73e6221f75c: function(arg0, arg1) {
151
+ const ret = arg0[arg1 >>> 0];
152
+ return ret;
153
+ },
154
+ __wbg_get_b3ed3ad4be2bc8ac: function() { return handleError(function (arg0, arg1) {
155
+ const ret = Reflect.get(arg0, arg1);
156
+ return ret;
157
+ }, arguments); },
158
+ __wbg_instanceof_ArrayBuffer_c367199e2fa2aa04: function(arg0) {
159
+ let result;
160
+ try {
161
+ result = arg0 instanceof ArrayBuffer;
162
+ } catch (_) {
163
+ result = false;
164
+ }
165
+ const ret = result;
166
+ return ret;
167
+ },
168
+ __wbg_instanceof_Map_53af74335dec57f4: function(arg0) {
169
+ let result;
170
+ try {
171
+ result = arg0 instanceof Map;
172
+ } catch (_) {
173
+ result = false;
174
+ }
175
+ const ret = result;
176
+ return ret;
177
+ },
178
+ __wbg_instanceof_Uint8Array_9b9075935c74707c: function(arg0) {
179
+ let result;
180
+ try {
181
+ result = arg0 instanceof Uint8Array;
182
+ } catch (_) {
183
+ result = false;
184
+ }
185
+ const ret = result;
186
+ return ret;
187
+ },
188
+ __wbg_isArray_d314bb98fcf08331: function(arg0) {
189
+ const ret = Array.isArray(arg0);
190
+ return ret;
191
+ },
192
+ __wbg_isSafeInteger_bfbc7332a9768d2a: function(arg0) {
193
+ const ret = Number.isSafeInteger(arg0);
194
+ return ret;
195
+ },
196
+ __wbg_iterator_6ff6560ca1568e55: function() {
197
+ const ret = Symbol.iterator;
198
+ return ret;
199
+ },
200
+ __wbg_length_32ed9a279acd054c: function(arg0) {
201
+ const ret = arg0.length;
202
+ return ret;
203
+ },
204
+ __wbg_length_35a7bace40f36eac: function(arg0) {
205
+ const ret = arg0.length;
206
+ return ret;
207
+ },
208
+ __wbg_new_361308b2356cecd0: function() {
209
+ const ret = new Object();
210
+ return ret;
211
+ },
212
+ __wbg_new_3eb36ae241fe6f44: function() {
213
+ const ret = new Array();
214
+ return ret;
215
+ },
216
+ __wbg_new_dca287b076112a51: function() {
217
+ const ret = new Map();
218
+ return ret;
219
+ },
220
+ __wbg_new_dd2b680c8bf6ae29: function(arg0) {
221
+ const ret = new Uint8Array(arg0);
222
+ return ret;
223
+ },
224
+ __wbg_next_3482f54c49e8af19: function() { return handleError(function (arg0) {
225
+ const ret = arg0.next();
226
+ return ret;
227
+ }, arguments); },
228
+ __wbg_next_418f80d8f5303233: function(arg0) {
229
+ const ret = arg0.next;
230
+ return ret;
231
+ },
232
+ __wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
233
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
234
+ },
235
+ __wbg_set_1eb0999cf5d27fc8: function(arg0, arg1, arg2) {
236
+ const ret = arg0.set(arg1, arg2);
237
+ return ret;
238
+ },
239
+ __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
240
+ arg0[arg1] = arg2;
241
+ },
242
+ __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
243
+ arg0[arg1 >>> 0] = arg2;
244
+ },
245
+ __wbg_value_0546255b415e96c1: function(arg0) {
246
+ const ret = arg0.value;
247
+ return ret;
248
+ },
249
+ __wbindgen_cast_0000000000000001: function(arg0) {
250
+ // Cast intrinsic for `F64 -> Externref`.
251
+ const ret = arg0;
252
+ return ret;
253
+ },
254
+ __wbindgen_cast_0000000000000002: function(arg0) {
255
+ // Cast intrinsic for `I64 -> Externref`.
256
+ const ret = arg0;
257
+ return ret;
258
+ },
259
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
260
+ // Cast intrinsic for `Ref(String) -> Externref`.
261
+ const ret = getStringFromWasm0(arg0, arg1);
262
+ return ret;
263
+ },
264
+ __wbindgen_cast_0000000000000004: function(arg0) {
265
+ // Cast intrinsic for `U64 -> Externref`.
266
+ const ret = BigInt.asUintN(64, arg0);
267
+ return ret;
268
+ },
269
+ __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 {
280
+ __proto__: null,
281
+ "./mini_yaml_rs_bg.js": import0,
282
+ };
283
+ }
284
+
285
+ function addToExternrefTable0(obj) {
286
+ const idx = wasm.__externref_table_alloc();
287
+ wasm.__wbindgen_externrefs.set(idx, obj);
288
+ return idx;
289
+ }
290
+
291
+ function debugString(val) {
292
+ // primitive types
293
+ const type = typeof val;
294
+ if (type == 'number' || type == 'boolean' || val == null) {
295
+ return `${val}`;
296
+ }
297
+ if (type == 'string') {
298
+ return `"${val}"`;
299
+ }
300
+ if (type == 'symbol') {
301
+ const description = val.description;
302
+ if (description == null) {
303
+ return 'Symbol';
304
+ } else {
305
+ return `Symbol(${description})`;
306
+ }
307
+ }
308
+ if (type == 'function') {
309
+ const name = val.name;
310
+ if (typeof name == 'string' && name.length > 0) {
311
+ return `Function(${name})`;
312
+ } else {
313
+ return 'Function';
314
+ }
315
+ }
316
+ // objects
317
+ if (Array.isArray(val)) {
318
+ const length = val.length;
319
+ let debug = '[';
320
+ if (length > 0) {
321
+ debug += debugString(val[0]);
322
+ }
323
+ for(let i = 1; i < length; i++) {
324
+ debug += ', ' + debugString(val[i]);
325
+ }
326
+ debug += ']';
327
+ return debug;
328
+ }
329
+ // Test for built-in
330
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
331
+ let className;
332
+ if (builtInMatches && builtInMatches.length > 1) {
333
+ className = builtInMatches[1];
334
+ } else {
335
+ // Failed to match the standard '[object ClassName]'
336
+ return toString.call(val);
337
+ }
338
+ if (className == 'Object') {
339
+ // we're a user defined class or Object
340
+ // JSON.stringify avoids problems with cycles, and is generally much
341
+ // easier than looping through ownProperties of `val`.
342
+ try {
343
+ return 'Object(' + JSON.stringify(val) + ')';
344
+ } catch (_) {
345
+ return 'Object';
346
+ }
347
+ }
348
+ // errors
349
+ if (val instanceof Error) {
350
+ return `${val.name}: ${val.message}\n${val.stack}`;
351
+ }
352
+ // TODO we could test for more things here, like `Set`s and `Map`s.
353
+ return className;
354
+ }
355
+
356
+ function getArrayU8FromWasm0(ptr, len) {
357
+ ptr = ptr >>> 0;
358
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
359
+ }
360
+
361
+ let cachedDataViewMemory0 = null;
362
+ function getDataViewMemory0() {
363
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
364
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
365
+ }
366
+ return cachedDataViewMemory0;
367
+ }
368
+
369
+ function getStringFromWasm0(ptr, len) {
370
+ ptr = ptr >>> 0;
371
+ return decodeText(ptr, len);
372
+ }
373
+
374
+ let cachedUint8ArrayMemory0 = null;
375
+ function getUint8ArrayMemory0() {
376
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
377
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
378
+ }
379
+ return cachedUint8ArrayMemory0;
380
+ }
381
+
382
+ function handleError(f, args) {
383
+ try {
384
+ return f.apply(this, args);
385
+ } catch (e) {
386
+ const idx = addToExternrefTable0(e);
387
+ wasm.__wbindgen_exn_store(idx);
388
+ }
389
+ }
390
+
391
+ function isLikeNone(x) {
392
+ return x === undefined || x === null;
393
+ }
394
+
395
+ function passStringToWasm0(arg, malloc, realloc) {
396
+ if (realloc === undefined) {
397
+ const buf = cachedTextEncoder.encode(arg);
398
+ const ptr = malloc(buf.length, 1) >>> 0;
399
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
400
+ WASM_VECTOR_LEN = buf.length;
401
+ return ptr;
402
+ }
403
+
404
+ let len = arg.length;
405
+ let ptr = malloc(len, 1) >>> 0;
406
+
407
+ const mem = getUint8ArrayMemory0();
408
+
409
+ let offset = 0;
410
+
411
+ for (; offset < len; offset++) {
412
+ const code = arg.charCodeAt(offset);
413
+ if (code > 0x7F) break;
414
+ mem[ptr + offset] = code;
415
+ }
416
+ if (offset !== len) {
417
+ if (offset !== 0) {
418
+ arg = arg.slice(offset);
419
+ }
420
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
421
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
422
+ const ret = cachedTextEncoder.encodeInto(arg, view);
423
+
424
+ offset += ret.written;
425
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
426
+ }
427
+
428
+ WASM_VECTOR_LEN = offset;
429
+ return ptr;
430
+ }
431
+
432
+ function takeFromExternrefTable0(idx) {
433
+ const value = wasm.__wbindgen_externrefs.get(idx);
434
+ wasm.__externref_table_dealloc(idx);
435
+ return value;
436
+ }
437
+
438
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
439
+ cachedTextDecoder.decode();
440
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
441
+ let numBytesDecoded = 0;
442
+ function decodeText(ptr, len) {
443
+ numBytesDecoded += len;
444
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
445
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
446
+ cachedTextDecoder.decode();
447
+ numBytesDecoded = len;
448
+ }
449
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
450
+ }
451
+
452
+ const cachedTextEncoder = new TextEncoder();
453
+
454
+ if (!('encodeInto' in cachedTextEncoder)) {
455
+ cachedTextEncoder.encodeInto = function (arg, view) {
456
+ const buf = cachedTextEncoder.encode(arg);
457
+ view.set(buf);
458
+ return {
459
+ read: arg.length,
460
+ written: buf.length
461
+ };
462
+ };
463
+ }
464
+
465
+ let WASM_VECTOR_LEN = 0;
466
+
467
+ let wasmModule, wasm;
468
+ function __wbg_finalize_init(instance, module) {
469
+ wasm = instance.exports;
470
+ wasmModule = module;
471
+ cachedDataViewMemory0 = null;
472
+ cachedUint8ArrayMemory0 = null;
473
+ wasm.__wbindgen_start();
474
+ return wasm;
475
+ }
476
+
477
+ async function __wbg_load(module, imports) {
478
+ if (typeof Response === 'function' && module instanceof Response) {
479
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
480
+ try {
481
+ return await WebAssembly.instantiateStreaming(module, imports);
482
+ } catch (e) {
483
+ const validResponse = module.ok && expectedResponseType(module.type);
484
+
485
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
486
+ 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);
487
+
488
+ } else { throw e; }
489
+ }
490
+ }
491
+
492
+ const bytes = await module.arrayBuffer();
493
+ return await WebAssembly.instantiate(bytes, imports);
494
+ } else {
495
+ const instance = await WebAssembly.instantiate(module, imports);
496
+
497
+ if (instance instanceof WebAssembly.Instance) {
498
+ return { instance, module };
499
+ } else {
500
+ return instance;
501
+ }
502
+ }
503
+
504
+ function expectedResponseType(type) {
505
+ switch (type) {
506
+ case 'basic': case 'cors': case 'default': return true;
507
+ }
508
+ return false;
509
+ }
510
+ }
511
+
512
+ function initSync(module) {
513
+ if (wasm !== undefined) return wasm;
514
+
515
+
516
+ if (module !== undefined) {
517
+ if (Object.getPrototypeOf(module) === Object.prototype) {
518
+ ({module} = module)
519
+ } else {
520
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
521
+ }
522
+ }
523
+
524
+ const imports = __wbg_get_imports();
525
+ if (!(module instanceof WebAssembly.Module)) {
526
+ module = new WebAssembly.Module(module);
527
+ }
528
+ const instance = new WebAssembly.Instance(module, imports);
529
+ return __wbg_finalize_init(instance, module);
530
+ }
531
+
532
+ async function __wbg_init(module_or_path) {
533
+ if (wasm !== undefined) return wasm;
534
+
535
+
536
+ if (module_or_path !== undefined) {
537
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
538
+ ({module_or_path} = module_or_path)
539
+ } else {
540
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
541
+ }
542
+ }
543
+
544
+ if (module_or_path === undefined) {
545
+ module_or_path = new URL('mini_yaml_rs_bg.wasm', import.meta.url);
546
+ }
547
+ const imports = __wbg_get_imports();
548
+
549
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
550
+ module_or_path = fetch(module_or_path);
551
+ }
552
+
553
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
554
+
555
+ return __wbg_finalize_init(instance, module);
556
+ }
557
+
558
+ export { initSync, __wbg_init as default };
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Shawn Xiang <xiang.elec@domain.com>"
6
6
  ],
7
7
  "description": "A minimalist, zero-copy parser for a strict subset of the YAML specification.",
8
- "version": "0.2.2",
8
+ "version": "0.2.4",
9
9
  "license": "Apache-2.0",
10
10
  "repository": {
11
11
  "type": "git",
@@ -14,14 +14,12 @@
14
14
  "files": [
15
15
  "mini_yaml_rs_bg.wasm",
16
16
  "mini_yaml_rs.js",
17
- "mini_yaml_rs_bg.js",
18
17
  "mini_yaml_rs.d.ts"
19
18
  ],
20
19
  "main": "mini_yaml_rs.js",
21
20
  "homepage": "https://github.com/hecmay/mini-yaml-rs",
22
21
  "types": "mini_yaml_rs.d.ts",
23
22
  "sideEffects": [
24
- "./mini_yaml_rs.js",
25
23
  "./snippets/*"
26
24
  ]
27
25
  }
@@ -1,458 +0,0 @@
1
- /**
2
- * Parse YAML string and return JSON object directly.
3
- * Returns a JavaScript object/array on success, or throws an error on parse failure.
4
- * @param {string} input
5
- * @returns {any}
6
- */
7
- export function parseYaml(input) {
8
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
9
- const len0 = WASM_VECTOR_LEN;
10
- const ret = wasm.parseYaml(ptr0, len0);
11
- if (ret[2]) {
12
- throw takeFromExternrefTable0(ret[1]);
13
- }
14
- return takeFromExternrefTable0(ret[0]);
15
- }
16
-
17
- /**
18
- * Parse YAML string and return mx-formatted JSON object directly.
19
- * Returns a JavaScript object with mx transformation on success, or throws an error on parse failure.
20
- * @param {string} input
21
- * @returns {any}
22
- */
23
- export function parseYamlToMx(input) {
24
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
25
- const len0 = WASM_VECTOR_LEN;
26
- const ret = wasm.parseYamlToMx(ptr0, len0);
27
- if (ret[2]) {
28
- throw takeFromExternrefTable0(ret[1]);
29
- }
30
- return takeFromExternrefTable0(ret[0]);
31
- }
32
-
33
- /**
34
- * Convert JSON to YAML string.
35
- * Takes a JavaScript object/array and returns a YAML string representation.
36
- * @param {any} input
37
- * @returns {string}
38
- */
39
- export function printYaml(input) {
40
- let deferred2_0;
41
- let deferred2_1;
42
- try {
43
- const ret = wasm.printYaml(input);
44
- var ptr1 = ret[0];
45
- var len1 = ret[1];
46
- if (ret[3]) {
47
- ptr1 = 0; len1 = 0;
48
- throw takeFromExternrefTable0(ret[2]);
49
- }
50
- deferred2_0 = ptr1;
51
- deferred2_1 = len1;
52
- return getStringFromWasm0(ptr1, len1);
53
- } finally {
54
- wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
55
- }
56
- }
57
- export function __wbg_Error_8c4e43fe74559d73(arg0, arg1) {
58
- const ret = Error(getStringFromWasm0(arg0, arg1));
59
- return ret;
60
- }
61
- export function __wbg_String_8f0eb39a4a4c2f66(arg0, arg1) {
62
- const ret = String(arg1);
63
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
64
- const len1 = WASM_VECTOR_LEN;
65
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
66
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
67
- }
68
- export function __wbg___wbindgen_bigint_get_as_i64_8fcf4ce7f1ca72a2(arg0, arg1) {
69
- const v = arg1;
70
- const ret = typeof(v) === 'bigint' ? v : undefined;
71
- getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
72
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
73
- }
74
- export function __wbg___wbindgen_boolean_get_bbbb1c18aa2f5e25(arg0) {
75
- const v = arg0;
76
- const ret = typeof(v) === 'boolean' ? v : undefined;
77
- return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
78
- }
79
- export function __wbg___wbindgen_debug_string_0bc8482c6e3508ae(arg0, arg1) {
80
- const ret = debugString(arg1);
81
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
82
- const len1 = WASM_VECTOR_LEN;
83
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
84
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
85
- }
86
- export function __wbg___wbindgen_in_47fa6863be6f2f25(arg0, arg1) {
87
- const ret = arg0 in arg1;
88
- return ret;
89
- }
90
- export function __wbg___wbindgen_is_bigint_31b12575b56f32fc(arg0) {
91
- const ret = typeof(arg0) === 'bigint';
92
- return ret;
93
- }
94
- export function __wbg___wbindgen_is_function_0095a73b8b156f76(arg0) {
95
- const ret = typeof(arg0) === 'function';
96
- return ret;
97
- }
98
- export function __wbg___wbindgen_is_object_5ae8e5880f2c1fbd(arg0) {
99
- const val = arg0;
100
- const ret = typeof(val) === 'object' && val !== null;
101
- return ret;
102
- }
103
- export function __wbg___wbindgen_is_string_cd444516edc5b180(arg0) {
104
- const ret = typeof(arg0) === 'string';
105
- return ret;
106
- }
107
- export function __wbg___wbindgen_jsval_eq_11888390b0186270(arg0, arg1) {
108
- const ret = arg0 === arg1;
109
- return ret;
110
- }
111
- export function __wbg___wbindgen_jsval_loose_eq_9dd77d8cd6671811(arg0, arg1) {
112
- const ret = arg0 == arg1;
113
- return ret;
114
- }
115
- export function __wbg___wbindgen_number_get_8ff4255516ccad3e(arg0, arg1) {
116
- const obj = arg1;
117
- const ret = typeof(obj) === 'number' ? obj : undefined;
118
- getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
119
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
120
- }
121
- export function __wbg___wbindgen_string_get_72fb696202c56729(arg0, arg1) {
122
- const obj = arg1;
123
- const ret = typeof(obj) === 'string' ? obj : undefined;
124
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
125
- var len1 = WASM_VECTOR_LEN;
126
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
127
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
128
- }
129
- export function __wbg___wbindgen_throw_be289d5034ed271b(arg0, arg1) {
130
- throw new Error(getStringFromWasm0(arg0, arg1));
131
- }
132
- export function __wbg_call_389efe28435a9388() { return handleError(function (arg0, arg1) {
133
- const ret = arg0.call(arg1);
134
- return ret;
135
- }, arguments); }
136
- export function __wbg_done_57b39ecd9addfe81(arg0) {
137
- const ret = arg0.done;
138
- return ret;
139
- }
140
- export function __wbg_entries_58c7934c745daac7(arg0) {
141
- const ret = Object.entries(arg0);
142
- return ret;
143
- }
144
- export function __wbg_get_9b94d73e6221f75c(arg0, arg1) {
145
- const ret = arg0[arg1 >>> 0];
146
- return ret;
147
- }
148
- export function __wbg_get_b3ed3ad4be2bc8ac() { return handleError(function (arg0, arg1) {
149
- const ret = Reflect.get(arg0, arg1);
150
- return ret;
151
- }, arguments); }
152
- export function __wbg_instanceof_ArrayBuffer_c367199e2fa2aa04(arg0) {
153
- let result;
154
- try {
155
- result = arg0 instanceof ArrayBuffer;
156
- } catch (_) {
157
- result = false;
158
- }
159
- const ret = result;
160
- return ret;
161
- }
162
- export function __wbg_instanceof_Map_53af74335dec57f4(arg0) {
163
- let result;
164
- try {
165
- result = arg0 instanceof Map;
166
- } catch (_) {
167
- result = false;
168
- }
169
- const ret = result;
170
- return ret;
171
- }
172
- export function __wbg_instanceof_Uint8Array_9b9075935c74707c(arg0) {
173
- let result;
174
- try {
175
- result = arg0 instanceof Uint8Array;
176
- } catch (_) {
177
- result = false;
178
- }
179
- const ret = result;
180
- return ret;
181
- }
182
- export function __wbg_isArray_d314bb98fcf08331(arg0) {
183
- const ret = Array.isArray(arg0);
184
- return ret;
185
- }
186
- export function __wbg_isSafeInteger_bfbc7332a9768d2a(arg0) {
187
- const ret = Number.isSafeInteger(arg0);
188
- return ret;
189
- }
190
- export function __wbg_iterator_6ff6560ca1568e55() {
191
- const ret = Symbol.iterator;
192
- return ret;
193
- }
194
- export function __wbg_length_32ed9a279acd054c(arg0) {
195
- const ret = arg0.length;
196
- return ret;
197
- }
198
- export function __wbg_length_35a7bace40f36eac(arg0) {
199
- const ret = arg0.length;
200
- return ret;
201
- }
202
- export function __wbg_new_361308b2356cecd0() {
203
- const ret = new Object();
204
- return ret;
205
- }
206
- export function __wbg_new_3eb36ae241fe6f44() {
207
- const ret = new Array();
208
- return ret;
209
- }
210
- export function __wbg_new_dca287b076112a51() {
211
- const ret = new Map();
212
- return ret;
213
- }
214
- export function __wbg_new_dd2b680c8bf6ae29(arg0) {
215
- const ret = new Uint8Array(arg0);
216
- return ret;
217
- }
218
- export function __wbg_next_3482f54c49e8af19() { return handleError(function (arg0) {
219
- const ret = arg0.next();
220
- return ret;
221
- }, arguments); }
222
- export function __wbg_next_418f80d8f5303233(arg0) {
223
- const ret = arg0.next;
224
- return ret;
225
- }
226
- export function __wbg_prototypesetcall_bdcdcc5842e4d77d(arg0, arg1, arg2) {
227
- Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
228
- }
229
- export function __wbg_set_1eb0999cf5d27fc8(arg0, arg1, arg2) {
230
- const ret = arg0.set(arg1, arg2);
231
- return ret;
232
- }
233
- export function __wbg_set_3f1d0b984ed272ed(arg0, arg1, arg2) {
234
- arg0[arg1] = arg2;
235
- }
236
- export function __wbg_set_f43e577aea94465b(arg0, arg1, arg2) {
237
- arg0[arg1 >>> 0] = arg2;
238
- }
239
- export function __wbg_value_0546255b415e96c1(arg0) {
240
- const ret = arg0.value;
241
- return ret;
242
- }
243
- export function __wbindgen_cast_0000000000000001(arg0) {
244
- // Cast intrinsic for `F64 -> Externref`.
245
- const ret = arg0;
246
- return ret;
247
- }
248
- export function __wbindgen_cast_0000000000000002(arg0) {
249
- // Cast intrinsic for `I64 -> Externref`.
250
- const ret = arg0;
251
- return ret;
252
- }
253
- export function __wbindgen_cast_0000000000000003(arg0, arg1) {
254
- // Cast intrinsic for `Ref(String) -> Externref`.
255
- const ret = getStringFromWasm0(arg0, arg1);
256
- return ret;
257
- }
258
- export function __wbindgen_cast_0000000000000004(arg0) {
259
- // Cast intrinsic for `U64 -> Externref`.
260
- const ret = BigInt.asUintN(64, arg0);
261
- return ret;
262
- }
263
- export function __wbindgen_init_externref_table() {
264
- const table = wasm.__wbindgen_externrefs;
265
- const offset = table.grow(4);
266
- table.set(0, undefined);
267
- table.set(offset + 0, undefined);
268
- table.set(offset + 1, null);
269
- table.set(offset + 2, true);
270
- table.set(offset + 3, false);
271
- }
272
- function addToExternrefTable0(obj) {
273
- const idx = wasm.__externref_table_alloc();
274
- wasm.__wbindgen_externrefs.set(idx, obj);
275
- return idx;
276
- }
277
-
278
- function debugString(val) {
279
- // primitive types
280
- const type = typeof val;
281
- if (type == 'number' || type == 'boolean' || val == null) {
282
- return `${val}`;
283
- }
284
- if (type == 'string') {
285
- return `"${val}"`;
286
- }
287
- if (type == 'symbol') {
288
- const description = val.description;
289
- if (description == null) {
290
- return 'Symbol';
291
- } else {
292
- return `Symbol(${description})`;
293
- }
294
- }
295
- if (type == 'function') {
296
- const name = val.name;
297
- if (typeof name == 'string' && name.length > 0) {
298
- return `Function(${name})`;
299
- } else {
300
- return 'Function';
301
- }
302
- }
303
- // objects
304
- if (Array.isArray(val)) {
305
- const length = val.length;
306
- let debug = '[';
307
- if (length > 0) {
308
- debug += debugString(val[0]);
309
- }
310
- for(let i = 1; i < length; i++) {
311
- debug += ', ' + debugString(val[i]);
312
- }
313
- debug += ']';
314
- return debug;
315
- }
316
- // Test for built-in
317
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
318
- let className;
319
- if (builtInMatches && builtInMatches.length > 1) {
320
- className = builtInMatches[1];
321
- } else {
322
- // Failed to match the standard '[object ClassName]'
323
- return toString.call(val);
324
- }
325
- if (className == 'Object') {
326
- // we're a user defined class or Object
327
- // JSON.stringify avoids problems with cycles, and is generally much
328
- // easier than looping through ownProperties of `val`.
329
- try {
330
- return 'Object(' + JSON.stringify(val) + ')';
331
- } catch (_) {
332
- return 'Object';
333
- }
334
- }
335
- // errors
336
- if (val instanceof Error) {
337
- return `${val.name}: ${val.message}\n${val.stack}`;
338
- }
339
- // TODO we could test for more things here, like `Set`s and `Map`s.
340
- return className;
341
- }
342
-
343
- function getArrayU8FromWasm0(ptr, len) {
344
- ptr = ptr >>> 0;
345
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
346
- }
347
-
348
- let cachedDataViewMemory0 = null;
349
- function getDataViewMemory0() {
350
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
351
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
352
- }
353
- return cachedDataViewMemory0;
354
- }
355
-
356
- function getStringFromWasm0(ptr, len) {
357
- ptr = ptr >>> 0;
358
- return decodeText(ptr, len);
359
- }
360
-
361
- let cachedUint8ArrayMemory0 = null;
362
- function getUint8ArrayMemory0() {
363
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
364
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
365
- }
366
- return cachedUint8ArrayMemory0;
367
- }
368
-
369
- function handleError(f, args) {
370
- try {
371
- return f.apply(this, args);
372
- } catch (e) {
373
- const idx = addToExternrefTable0(e);
374
- wasm.__wbindgen_exn_store(idx);
375
- }
376
- }
377
-
378
- function isLikeNone(x) {
379
- return x === undefined || x === null;
380
- }
381
-
382
- function passStringToWasm0(arg, malloc, realloc) {
383
- if (realloc === undefined) {
384
- const buf = cachedTextEncoder.encode(arg);
385
- const ptr = malloc(buf.length, 1) >>> 0;
386
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
387
- WASM_VECTOR_LEN = buf.length;
388
- return ptr;
389
- }
390
-
391
- let len = arg.length;
392
- let ptr = malloc(len, 1) >>> 0;
393
-
394
- const mem = getUint8ArrayMemory0();
395
-
396
- let offset = 0;
397
-
398
- for (; offset < len; offset++) {
399
- const code = arg.charCodeAt(offset);
400
- if (code > 0x7F) break;
401
- mem[ptr + offset] = code;
402
- }
403
- if (offset !== len) {
404
- if (offset !== 0) {
405
- arg = arg.slice(offset);
406
- }
407
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
408
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
409
- const ret = cachedTextEncoder.encodeInto(arg, view);
410
-
411
- offset += ret.written;
412
- ptr = realloc(ptr, len, offset, 1) >>> 0;
413
- }
414
-
415
- WASM_VECTOR_LEN = offset;
416
- return ptr;
417
- }
418
-
419
- function takeFromExternrefTable0(idx) {
420
- const value = wasm.__wbindgen_externrefs.get(idx);
421
- wasm.__externref_table_dealloc(idx);
422
- return value;
423
- }
424
-
425
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
426
- cachedTextDecoder.decode();
427
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
428
- let numBytesDecoded = 0;
429
- function decodeText(ptr, len) {
430
- numBytesDecoded += len;
431
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
432
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
433
- cachedTextDecoder.decode();
434
- numBytesDecoded = len;
435
- }
436
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
437
- }
438
-
439
- const cachedTextEncoder = new TextEncoder();
440
-
441
- if (!('encodeInto' in cachedTextEncoder)) {
442
- cachedTextEncoder.encodeInto = function (arg, view) {
443
- const buf = cachedTextEncoder.encode(arg);
444
- view.set(buf);
445
- return {
446
- read: arg.length,
447
- written: buf.length
448
- };
449
- };
450
- }
451
-
452
- let WASM_VECTOR_LEN = 0;
453
-
454
-
455
- let wasm;
456
- export function __wbg_set_wasm(val) {
457
- wasm = val;
458
- }