Open-source IoT Platform - Device management, data collection, processing and visualization.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

33 lines
725 B

var inspector = require('../');
// Custom type schema
var customValidation = {
validDate: function (schema, date) {
if (schema.$validDate === true
&& Object.prototype.toString.call(date) === "[object Date]"
&& isNaN(date.getTime())) {
this.report('must be a valid date');
}
}
};
inspector.Validation.extend(customValidation);
var data = {
validDate: new Date(),
invalidDate: new Date('invalid'),
noDate: 'hello!'
};
var schema = {
type: 'object',
items: {
type: 'date',
$validDate: true
}
};
var result = inspector.validate(schema, data);
console.log(result.format());
/*
Property @[invalidDate]: must be a valid date
Property @[noDate]: must be date, but is string
*/