Validation & structured output
Validate without Zod
validation() only needs a safeParse() method matching Zod's shape -- write your own if you don't want the dependency.
← All recipes
import { Maskea, validation, type ZodLikeSchema } from "@nopeatech/maskea";
interface Invoice { total: number; currency: string }
const InvoiceSchema: ZodLikeSchema<Invoice> = {
safeParse(data: unknown) {
const d = data as Invoice;
if (typeof d?.total === "number" && typeof d?.currency === "string") {
return { success: true, data: d };
}
return { success: false, error: "missing total or currency" };
},
};
const maskea = new Maskea().use(validation({ schema: InvoiceSchema }));Checked against the shipped @nopeatech/maskea API. Full docs at nopea.tech/maskea/docs.