max
max(limit, [closed=true])
作用
限制被检测数组长度的最大值。
参数
limit(number) - 数组长度的最大值[closed](boolean) - 是否闭区间,默认true, 表示闭区间,要求被检测数组长度须小于或等于limit. 若closed明确为false, 则表示开区间,要求被检测数组长度必须严格大于limit。
示例
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]); // pass最后更新于
这有帮助吗?