Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const createYupSchemaAttribute = (type, validations) => {
let schema = yup.mixed();
if (
['string', 'text', 'richtext', 'email', 'password', 'enumeration'].includes(
type
)
) {
schema = yup.string();
}
if (type === 'json') {
schema = yup
.mixed(errorsTrads.json)
.test('isJSON', errorsTrads.json, value => {
if (value === undefined) {
return true;
}
try {
JSON.parse(value);
return true;
} catch (err) {
return false;
}
})
.nullable();
}
if (type === 'email') {
const createYupSchemaAttribute = (type, validations) => {
let schema = yup.mixed();
if (
['string', 'text', 'richtext', 'email', 'password', 'enumeration'].includes(
type
)
) {
schema = yup.string();
}
if (type === 'json') {
schema = yup
.mixed(errorsTrads.json)
.test('isJSON', errorsTrads.json, value => {
if (value === undefined) {
return true;
}
if (
isNumber(value) ||
isNull(value) ||
isObject(value) ||
isArray(value)
) {
return true;
}
try {
JSON.parse(value);
return true;
const createYupSchemaAttribute = (type, validations) => {
let schema = yup.mixed();
if (
['string', 'text', 'richtext', 'email', 'password', 'enumeration'].includes(
type
)
) {
schema = yup.string();
}
if (type === 'json') {
schema = yup
.mixed(errorsTrads.json)
.test('isJSON', errorsTrads.json, value => {
if (value === undefined) {
return true;
}
if (
isNumber(value) ||
isNull(value) ||
isObject(value) ||
isArray(value)
) {
return true;
}
try {
JSON.parse(value);
const createYupSchemaAttribute = (type, validations) => {
let schema = yup.mixed();
if (
['string', 'text', 'richtext', 'email', 'password', 'enumeration'].includes(
type
)
) {
schema = yup.string();
}
if (type === 'json') {
schema = yup
.mixed(errorsTrads.json)
.test('isJSON', errorsTrads.json, value => {
if (value === undefined) {
return true;
}
try {
JSON.parse(value);
return true;
} catch (err) {
return false;
}
})
.nullable();
}
if (type === 'email') {
schema = schema.email(errorsTrads.email);