better-schemas
A simple schema validation implementation for NodeJs.
Usage
const Schema =
Create a schema for well-defined structures
const postSchema = 'user.post' name : type: String required: true // throws when not set description: String // optional { var data = reqbody try postSchema res catche }
Define your own base-types
const MyType = 'my type' n == 1ifMyType console
Define your own Schemas
const MySchema = 'my-schema' key : type:SchemaTypesAny default: 'value' // sets default when undefined arrays: type: String simple_types: Number helper_types: SchemaTypesInteger name : type:String required: true var data = MySchema // undefined & null are replaced by defaults
Retrieve schemas by name
const MySchema = Schema
Create a nested Schema
const MySchema = Schemaconst MyOtherSchema = 'complex-schema' name: type: String required: true data: MySchema