A minimalist, zero-copy parser for a strict subset of the YAML specification.
npm install mini-yaml-rsA minimalist, zero-copy YAML parser for Rust. Supports sequences, mappings, and custom tags.
- Zero-copy parsing (returns references to input)
- Sequences and mappings (flow and block styles)
- Custom tag support: !tagname becomes __type: "tagname"
- Works in both Rust backend (Tauri) and WebAssembly
``toml`
[dependencies]
mini-yaml-rs = "0.2"
`bash`
npm install mini-yaml-rs
`bashBuild Rust library (for Tauri/backend)
make build-rust
Usage
$3
`rust
use mini_yaml_rs::parse;let yaml = parse(r#"
+setupSettings:
title: Settings
authors[]:
- !mod +@Me{}
- !mod +@Boby at Unix Group
signature:
pubkey: |
MCowBQYDK2VwAyEAGb9F2CMlxqLDB3rrzBVwC7aB...
created: 2024-06-01T12:00:00Z
modified: 2024-06-01T12:00:00Z
"#).unwrap();
// Returns Yaml<'_> enum - use to_json() for serde_json::Value
let json = yaml.to_json();
println!("{}", json);
`Output:
`json
{
"+setupSettings": {
"title": "Settings",
"authors":
{
"__type": "mod",
"+@[Me"
},
{
"__type": "mod",
"+@Boby at Unix Group"
}
],
"signature": {
"pubkey": "MCowBQYDK2VwAyEAGb9F2CMlxqLDB3rrzBVwC7aB..."
},
"created": "2024-06-01T12:00:00Z",
"modified": "2024-06-01T12:00:00Z"
}
}
`$3
The
to_mx() method transforms keys in +namelabel format:`rust
use mini_yaml_rs::parse;let yaml = parse(r#"
+setupSettings:
title: Settings
enabled: true
"#).unwrap();
let mx = yaml.to_mx();
println!("{}", mx);
`Output:
`json
{
"+setup": {
"__name": "Settings",
"__value": "db://settings",
"title": "Settings",
"enabled": true
}
}
`The key
+setupSettings becomes +setup with:
- __name = bracket content (Settings)
- __value = paren content (db://settings, optional)$3
Tags are converted to
__type fields:`yaml
!person {name: John} # → {__type: "person", name: "John"}
!custom_tag [1, 2, 3] # → {__type: "custom_tag", __value: [1, 2, 3]}
`$3
Unquoted scalar values are automatically converted to native types:
`yaml
42 # → 42 (as integer)
-123 # → -123 (as integer)
3.14 # → 3.14 (as float)
1.0e10 # → 1.0e10 (as float)
true # → true (as boolean)
false # → false (as boolean)
yes/no # → true/false (as boolean)
on/off # → true/false (as boolean)Keep these as strings by quoting:
"42" # → "42" (string, quotes stripped)
'true' # → "true" (string, quotes stripped)
`$3
All functions return plain JavaScript objects (not
Map objects), making them easy to use with standard JS object syntax.`typescript
import init, { parseYaml, parseYamlToMx, printYaml } from 'mini-yaml-rs';// Initialize WASM module
await init();
// Parse YAML → JavaScript object (no JSON.parse needed)
const obj = parseYaml(
);
console.log(obj.name); // "hello"
console.log(obj.value); // 42
console.log(obj.items); // ["one", "two"]// Convert JavaScript object → YAML string
const yaml = printYaml({
title: "My Config",
enabled: true,
settings: {
theme: "dark",
fontSize: 14
}
});
console.log(yaml);
// title: My Config
// enabled: true
// settings:
// theme: dark
// fontSize: 14
// Parse with mx transformation
const mx = parseYamlToMx(
);
console.log(mx["+setup"].__name); // "Settings"
console.log(mx["+setup"].__value); // "db://settings"
``Apache-2.0. See LICENSE.
Based on minimal-yaml by Nathan Whitaker.