Expand description
HEDL WebAssembly Bindings
This crate provides WebAssembly bindings for HEDL, enabling HEDL parsing and manipulation in browsers and other JavaScript/TypeScript environments.
§Usage (JavaScript/TypeScript)
import init, { parse, toJson, fromJson, format, validate, getStats } from 'hedl-wasm';
await init();
// Parse HEDL
const doc = parse(`
%VERSION 1.0
%STRUCT User[id, name, email]
---
users:@User
| alice | Alice Smith | alice@example.com |
| bob | Bob Jones | bob@example.com |
`);
// Convert to JSON
const json = toJson(doc);
// Convert JSON to HEDL
const hedl = fromJson(jsonData);
// Format HEDL
const formatted = format(hedlString);
// Validate HEDL
const result = validate(hedlString);
if (!result.valid) {
console.error(result.errors);
}
// Get token statistics
const stats = getStats(hedlString);
console.log(`Token savings: ${stats.savingsPercent}%`);Structs§
- Hedl
Document - Parsed HEDL document wrapper.
Constants§
- DEFAULT_
MAX_ INPUT_ SIZE - Default maximum input size: 500 MB
This is a conservative default that balances memory safety with practical use cases.
Can be customized using
setMaxInputSize()for larger documents.
Functions§
- compare_
tokens - Compare HEDL and JSON token counts in real-time.
- format
- Format HEDL to canonical form.
- from_
csv - Convert CSV string to HEDL.
- from_
json - Convert JSON string to HEDL.
- from_
toon - Convert TOON string to HEDL.
- from_
xml - Convert XML string to HEDL.
- from_
yaml - Convert YAML string to HEDL.
- get_
max_ input_ size - Get the current maximum input size in bytes.
- get_
stats - Get token usage statistics.
- init
- Initialize panic hook for error handling.
- parse
- Parse a HEDL string and return a document.
- set_
max_ input_ size - Set the maximum input size in bytes.
- to_csv
- Convert HEDL string to CSV.
- to_json
- Convert HEDL string to JSON.
- to_toon
- Convert HEDL string to TOON.
- to_xml
- Convert HEDL string to XML.
- to_yaml
- Convert HEDL string to YAML.
- validate
- Validate HEDL and return detailed diagnostics.
- version
- HEDL version constant.