mini-yaml-rs 0.1.5
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/LICENSE +201 -0
- package/README.md +128 -0
- package/mini_yaml_rs.d.ts +50 -0
- package/mini_yaml_rs.js +255 -0
- package/mini_yaml_rs_bg.wasm +0 -0
- package/package.json +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Shawn Xiang
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# mini-yaml-rs
|
|
2
|
+
|
|
3
|
+
A minimalist, zero-copy YAML parser for Rust. Supports sequences, mappings, and custom tags.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Zero-copy parsing (returns references to input)
|
|
8
|
+
- Sequences and mappings (flow and block styles)
|
|
9
|
+
- Custom tag support: `!tagname` becomes `__type: "tagname"`
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```rust
|
|
14
|
+
use mini_yaml_rs::parse;
|
|
15
|
+
|
|
16
|
+
let yaml = parse(r#"
|
|
17
|
+
+setup[Settings](db://settings):
|
|
18
|
+
title: Settings
|
|
19
|
+
authors[]:
|
|
20
|
+
- !mod +@[Me](shawnx){}
|
|
21
|
+
- !mod +@[Boby at Unix Group](boby:unix.org)
|
|
22
|
+
|
|
23
|
+
signature:
|
|
24
|
+
pubkey: |
|
|
25
|
+
MCowBQYDK2VwAyEAGb9F2CMlxqLDB3rrzBVwC7aB...
|
|
26
|
+
|
|
27
|
+
created: 2024-06-01T12:00:00Z
|
|
28
|
+
modified: 2024-06-01T12:00:00Z
|
|
29
|
+
"#).unwrap();
|
|
30
|
+
|
|
31
|
+
// Returns Yaml<'_> enum - use to_json() for serde_json::Value
|
|
32
|
+
let json = yaml.to_json();
|
|
33
|
+
println!("{}", json);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Output:
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"+setup[Settings](db://settings)": {
|
|
40
|
+
"title": "Settings",
|
|
41
|
+
"authors": [
|
|
42
|
+
{
|
|
43
|
+
"__type": "mod",
|
|
44
|
+
"+@[Me](shawnx)"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"__type": "mod",
|
|
48
|
+
"+@[Boby at Unix Group](boby:unix.org)"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"signature": {
|
|
52
|
+
"pubkey": "MCowBQYDK2VwAyEAGb9F2CMlxqLDB3rrzBVwC7aB..."
|
|
53
|
+
},
|
|
54
|
+
"created": "2024-06-01T12:00:00Z",
|
|
55
|
+
"modified": "2024-06-01T12:00:00Z"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Magix Format
|
|
61
|
+
|
|
62
|
+
The `to_mx()` method transforms keys in `+name[label](value)` format:
|
|
63
|
+
|
|
64
|
+
```rust
|
|
65
|
+
use mini_yaml_rs::parse;
|
|
66
|
+
|
|
67
|
+
let yaml = parse(r#"
|
|
68
|
+
+setup[Settings](db://settings):
|
|
69
|
+
title: Settings
|
|
70
|
+
enabled: true
|
|
71
|
+
"#).unwrap();
|
|
72
|
+
|
|
73
|
+
let mx = yaml.to_mx();
|
|
74
|
+
println!("{}", mx);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Output:
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"+setup": {
|
|
81
|
+
"__name": "Settings",
|
|
82
|
+
"__value": "db://settings",
|
|
83
|
+
"title": "Settings",
|
|
84
|
+
"enabled": true
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The key `+setup[Settings](db://settings)` becomes `+setup` with:
|
|
90
|
+
- `__name` = bracket content (`Settings`)
|
|
91
|
+
- `__value` = paren content (`db://settings`, optional)
|
|
92
|
+
|
|
93
|
+
### Tag Support
|
|
94
|
+
|
|
95
|
+
Tags are converted to `__type` fields:
|
|
96
|
+
|
|
97
|
+
```yaml
|
|
98
|
+
!person {name: John} # → {__type: "person", name: "John"}
|
|
99
|
+
!custom_tag [1, 2, 3] # → {__type: "custom_tag", __value: [1, 2, 3]}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Type Inference
|
|
103
|
+
|
|
104
|
+
Unquoted scalar values are automatically converted to native types:
|
|
105
|
+
|
|
106
|
+
```yaml
|
|
107
|
+
42 # → 42 (as integer)
|
|
108
|
+
-123 # → -123 (as integer)
|
|
109
|
+
3.14 # → 3.14 (as float)
|
|
110
|
+
1.0e10 # → 1.0e10 (as float)
|
|
111
|
+
true # → true (as boolean)
|
|
112
|
+
false # → false (as boolean)
|
|
113
|
+
yes/no # → true/false (as boolean)
|
|
114
|
+
on/off # → true/false (as boolean)
|
|
115
|
+
|
|
116
|
+
# Keep these as strings by quoting:
|
|
117
|
+
"42" # → "42" (string, quotes stripped)
|
|
118
|
+
'true' # → "true" (string, quotes stripped)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
125
|
+
|
|
126
|
+
## Acknowledgments
|
|
127
|
+
|
|
128
|
+
Based on [minimal-yaml](https://github.com/nathanwhit/minimal-yaml) by Nathan Whitaker.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parse YAML string and return JSON string.
|
|
6
|
+
* Returns a JSON string on success, or throws an error on parse failure.
|
|
7
|
+
*/
|
|
8
|
+
export function parseYaml(input: string): string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parse YAML string and return mx-formatted JSON string.
|
|
12
|
+
* Returns a JSON string with mx transformation on success, or throws an error on parse failure.
|
|
13
|
+
*/
|
|
14
|
+
export function parseYamlToMx(input: string): string;
|
|
15
|
+
|
|
16
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
17
|
+
|
|
18
|
+
export interface InitOutput {
|
|
19
|
+
readonly memory: WebAssembly.Memory;
|
|
20
|
+
readonly parseYaml: (a: number, b: number) => [number, number, number, number];
|
|
21
|
+
readonly parseYamlToMx: (a: number, b: number) => [number, number, number, number];
|
|
22
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
23
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
24
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
25
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
26
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
27
|
+
readonly __wbindgen_start: () => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
34
|
+
* a precompiled `WebAssembly.Module`.
|
|
35
|
+
*
|
|
36
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
37
|
+
*
|
|
38
|
+
* @returns {InitOutput}
|
|
39
|
+
*/
|
|
40
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
44
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
45
|
+
*
|
|
46
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
47
|
+
*
|
|
48
|
+
* @returns {Promise<InitOutput>}
|
|
49
|
+
*/
|
|
50
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/mini_yaml_rs.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/* @ts-self-types="./mini_yaml_rs.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parse YAML string and return JSON string.
|
|
5
|
+
* Returns a JSON string on success, or throws an error on parse failure.
|
|
6
|
+
* @param {string} input
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
9
|
+
export function parseYaml(input) {
|
|
10
|
+
let deferred3_0;
|
|
11
|
+
let deferred3_1;
|
|
12
|
+
try {
|
|
13
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
14
|
+
const len0 = WASM_VECTOR_LEN;
|
|
15
|
+
const ret = wasm.parseYaml(ptr0, len0);
|
|
16
|
+
var ptr2 = ret[0];
|
|
17
|
+
var len2 = ret[1];
|
|
18
|
+
if (ret[3]) {
|
|
19
|
+
ptr2 = 0; len2 = 0;
|
|
20
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
21
|
+
}
|
|
22
|
+
deferred3_0 = ptr2;
|
|
23
|
+
deferred3_1 = len2;
|
|
24
|
+
return getStringFromWasm0(ptr2, len2);
|
|
25
|
+
} finally {
|
|
26
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Parse YAML string and return mx-formatted JSON string.
|
|
32
|
+
* Returns a JSON string with mx transformation on success, or throws an error on parse failure.
|
|
33
|
+
* @param {string} input
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
export function parseYamlToMx(input) {
|
|
37
|
+
let deferred3_0;
|
|
38
|
+
let deferred3_1;
|
|
39
|
+
try {
|
|
40
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
41
|
+
const len0 = WASM_VECTOR_LEN;
|
|
42
|
+
const ret = wasm.parseYamlToMx(ptr0, len0);
|
|
43
|
+
var ptr2 = ret[0];
|
|
44
|
+
var len2 = ret[1];
|
|
45
|
+
if (ret[3]) {
|
|
46
|
+
ptr2 = 0; len2 = 0;
|
|
47
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
48
|
+
}
|
|
49
|
+
deferred3_0 = ptr2;
|
|
50
|
+
deferred3_1 = len2;
|
|
51
|
+
return getStringFromWasm0(ptr2, len2);
|
|
52
|
+
} finally {
|
|
53
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function __wbg_get_imports() {
|
|
58
|
+
const import0 = {
|
|
59
|
+
__proto__: null,
|
|
60
|
+
__wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
|
|
61
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
62
|
+
return ret;
|
|
63
|
+
},
|
|
64
|
+
__wbindgen_init_externref_table: function() {
|
|
65
|
+
const table = wasm.__wbindgen_externrefs;
|
|
66
|
+
const offset = table.grow(4);
|
|
67
|
+
table.set(0, undefined);
|
|
68
|
+
table.set(offset + 0, undefined);
|
|
69
|
+
table.set(offset + 1, null);
|
|
70
|
+
table.set(offset + 2, true);
|
|
71
|
+
table.set(offset + 3, false);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
__proto__: null,
|
|
76
|
+
"./mini_yaml_rs_bg.js": import0,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function getStringFromWasm0(ptr, len) {
|
|
81
|
+
ptr = ptr >>> 0;
|
|
82
|
+
return decodeText(ptr, len);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let cachedUint8ArrayMemory0 = null;
|
|
86
|
+
function getUint8ArrayMemory0() {
|
|
87
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
88
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
89
|
+
}
|
|
90
|
+
return cachedUint8ArrayMemory0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
94
|
+
if (realloc === undefined) {
|
|
95
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
96
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
97
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
98
|
+
WASM_VECTOR_LEN = buf.length;
|
|
99
|
+
return ptr;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let len = arg.length;
|
|
103
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
104
|
+
|
|
105
|
+
const mem = getUint8ArrayMemory0();
|
|
106
|
+
|
|
107
|
+
let offset = 0;
|
|
108
|
+
|
|
109
|
+
for (; offset < len; offset++) {
|
|
110
|
+
const code = arg.charCodeAt(offset);
|
|
111
|
+
if (code > 0x7F) break;
|
|
112
|
+
mem[ptr + offset] = code;
|
|
113
|
+
}
|
|
114
|
+
if (offset !== len) {
|
|
115
|
+
if (offset !== 0) {
|
|
116
|
+
arg = arg.slice(offset);
|
|
117
|
+
}
|
|
118
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
119
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
120
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
121
|
+
|
|
122
|
+
offset += ret.written;
|
|
123
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
WASM_VECTOR_LEN = offset;
|
|
127
|
+
return ptr;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function takeFromExternrefTable0(idx) {
|
|
131
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
132
|
+
wasm.__externref_table_dealloc(idx);
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
137
|
+
cachedTextDecoder.decode();
|
|
138
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
139
|
+
let numBytesDecoded = 0;
|
|
140
|
+
function decodeText(ptr, len) {
|
|
141
|
+
numBytesDecoded += len;
|
|
142
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
143
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
144
|
+
cachedTextDecoder.decode();
|
|
145
|
+
numBytesDecoded = len;
|
|
146
|
+
}
|
|
147
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const cachedTextEncoder = new TextEncoder();
|
|
151
|
+
|
|
152
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
153
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
154
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
155
|
+
view.set(buf);
|
|
156
|
+
return {
|
|
157
|
+
read: arg.length,
|
|
158
|
+
written: buf.length
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let WASM_VECTOR_LEN = 0;
|
|
164
|
+
|
|
165
|
+
let wasmModule, wasm;
|
|
166
|
+
function __wbg_finalize_init(instance, module) {
|
|
167
|
+
wasm = instance.exports;
|
|
168
|
+
wasmModule = module;
|
|
169
|
+
cachedUint8ArrayMemory0 = null;
|
|
170
|
+
wasm.__wbindgen_start();
|
|
171
|
+
return wasm;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function __wbg_load(module, imports) {
|
|
175
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
176
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
177
|
+
try {
|
|
178
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
179
|
+
} catch (e) {
|
|
180
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
181
|
+
|
|
182
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
183
|
+
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);
|
|
184
|
+
|
|
185
|
+
} else { throw e; }
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const bytes = await module.arrayBuffer();
|
|
190
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
191
|
+
} else {
|
|
192
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
193
|
+
|
|
194
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
195
|
+
return { instance, module };
|
|
196
|
+
} else {
|
|
197
|
+
return instance;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function expectedResponseType(type) {
|
|
202
|
+
switch (type) {
|
|
203
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function initSync(module) {
|
|
210
|
+
if (wasm !== undefined) return wasm;
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
if (module !== undefined) {
|
|
214
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
215
|
+
({module} = module)
|
|
216
|
+
} else {
|
|
217
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const imports = __wbg_get_imports();
|
|
222
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
223
|
+
module = new WebAssembly.Module(module);
|
|
224
|
+
}
|
|
225
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
226
|
+
return __wbg_finalize_init(instance, module);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function __wbg_init(module_or_path) {
|
|
230
|
+
if (wasm !== undefined) return wasm;
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
if (module_or_path !== undefined) {
|
|
234
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
235
|
+
({module_or_path} = module_or_path)
|
|
236
|
+
} else {
|
|
237
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (module_or_path === undefined) {
|
|
242
|
+
module_or_path = new URL('mini_yaml_rs_bg.wasm', import.meta.url);
|
|
243
|
+
}
|
|
244
|
+
const imports = __wbg_get_imports();
|
|
245
|
+
|
|
246
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
247
|
+
module_or_path = fetch(module_or_path);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
251
|
+
|
|
252
|
+
return __wbg_finalize_init(instance, module);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mini-yaml-rs",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"Shawn Xiang <xiang.elec@domain.com>"
|
|
6
|
+
],
|
|
7
|
+
"description": "A minimalist, zero-copy parser for a strict subset of the YAML specification.",
|
|
8
|
+
"version": "0.1.5",
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/hecmay/mini-yaml-rs.git"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"mini_yaml_rs_bg.wasm",
|
|
16
|
+
"mini_yaml_rs.js",
|
|
17
|
+
"mini_yaml_rs.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"main": "mini_yaml_rs.js",
|
|
20
|
+
"homepage": "https://github.com/hecmay/mini-yaml-rs",
|
|
21
|
+
"types": "mini_yaml_rs.d.ts",
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"./snippets/*"
|
|
24
|
+
]
|
|
25
|
+
}
|