Skip to content

Commit b4fc3d2

Browse files
committed
Transfers responsibility of verifying value to SchemaType
1 parent a27aa94 commit b4fc3d2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/schema.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ export default class Schema {
2929
}
3030

3131
verifyType(prop, value) {
32-
const schemaType = this.schemaTypes[prop];
33-
if (value === null && schemaType.nullable) return true;
34-
return schemaType.type === value.constructor;
32+
return this.schemaTypes[prop].verify(value);
3533
}
3634

3735
getDefault(prop) {

lib/schematype.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const defaults = {
22
String: null,
33
Number: null,
44
Boolean: false,
5-
Date: Date.now,
5+
Date: () => new Date,
66
Model: null,
77
};
88

@@ -20,4 +20,9 @@ export default class SchemaType {
2020
this.nullable = typeof type.nullable === 'boolean' ? type.nullable : true;
2121
}
2222
}
23+
24+
verify(value) {
25+
if (value === null && this.nullable) return true;
26+
return this.type === value.constructor;
27+
}
2328
}

0 commit comments

Comments
 (0)