-
-
Notifications
You must be signed in to change notification settings - Fork 1
Array
Alan Berdinelli edited this page Mar 24, 2021
·
7 revisions
Array type validates the value is an Array. Then, if you also define the type of the elements, it checks all the elements are the correct type.
const Schemy = require('schemy');
const Example = new Schemy({
data: {
type: []
}
});Will fail if any of the elements inside the array is not a string.
const Schemy = require('schemy');
const Example = new Schemy({
data: {
type: [String]
}
});Will fail if any of the elements inside the array is not a number.
const Schemy = require('schemy');
const Example = new Schemy({
data: {
type: [Number]
}
});Will fail if any of the elements fails the schema validation.
const Schemy = require('schemy');
const childSchema = new Schemy({
title: { type: String }
});
const Example = new Schemy({
data: {
type: [childSchema]
}
});You can also pass schema objects as array items and schemy will validate them for you:
const Example = new Schemy({
data: [{ title: String }]
});Since 1.9.0, you can set a min and/or max number of elements within an array:
const Example = new Schemy({
items: {
type: [],
min: 1,
max: 10
}
});Developed with ♥ by Alan Berdinelli.