Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
path: 'path',
errors: ['error'],
inner: [new yup.ValidationError('error', true, 'path')],
type: 'date',
value: { start: '2017-11-10' },
};
error.value = 'value';
error.value = true;
error.value = 5;
error.value = { name: 'value' };
error.type = {};
error.type = [];
error.errors = ['error'];
// mixed
let mixed: MixedSchema = yup.mixed();
mixed.clone();
mixed.label('label');
mixed.meta({ meta: 'value' });
mixed.describe().label;
mixed.describe().meta;
mixed.describe().tests;
mixed.describe().type;
mixed.concat(yup.string());
mixed.validate({});
mixed.validate({ hello: 'world' }, { strict: true }).then(value => value);
mixed.validateSync({ hello: 'world' }, { strict: true });
mixed.validateAt('path', {}, { strict: true, context: {} });
mixed.validateAt('path', {}, { strict: true, context: {} }).then(value => value);
mixed.validateSyncAt('path', {}, { strict: true, context: {} });
mixed.isValid(undefined, (valid: true) => true);
mixed.isValid({ hello: 'world' }).then(valid => valid);
import { Form } from '@rocketseat/unform';
import React from 'react';
import { hot } from 'react-hot-loader/root';
import * as Yup from 'yup';
import { TextField, Select, Checkbox } from '../../lib';
import GlobalStyles, { Section } from './styles';
// validation schema.
const schema = Yup.object().shape({
firstName: Yup.string(),
lastName: Yup.string(),
email: Yup.string(),
country: Yup.mixed(),
tech: Yup.mixed(),
withDefault: Yup.number(),
withError: Yup.string(),
multipleSelect: Yup.array(),
terms: Yup.boolean(),
acceptEmails: Yup.boolean(),
});
function App() {
function handleSubmit(payload) {
console.log(payload);
}
const initialData = {
firstName: 'Diego',
withDefault: 1,
.strict()
.required(),
)
.default([]),
htmlSerializer: yupMixed()
.test('is function', '${path} is not a function', isFunction)
.default(() => () => () => {}),
schemas: yupObject()
.strict()
.required(),
lang: yupString().default('*'),
shouldDownloadImage: yupMixed()
.test('is function', '${path} is not a function', isFunction)
.default(() => () => false),
// TODO: Remove `shouldNormalizeImage` in version 4
shouldNormalizeImage: yupMixed().test(
'is function',
'${path} is not a function',
x => typeof x === 'undefined' || isFunction(x),
),
plugins: yupArray()
.max(0)
.default([]),
// Default value set in validatePluginOptions below.
typePathsFilenamePrefix: yupString().default(`prismic-typepaths---`),
// Browser-only validations
pathResolver: yupMixed().test(
'is function',
'${path} is not a function',
x => typeof x === 'undefined' || isFunction(x),
),
const pluginLoose = yup.string();
const pluginStrict = yup.array().min(2).max(2)
.test(
'tuple',
'Plugin tuples must be [string, object]',
([name, cfg]) => yup.string().isValidSync(name) && yup.object().isValidSync(cfg),
);
const plugin = yup.mixed().test(
'plugin',
'Plugin definitions must be a string or [string, object]',
val => pluginLoose.isValidSync(val) || pluginStrict.isValidSync(val),
);
const every = yup.mixed().test(
'every',
'The "every" setting must be a number or a list of numbers',
val => yup.number().isValidSync(val) || yup.array().of(yup.number()),
);
const configFile = yup.object().shape({
spaces: yup.array().of(space),
every,
plugins: yup.array().of(plugin),
});
const configCLI = yup.object().shape({
dir: yup.string(),
space: yup.array().of(space),
spaces: yup.array().of(space),
every: yup.array().of(yup.number()),
restricted: boolean().required(
'You must indicate if this user should have restricted access.'
)
});
export const UpdateUserSchema = object({
username: string()
.min(3, 'Username must be between 3 and 32 characters.')
.max(32, 'Username must be between 3 and 32 characters.'),
email: string().email('Must be a valid email address.'),
restricted: boolean()
});
const GrantSchema = object({
id: number().required('ID is required.'),
permissions: mixed().oneOf(
[null, 'read_only', 'read_write'],
'Permissions must be null, read_only, or read_write.'
)
});
export const UpdateGrantSchema = object({
global: object(),
linode: array().of(GrantSchema),
domain: array().of(GrantSchema),
nodebalancer: array().of(GrantSchema),
image: array().of(GrantSchema),
longview: array().of(GrantSchema),
stackscript: array().of(GrantSchema),
volume: array().of(GrantSchema)
});
validationSchema: ({ t }: Props) =>
object().shape({
[FIELDS.hasInvestmentLimit]: boolean(),
[FIELDS.investmentLimit]: mixed().when(FIELDS.hasInvestmentLimit, {
is: true,
then: number()
.min(
0,
t("create-program-page.settings.validation.investment-limit-min")
)
.lessThan(
10000000000,
"Investment Limit must be less than 10000000000"
)
.required(
t(
"create-program-page.settings.validation.investment-limit-required"
)
)
})
is: protocol => protocol === 'https',
then: string().required('SSL key is required when using HTTPS.')
}),
ssl_cert: string().when('protocol', {
is: protocol => protocol === 'https',
then: string().required('SSL certificate is required when using HTTPS.')
}),
stickiness: mixed().oneOf(['none', 'table', 'http_cookie']),
nodes: array()
.of(nodeBalancerConfigNodeSchema)
.required()
.min(1, 'You must provide at least one back end node.')
});
export const UpdateNodeBalancerConfigSchema = object({
algorithm: mixed().oneOf(['roundrobin', 'leastconn', 'source']),
check_attempts: number(),
check_body: string().when('check', {
is: check => check === 'http_body',
then: string().required()
}),
check_interval: number().typeError('Check interval must be a number.'),
check_passive: boolean(),
check_path: string()
.matches(/\/.*/)
.when('check', {
is: check => check === 'http',
then: string().required()
})
.when('check', {
is: check => check === 'http_body',
then: string().required()
const {mixed} = require('yup')
module.exports = mixed().oneOf(['beginner', 'intermediate', 'advanced'])
otherwise: yup
.number()
.min(0)
.required(),
}),
salaryCurrency: optionSchema.when("noSalaryProvided", {
is: true,
then: optionSchema.notRequired(),
otherwise: optionSchema.required(),
}),
salaryPeriod: yup
.mixed<"hourly" | "weekly" | "monthly">()
.when("noSalaryProvided", {
is: true,
then: yup.mixed().notRequired(),
otherwise: yup
.mixed<"hourly" | "weekly" | "monthly">()
.oneOf(["hourly", "weekly", "monthly"]),
}),
noSalaryProvided: yup.boolean().notRequired(),
tags: yup
.array()
.of(optionSchema)
.nullable()
.notRequired(),
authorEmail: yup
.string()
.email()
.required(),
});
export type IAddReviewFields = yup.InferType;
import { array, boolean, mixed, number, object, string } from 'yup';
export const createServiceMonitorSchema = object().shape({
label: string()
.required('Label is required.')
.min(3, 'Label must be between 3 and 64 characters.')
.max(64, 'Label must be between 3 and 64 characters.'),
service_type: mixed()
.required('Monitor type is required.')
.oneOf(['url', 'tcp']),
address: string().required('URL is required.'),
timeout: number().required('Timeout is required.'),
credentials: array()
.of(number())
.notRequired(),
notes: string().notRequired(),
consultation_group: string().notRequired(),
body: string()
.notRequired()
.max(100, 'Body must be 100 characters or less.')
});
export const sshSettingSchema = object().shape({
access: boolean(),