Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (input: Input) => {
if (skipOnEmpty && isEmpty(input)) {
return;
}
const matches = matcher(input);
if (matches) {
return;
}
if (typeof errorContent === 'function') {
return errorContent(input);
}
return errorContent;
};
};
return (input: Input, fields: Fields) => {
const matches = matcher(input, fields);
/*
always mark empty fields valid to match Polaris guidelines
https://polaris.shopify.com/patterns/error-messages#section-form-validation
*/
if (isEmpty(input)) {
return;
}
if (matches) {
return;
}
if (typeof errorContent === 'function') {
return errorContent(toString(input));
}
return errorContent;
};
}
export function lengthLessThan(length: number, error: ErrorContent) {
return validator(predicates.lengthLessThan(length))(error);
}
lengthLessThan(length: number, errorContent: ErrorContent) {
return validate(lengthLessThan(length), errorContent);
},
export function lengthMoreThan(length, error: ErrorContent) {
return validator(predicates.lengthMoreThan(length))(error);
}
lengthMoreThan(length: number, errorContent: ErrorContent) {
return validate(lengthMoreThan(length), errorContent);
},
export function numericString(error: ErrorContent) {
return validator(predicates.isNumericString)(error);
}
export function positiveIntegerString(error: ErrorContent) {
return validator(predicates.isPositiveIntegerString)(error);
}
export function positiveNumericString(error: ErrorContent) {
return validator(predicates.isPositiveNumericString)(error);
}
export function notEmpty(error: ErrorContent) {
return validator(predicates.notEmpty, {skipOnEmpty: false})(error);
}