Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jankaszel/validate-web-annotation

Validate JSON objects against the Web Annotation Data Model specification
https://github.com/jankaszel/validate-web-annotation

annotation validation web-annotation

Last synced: 17 days ago
JSON representation

Validate JSON objects against the Web Annotation Data Model specification

Awesome Lists containing this project

README

        

# Validating Web Annotations

A JavaScript library for validating JSON objects against the [Web Annotation Data Model (WADM) specification](https://www.w3.org/TR/annotation-model/) via [JSON Schema](https://json-schema.org).

`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.

## API

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.

```js
// 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);
```

## Benchmarks

In order to collect benchmarks on the schema-based validation approach, run the benchmarking suite (which uses [benchmark.js](https://benchmarkjs.com)) via `npm run bench`.

## License

MIT