Where all things good come from! This Class uses JSON Schema Draft 4 to build basic models for the rest of the application. Please See json-schema.org and also ajv validator for the basics.

import {SchemaClass} from 'json-schema-class';
export MyClass extends 'SchemaClass'{
constructor(){
super({
"title": "Example Schema",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "lastName"]
});

let model = this;
model.firstName = "My"
model.lastName = "Class"

this.validate(model) //Validate model and add missing defaults
)
}

Constructors

Properties

Methods

Constructors

Properties

events: any

Event Emitter

merge: typeof main

A Merge utility for JavaScript Objects

schema: Object

The Schema for this Class

validator: any

Class Validator - Instance of ajv.compile()

Methods

  • Validate data against the current schema

    Parameters

    • data: Object

    Returns Object

    data