Licence
MIT
Version
0.1.5
Deps
1
Size
9 kB
Vulns
0
Weekly
0
@famtree/validate
Validate famtree genogram documents against
@famtree/schema using
Ajv (JSON Schema Draft 2020-12).
To keep the footprint small, ajv is an optional peer dependency — it's loaded lazily
only when you actually validate.
Install
npm install @famtree/validate ajv
If you install @famtree/validate without ajv, calling validate() throws a clear
error telling you to add ajv.
Usage
import { validate } from "@famtree/validate"
try {
await validate(doc) // doc: unknown
// doc conforms to famtree.schema.json
} catch (err) {
// Either ajv is missing, or the document is invalid.
// Invalid-document errors list each failing path and message.
console.error((err as Error).message)
}
validate(doc: unknown): Promise<void>
- Resolves when
docmatches the schema. - Rejects with an
Errorwhose message aggregates all schema violations (allErrors: true), each as• <path> <message>. - Rejects with an install hint if the optional
ajvdependency is not present.
It's async because ajv is imported on demand the first time you validate.
Notes
- This package validates structure against the JSON Schema. Deeper semantic checks (dangling references, duplicate ids, proband uniqueness, …) are tracked separately.
- The
@famtree/cli--validateflag uses this package under the hood.
Related packages
| Package | Description |
|---|---|
@famtree/cli |
famtree command-line renderer |
@famtree/schema |
JSON Schema + TypeScript types |
@famtree/renderer |
SVG renderer |
@famtree/core |
Domain graph + layout engine |
License
MIT Felipe Plets