max
max(limit, [closed=true])
Effect
Restrict the max length of the detected array.
Arguments
limit(number) - The max length.[closed](boolean) - Whether it is a closed interval or not, the default istrue, which means a closed interval, it requires the detected array's length less than or equal tolimit. If you exactly setclosedtofalse, you'll get an opened interval, it requires the detected array's length strictly less thanlimit.
Example
const schema = racoon.array(racoon.number()).max(3);
schema.validate([1, 2, 3, 4]); // fail
schema.validate([1, 2, 3]); // pass
schema.validate([1, 2, 3, 4]); // pass
const schema2 = racoon.array(racoon.number()).max(3, false);
schema2.validate([1, 2]); // fail
schema2.validate([1, 2, 3]); // fail
schema2.validate([1, 2, 3, 4]); // passLast updated
Was this helpful?