Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function validate(validator: t.Type, data: any, location: string): any { // eslint-disable-line @typescript-eslint/no-explicit-any
const result = validator.decode(data);
const report = reporter(result);
if (isLeft(result)) {
report.unshift('The following errors occured during validation in `' + location + '`:');
let newReport = report.join('\n ');
let regex = /Expecting (\w+) at (\w+)\.0 but instead got: (.+)\.\n *Expecting (\w+) at \w+\.1 but instead got: (.+)\./g;
newReport = newReport.replace(regex, chalk`Expecting {bold.blue $1} or {bold.blue $4} at {bold.green $2} but instead got {bold.red $3}`);
regex = /Expecting (\w+) at (\w+) but instead got: (.+)\./g;
newReport = newReport.replace(regex, chalk`Expecting {bold.blue $1} at {bold.green $2} but instead got {bold.red $3}`);
log().e(newReport).from('•_•').now();
return null;
} else {
return result.right;
export function validateSerializedHttpArray(records: object[]) {
const result = t.array(SerializedHttp).decode(records);
if (result.isLeft()) {
const errs = reporter(result);
throw new YesNoError(`Invalid serialized HTTP. (Errors: ${errs.join(', ')})`);
}
}