A JavaScript library for validating JSON objects against the Web Annotation Data Model (WADM) specification via JSON Schema.
npm install validate-web-annotation
This library is still under active development and only partially covers the WADM specification. While most general-purpose properties of an annotation are being properly validated (e.g., id
, target
, body
), more specific properties such as purpose
and state
are missing validation. I intend this library to perform efficiently and general-purpose rather than covering the whole WADM specification. I'll explicitly specify the validation coverage in future versions.
This library exposes a simple function for validating annotations:
validateAnnotation(annotation, opts = {})
Options:
optionalId
: The annotation's ID (annotation.id
) becomes optional. Suited for validating not-yet-persisted annotations.
Returns a boolean value on whether the input is valid or not.
// see ./example.js for a full example
const validateAnnotation = require("validate-web-annotation");
const annotation = {
"@context": "http://www.w3.org/ns/anno.jsonld",
id: "http://example.org/anno1",
type: "Annotation",
// ...
};
const valid = validateAnnotation(annotation);
In order to collect benchmarks on the schema-based validation approach, run the benchmarking suite (which uses benchmark.js) via npm run bench
.
MIT