yup .oneOf

node v10.24.1
version: master
endpointsharetweet
const { string } = require("yup"); const fruits = ["banana", "apple"]; const nullable = string().oneOf(fruits).nullable(); const withNull = string().oneOf([...fruits, null]); const nullableWithNull = string().oneOf([...fruits, null]).nullable(); console.log({ nullable: await nullable.isValid(null), withNull: await withNull.isValid(null), nullableWithNull: await nullableWithNull.isValid(null) });
Loading…

no comments

    sign in to comment