mtype-tv4
Extends mtype type checking facade to support JSON schema via TV4.
Mtype functions can be used to test that an object complies with a specified JSON schema.
i.e. const result = mtype.is( myObj, 'schemaName' )
Usage
// Sample Schemaconst personSchema = 'id': 'person' // Use this id to refer to this schema in Mtype calls 'type': 'object' 'properties': 'name': 'type': 'string' 'title': 'type': 'string' 'age': 'type': 'number' 'required': 'name' 'title' const productSchema = 'id': 'product' // Use this id to refer to this schema in Mtype calls 'type': 'object' 'properties': 'desc': 'type': 'string' 'price': 'type': 'number' 'required': 'desc' 'price' // Note: Property names are discarded. Reference schema using 'id' value. e.g. 'person'const schemas = a: personSchema b: productSchema // create TV4 instance loaded with passed schemasconst validator = // create mtype instance backed by TV4 instance created aboveconst t = Validator // Test dataconst trump = name: 'Trump' title: 'SCROTUS' age : 70 const hat = 'desc': 'red maga hat' 'price': 1999 // test against schema etcconsole // trueconsole // falseconsole // trueconsole // trueconsole // [ 'person', 'product' ]
license
MIT