How to use io-ts-reporters - 3 common examples

To help you get started, we’ve selected a few io-ts-reporters examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github u32i64 / vk-chat-bot / src / extra / log.ts View on Github external
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;
github FormidableLabs / yesno / src / http-serializer.ts View on Github external
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(', ')})`);
  }
}

io-ts-reporters

Formatting of io-ts validation errors

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis

Popular io-ts-reporters functions