required

required([strict=false])

作用

限制被检测值不为undefined | null.

若开启严格模式(strict=true), 则被检测值不允许为undefined | null | []

参数

  • [strict] (boolean) - 是否开启严格模式,默认为false不开启。若明确设置strict=true则开启严格模式。

示例

const schema1 = racoon.array();
schema1.validate(undefined); // pass, 返回值为 undefined
schema1.validate(null); // pass, 返回值为 null
schema1.validate([]); // pass, 返回值为 []

const schema2 = racoon.array().required();
schema2.validate(undefined); // fail
schema2.validate(null); // fail
schema2.validate([]); // pass

const schema3 = racoon.array().required(true);
schema3.validate(undefined); // fail
schema3.validate(null); // fail
schema3.validate([]); // fail

最后更新于