Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
numSchema.lessThan(5, () => 'lt');
numSchema.moreThan(5);
numSchema.moreThan(5, 'mt');
numSchema.moreThan(5, () => 'mt');
numSchema.integer();
numSchema.integer('int');
numSchema.integer(() => 'int');
numSchema.truncate();
numSchema.round('floor');
numSchema
.validate(5, { strict: true })
.then(value => value)
.catch(err => err);
// Boolean Schema
const boolSchema = yup.boolean();
boolSchema.isValid(true); // => true
// Date Schema
const dateSchema = yup.date();
dateSchema.isValid(new Date()); // => true
dateSchema.min(new Date());
dateSchema.min('2017-11-12');
dateSchema.min(new Date(), 'message');
dateSchema.min('2017-11-12', 'message');
dateSchema.min('2017-11-12', () => 'message');
dateSchema.max(new Date());
dateSchema.max('2017-11-12');
dateSchema.max(new Date(), 'message');
dateSchema.max('2017-11-12', 'message');
dateSchema.max('2017-11-12', () => 'message');
comments: string(),
memory_limit: number(),
run_level: mixed().oneOf(['default', 'single', 'binbash']),
virt_mode: mixed().oneOf(['paravirt', 'fullvirt']),
helpers,
root_device: string()
});
export const CreateLinodeDiskSchema = object({
size: number().required('Disk size is required.'),
label: string()
.required('A disk label is required.')
.min(1, 'Label must be between 1 and 48 characters.')
.max(48, 'Label must be between 1 and 48 characters.'),
filesystem: mixed().oneOf(['raw', 'swap', 'ext3', 'ext4', 'initrd']),
read_only: boolean(),
image: string(),
authorized_keys: array().of(string()),
authorized_users: array().of(string()),
root_pass: string().when('image', {
is: value => Boolean(value),
then: string()
.required(
'You must provide a root password when deploying from an image.'
)
.concat(rootPasswordValidation),
// .test('is-strong-password', 'Please choose a stronger password.', (value: string) => return zxcvbn(value).score > 3),
otherwise: string().notRequired()
}),
stackscript_id: number(),
stackscript_data
});
clientId: yup.string(),
})).max(10, 'Only 10 users may be used.'),
otherwise: yup.array().notRequired()
}),
customMeterDimensions: yup.array().of(
yup.object().uniqueProperty('meterName', 'No duplicate Meters')
.shape({
meterName: yup.mixed().when('isDeleted', {
is: (val) => {
return !!val === false
},
then: yup.string().required('Meter is required'),
otherwise: yup.mixed().notRequired()
}),
planName: yup.string(),
monthlyUnlimited: yup.boolean(),
annualUnlimited: yup.boolean(),
monthlyQuantityIncludedInBase: yup.number().test('validNumber', 'Not a valid integer', (val): boolean => {
if (val === null || val === undefined || val === '') {
return true;
} else {
return yup.number().integer().isValidSync(val);
}
}).min(0, "Value must be an int greater or equal to 0")
.required("Included in Base is a required field"),
annualQuantityIncludedInBase: yup.number(),
clientId: yup.string(),
})),
privatePlan: yup.boolean(),
isNew: yup.boolean(),
status: yup.string(),
createdTime: yup.string(),
description: Yup.string(),
bedroom: Yup.number(),
bathroom: Yup.number(),
location: Yup.object().shape({
address: Yup.string(),
lat: Yup.number(),
lng: Yup.number(),
}),
price: Yup.number(),
haveInternet: Yup.boolean(),
haveAirCond: Yup.boolean(),
petsAllowed: Yup.boolean(),
photos: Yup.array().of(Yup.string()),
haveHeating: Yup.boolean(),
haveTv: Yup.boolean(),
isActive: Yup.boolean(),
maxGuest: Yup.number(),
});
try {
await schema.validate(info);
const place = await PlaceModel.findById(placeId);
if (place) {
if (place.owner.toString() === ownerId.toString()) {
(Object.keys(info) as (keyof PlaceInfo)[]).forEach(key => {
place[key] = info[key];
});
return place.save();
}
best: string[];
employed: boolean;
date: Date;
hello: string;
cities: string;
gender: string;
birthday: Date;
break: Date;
hidden: string;
}
const schema = Yup.object().shape({
best: Yup.array()
.min(1)
.required(),
employed: Yup.boolean().required(),
date: Yup.date().required(),
hello: Yup.string().required(),
cities: Yup.string().required(),
gender: Yup.string().required(),
birthday: Yup.date().required(),
break: Yup.date().required(),
hidden: Yup.string().required(),
});
/**
* Uses the optional helper makeValidate function to format the error messages
* into something usable by final form.
*/
const validate = makeValidate(schema);
/**
fileImport: 'File Import',
file: 'File',
formatInfo: 'Format Information',
createDevices: 'Create Devices',
selectAFile: 'Please select a template file',
fileInfoPlaceholder: 'Please select a template format',
claimAuthCode: 'Set claim authentication code',
targetedComponents: 'Targeted Components',
})
const validationSchema = Yup.object({
format_id: Yup.string().required(sharedMessages.validateRequired),
data: Yup.string().required(m.selectAFile),
set_claim_auth_code: Yup.boolean(),
components: Yup.object({
is: Yup.boolean().required(),
as: Yup.boolean(),
js: Yup.boolean(),
ns: Yup.boolean(),
}).required(sharedMessages.validateRequired),
})
export default class DeviceBulkCreateForm extends Component {
static propTypes = {
components: PropTypes.components.isRequired,
initialValues: PropTypes.shape({
format_id: PropTypes.string,
data: PropTypes.string,
set_claim_auth_code: PropTypes.bool,
}).isRequired,
onSubmit: PropTypes.func.isRequired,
}
.typeError('Weight must be a number.')
.min(1, `Weight must be between 1 and 255.`)
.max(255, `Weight must be between 1 and 255.`),
mode: mixed().oneOf(['accept', 'reject', 'backup', 'drain'])
});
export const createNodeBalancerConfigSchema = 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()
}),
check_timeout: number()
.typeError('Timeout must be a number.')
.integer(),
check: mixed().oneOf(['none', 'connection', 'http', 'http_body']),
cipher_suite: mixed().oneOf(['recommended', 'legacy']),
port: number()
@Validate(yup.lazy(() => Period.schema()))
public period?: FlatConvectorModel;
}
export class PatientCommunication extends BackboneElement {
@Default('fhir.datatypes.Patient.PatientCommunication')
@ReadOnly()
public readonly type: string;
@Required()
@Validate(yup.lazy(() => CodeableConcept.schema()))
public language: FlatConvectorModel;
@Validate(yup.boolean())
public preferred?: boolean;
}
export class PatientLink extends BackboneElement {
@Default('fhir.datatypes.Patient.PatientLink')
@ReadOnly()
public readonly type: string;
@Required()
@Validate(yup.lazy(() => Reference.schema()))
public other: FlatConvectorModel; //Patient|RelatedPerson
@Required()
@Validate(yup.string())
public type_: string;
.max(9999, 'Expiration year must be four digits.'),
expiry_month: number()
.required('Expiration month is required.')
.min(1, 'Expiration month must be a number from 1 to 12.')
.max(12, 'Expiration month must be a number from 1 to 12.')
});
export const CreateUserSchema = object({
username: string()
.required('Username is required.')
.min(3, 'Username must be between 3 and 32 characters.')
.max(32, 'Username must be between 3 and 32 characters.'),
email: string()
.required('Email address is required.')
.email('Must be a valid email address.'),
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'],
createDevices: 'Create Devices',
selectAFile: 'Please select a template file',
fileInfoPlaceholder: 'Please select a template format',
claimAuthCode: 'Set claim authentication code',
targetedComponents: 'Targeted Components',
})
const validationSchema = Yup.object({
format_id: Yup.string().required(sharedMessages.validateRequired),
data: Yup.string().required(m.selectAFile),
set_claim_auth_code: Yup.boolean(),
components: Yup.object({
is: Yup.boolean().required(),
as: Yup.boolean(),
js: Yup.boolean(),
ns: Yup.boolean(),
}).required(sharedMessages.validateRequired),
})
export default class DeviceBulkCreateForm extends Component {
static propTypes = {
components: PropTypes.components.isRequired,
initialValues: PropTypes.shape({
format_id: PropTypes.string,
data: PropTypes.string,
set_claim_auth_code: PropTypes.bool,
}).isRequired,
onSubmit: PropTypes.func.isRequired,
}
state = {
allowedFileExtensions: undefined,