Field Types
Primitives
Below is a list of general options supported by all primitive and built-in types.
Options
-
required :
booleanThe value is required and may not be undefined, though may be
null. (Default:false) -
nullable :
booleanThe value may or may not be null. (Default:
true)
Array
The field should be an array. For an array of specified elements, consider using PerfectSchema.ArrayOf(type%)
Options
-
minCount :
NumberThe minimum number of elements allowed in the array (Default:
0) -
maxCount :
NumberThe maximum number of elements allowed in the array (Default:
Infinity)
Boolean
The field should be a strict boolean value of true or false.
Date
The field should be an instance of Date and be a valid date value.
Options
-
minDate :
Date|NumberThe earliest date allowed (Default:
-Infinity) -
maxDate :
Date|NumberThe latest date allowed (Default:
Infinity)
Number
The field should be a strict number, and not NaN.
Options
-
minNumber :
NumberThe smallest value allowed (Default:
-Infinity) -
maxNumber :
NumberThe highest value allowed (Default:
Infinity)
Object
The field should be an instanceo of Object.
String
The field should be a string.
Options
-
minLength :
NumberThe smallest string allowed (Default:
0) -
maxLength :
NumberThe largest string allowed (Default:
Infinity)
Built-in types
PerfectSchema.Any
A wildcard type whose value can be anything. This is intended to be an unchecked, blackbox type.
const schema = new PerfectSchema({
foo: PerfectSchema.Any,
bar: {
type: PerfectSchema.Any
}
});
PerfectSchema.AnyOf(type%[, type%[, ...]])
Like the Any built-in type, but restricts the actual wildcard types.
const schema = new PerfectSchema({
foo: PerfectSchema.AnyOf(String, Number, Date),
bar: {
type: PerfectSchema.ArrayOf(PerfectSchema.AnyOf(String, Number))
}
});
PerfectSchema.ArrayOf(type%)
Like the Array type, but specify element type(s).
const schema = new PerfectSchema({
foo: PerfectSchema.ArrayOf(String),
bar: {
type: PerfectSchema.ArrayOf(PerfectSchema.AnyOf(String, Number))
}
});
Options
All options from ![]()
Array are inherited.
-
timeout :
NumberThe timeout in milliseconds before array element validation should abort (Default:
200)Warning : validation will not return until all array elements are either checked or when the timeout expires.
PerfectSchema.Integer
The field should be a strict integer between, and not be Infinity or NaN.
const schema = new PerfectSchema({
foo: PerfectSchema.Any,
bar: {
type: PerfectSchema.Integer
}
});
Options
All options from ![]()
Number are inherited.