mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
13 lines
399 B
TypeScript
13 lines
399 B
TypeScript
import { z, ZodTypeAny } from "zod";
|
|
|
|
// this is a patched zod string to remove empty string to undefined
|
|
export const zpStr = <T extends ZodTypeAny>(
|
|
schema: T,
|
|
opt: { stripNull: boolean } = { stripNull: true }
|
|
) =>
|
|
z.preprocess((val) => {
|
|
if (opt.stripNull && val === null) return undefined;
|
|
if (typeof val !== "string") return val;
|
|
return val.trim() || undefined;
|
|
}, schema);
|