Validator
The validator checks xtyle definitions against the JSON Schema specification. It catches structural errors, type mismatches, and invalid token values.
Installation
Section titled “Installation”npm install @xtylejs/validateCLI Usage
Section titled “CLI Usage”npx xtyle-validate brand.xtyle.jsonExits with code 0 if valid, code 1 if invalid (with error details printed to stderr).
Programmatic Usage
Section titled “Programmatic Usage”import { validate, validateFile } from "@xtylejs/validate";
const result = validate({ xtyle: "1.0", name: "my-brand", visual: { colors: { palette: { ocean: "#0077B6" }, }, },});
if (result.valid) { console.log("Definition is valid.");} else { for (const issue of result.issues) { console.error(`${issue.path}: ${issue.message}`); }}validate(definition)
Section titled “validate(definition)”Validates a parsed definition object.
Returns { valid: boolean, issues: ValidationIssue[] }.
validateFile(filePath)
Section titled “validateFile(filePath)”Reads a JSON file from disk and validates it.
Returns { valid: boolean, issues: ValidationIssue[] }.
ValidationIssue
Section titled “ValidationIssue”interface ValidationIssue { path: string; // JSON pointer to the invalid token message: string; // Human-readable error description}