@manuscripts/json-schema
TypeScript icon, indicating that this package has built-in type declarations

2.2.7 • Public • Published

json-schema

The Manuscripts JSON Schema types and validation functions.

Build

yarn build

Validation

To validate a document against the schema, the validate function can be used:

import { validate } from '@manuscripts/json-schema';

const document = {
    objectType: 'MPManuscript'
};

const error = validate(document);
if (!error) {
    console.log('document is valid');
} else {
    console.log(`document is invalid: ${error}`);
}

The schema is selected based on the objectType property of the document.

Types

A Typescript interface is generated (and included in the package) for each abstract/concrete schema:

import { Model } from '@manuscripts/json-schema';

function getId(document: Model) {
    return document._id;
}

An ObjectTypes enum is also available that includes all supported types with their corresponding objectType value:

import { Model, ObjectTypes } from '@manuscripts/json-schema';

function isManuscript(document: Model) {
    return document.objectType === ObjectTypes.Manuscript;
}

Readme

Keywords

none

Package Sidebar

Install

npm i @manuscripts/json-schema

Weekly Downloads

480

Version

2.2.7

License

Apache-2.0

Unpacked Size

3.97 MB

Total Files

23

Last publish

Collaborators

  • maci