@formspec/validator
v0.1.0-alpha.28
Published
JSON Schema validator for FormSpec — backed by @cfworker/json-schema, safe for secure runtimes
Maintainers
Readme
@formspec/validator
Runtime JSON Schema validation for FormSpec, backed by @cfworker/json-schema.
This package is intended for environments where code-generating validators are a bad fit, including workers and CSP-restricted runtimes.
Install
pnpm add @formspec/validatorUsage
import { createFormSpecValidator } from "@formspec/validator";
const validator = createFormSpecValidator({
type: "object",
required: ["name"],
properties: {
name: { type: "string" },
country: { type: "string", "x-formspec-source": "countries" },
},
});
const result = validator.validate({ name: "Alice", country: "us" });Unknown x-formspec-* keywords are ignored by the underlying validator, so generated schemas work without extra vocabulary registration.
Main Exports
createFormSpecValidator(schema, options?)CreateValidatorOptionsValidatorValidationResultOutputUnitSchemaDraft
License
This package is part of the FormSpec monorepo and is released under the MIT License. See LICENSE for details.
