Skip to content

Validator

The validator checks xtyle definitions against the JSON Schema specification. It catches structural errors, type mismatches, and invalid token values.

Terminal window
npm install @xtylejs/validate
Terminal window
npx xtyle-validate brand.xtyle.json

Exits with code 0 if valid, code 1 if invalid (with error details printed to stderr).

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}`);
}
}

Validates a parsed definition object.

Returns { valid: boolean, issues: ValidationIssue[] }.

Reads a JSON file from disk and validates it.

Returns { valid: boolean, issues: ValidationIssue[] }.

interface ValidationIssue {
path: string; // JSON pointer to the invalid token
message: string; // Human-readable error description
}