Skip to main content

Crate hedl_wasm

Crate hedl_wasm 

Source
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§

HedlDocument
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.