schema-definition
v1.0.0
Published
A schema definition module for consumption by modeling libraries (or as a validator)
Downloads
3
Readme
schema.js
A JavaScript module for defining data schemas for consumption by modeling libraries
npm install --save schema-definition
var Schema = require('schema-definition');
var contactInfoSchema = new Schema({
phone: { type: String, regex: /^[0-9]{3}\.[0-9]{3}\.[0-9]{4}$/ },
email: { type: String, regex: /^.+@.+$/ }
})
var personSchema = new Schema({
name: String,
dateOfBirth: Date,
contactInfo: contactInfoSchema,
emergencyContacts: [ contactInfoSchema ]
});
personSchema.validate({
name: 'Bob',
dateOfBirth: '1990-1-1',
contactInfo: {
phone: '555.555.5555',
email: '[email protected]'
}
});
personSchema.validateProperty('name', 'Bob');