rawCheck

Creates a raw check validation action.

const Action = v.rawCheck<TInput>(action);

Generics

  • TInput extends any

Parameters

Explanation

With rawCheck you can freely validate the input with a custom action and add issues if necessary.

Returns

Examples

The following examples show how rawCheck can be used.

Emails schema

Object schema that ensures that the primary email is not the same as any of the other emails.

This rawCheck validation action adds an issue for any invalid other email and forwards it via path to the appropriate nested field.

const EmailsSchema = v.pipe(
  v.object({
    primaryEmail: v.pipe(v.string(), v.email()),
    otherEmails: v.array(v.pipe(v.string(), v.email())),
  }),
  v.rawCheck(({ dataset, addIssue }) => {
    if (dataset.typed) {
      dataset.value.otherEmails.forEach((otherEmail, index) => {
        if (otherEmail === dataset.value.primaryEmail) {
          addIssue({
            message: 'This email is already being used as the primary email.',
            path: [
              {
                type: 'object',
                origin: 'value',
                input: dataset.value,
                key: 'otherEmails',
                value: dataset.value.otherEmails,
              },
              {
                type: 'array',
                origin: 'value',
                input: dataset.value.otherEmails,
                key: index,
                value: otherEmail,
              },
            ],
          });
        }
      });
    }
  })
);

The following APIs can be combined with rawCheck.

Schemas

Methods

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of dailydotdev
  • GitHub profile picture of Thanaen
  • GitHub profile picture of KATT
  • GitHub profile picture of osdiab
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of F0rce
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of seahindeniz