1.0.0 • Published 9 years ago

schema-definition v1.0.0

Weekly downloads
5
License
ISC
Repository
github
Last release
9 years ago

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: 'bob@example.com'
	}
});

personSchema.validateProperty('name', 'Bob');