Skip to content

Commit

Permalink
fix: refactored zod and valibot validators
Browse files Browse the repository at this point in the history
  • Loading branch information
YannicEl committed Aug 23, 2023
1 parent 82afa69 commit 026a0be
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions packages/lib/src/validators/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,10 @@ const emojiRegex = /^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u;

export const emoji = defineValidator('emoji', (value) => regex(emojiRegex).validate(value));

export const zodValidator = defineValidatorWithArgs(
'zodValidator',
(value, schema: ZodSchema) => schema.safeParse(value).success
);
export function zodValidator(name: string, schema: ZodSchema) {
return defineValidator(name, (value) => schema.safeParse(value).success);
}

export const valibotValidator = defineValidatorWithArgs(
'valibotValidator',
(value, schema: ValibotSchema) => {
try {
return !!schema.parse(value);
} catch (error) {
console.log('hi');
return false;
}
}
);
export function valibotValidator(name: string, schema: ValibotSchema) {
return defineValidator(name, (value) => !!schema._parse(value).output);
}

0 comments on commit 026a0be

Please sign in to comment.