Update valibot, finally

Signed-off-by: Nicole Mikołajczyk <git@mkljczk.pl>
This commit is contained in:
Nicole Mikołajczyk
2025-05-25 14:47:22 +02:00
parent 6d0116292e
commit 691d1aecf5
6 changed files with 35 additions and 29 deletions

View File

@ -30,11 +30,14 @@ const emojiSchema = v.pipe(v.string(), v.emoji());
const mimeSchema = v.pipe(v.string(), v.regex(/^\w+\/[-+.\w]+$/));
/** valibot schema to force the value into an object, if it isn't already. */
const coerceObject = <T extends v.ObjectEntries>(shape: T) =>
v.pipe(
v.any(),
v.transform((input) => typeof input === 'object' && input !== null ? input : {}),
v.object(shape),
);
const coerceObject = <T extends v.ObjectEntries>(shape: T): v.ObjectSchema<T, undefined> =>
v.optional(
v.pipe(
v.any(),
v.transform((input) => typeof input === 'object' && input !== null ? input : {}),
v.object(shape),
),
{},
) as any;
export { filteredArray, emojiSchema, datetimeSchema, dateSchema, mimeSchema, coerceObject };