Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test(value) {
return value == null || +value > this.resolve(moreThan);
},
});
},
positive(msg = '${path} must be a positive amount') {
return this.min(0, msg);
},
negative(msg = '${path} must be a negative amount') {
return this.max(0, msg);
},
});
yup.setLocale(locale);
yup.amount = AmountSchema;
yup.addMethod(yup.string, 'name', function nameMethod(message) {
const nameRegex = /^[a-zA-Z]+( [a-zA-Z]+)*$/;
// eslint-disable-next-line no-template-curly-in-string
return this.test('name', locale.string.name, function nameTest() {
return nameRegex.test(this.options.originalValue) || this.createError({ message });
});
});
export default yup;
setAWSCredentials(e) {
e.preventDefault();
const { awsAccessKeyId, awsSecretAccessKey, awsRegion } = this.state;
const awsCredentials = { awsAccessKeyId, awsSecretAccessKey, awsRegion };
// Create custom instructions for Yup error handling
setLocale({
mixed: { notOneOf: 'AWS Region is required' },
string: {
min: 'Please enter a valid AWS credential',
max: 'Please enter a valid AWS credential',
},
});
// Define Yup Error Schema
const awsCredentialsSchema = object().strict().shape({
awsAccessKeyId: string().required('Please enter a valid AWS Access Key Id').min(15).max(40),
awsSecretAccessKey: string().required('Please enter a valid AWS Secret Access Key').min(30).max(50),
awsRegion: mixed().required('AWS Region is required').notOneOf(['default']),
});
awsCredentialsSchema.validate(awsCredentials, { abortEarly: false })
.then((data) => {
this.setState(prevState => ({
...prevState,
export function setLanguageCode(arg) {
if (!languages[arg]) {
throw new Error(`Invalid language ${arg}.`);
}
moment.locale(arg);
localStorage.setItem('language', arg);
if (getLanguage().dictionary.validation) {
setYupLocale(getLanguage().dictionary.validation);
}
}