@zpl-toolchain/core
v0.1.12
Published
ZPL II toolchain — parse, validate, format, and print Zebra Programming Language files (see @zpl-toolchain/print for printing)
Maintainers
Readme
@zpl-toolchain/core
TypeScript wrapper for the ZPL toolchain WASM bindings. Provides full TypeScript types and an ergonomic API for parsing, validating, formatting, and explaining ZPL code.
Part of the zpl-toolchain project.
Installation
npm install @zpl-toolchain/coreUsage
import { init, parse, format, validate, explain } from "@zpl-toolchain/core";
// Initialize WASM module (required once before calling any function)
await init();
// Parse ZPL
const result = parse("^XA^FDHello^FS^XZ");
console.log(result.ast.labels.length); // 1
// Format ZPL
const formatted = format("^XA^FD Hello ^FS^XZ", "label");
// Validate ZPL
const validation = validate("^XA^FDHello^FS^XZ");
console.log(validation.ok); // true
// Explain a diagnostic code
const explanation = explain("ZPL1201");API
| Function | Signature | Description |
|---|---|---|
| init() | () → Promise<void> | Initialize WASM module (call once) |
| parse(input) | (string) → ParseResult | Parse ZPL, return AST + diagnostics |
| parseWithTables(input, tablesJson) | (string, string) → ParseResult | Parse with explicit parser tables |
| validate(input, profileJson?) | (string, string?) → ValidationResult | Parse + validate |
| validateWithTables(input, tablesJson, profileJson?) | (string, string, string?) → ValidationResult | Parse + validate with explicit parser tables |
| format(input, indent?) | (string, IndentStyle?) → string | Format ZPL |
| explain(id) | (string) → string \| null | Explain a diagnostic code |
Errors thrown by the WASM layer are wrapped with operation context (for example, @zpl-toolchain/core parse failed: ...) to make failures easier to diagnose in logs and callers.
Types
All types are exported and match the Rust AST serialization format:
Node— discriminated union onkind:CommandNode | FieldDataNode | RawDataNode | TriviaNodeSeverity—"error" | "warn" | "info"(lowercase, matching Rust serde)Presence—"unset" | "empty" | "value"(lowercase)IndentStyle—"none" | "label" | "field"ValidationResult.resolved_labels— optional renderer-ready per-label resolved state snapshots
See src/index.ts for the full type definitions.
Build from source
# Install dependencies
npm install
# Build WASM artifacts (requires wasm-pack)
npm run build:wasm
# Build TypeScript package
npm run build