/
opt
/
canhelp
/
node_modules
/
@hono
/
zod-validator
/
dist
/
/opt/canhelp/node_modules/@hono/zod-validator/dist
mkdir
upload
Name
Size
Mode
Actions
index.cjs
2185
0644
edit
dl
rm
index.d.cts
1263
0644
edit
dl
rm
index.d.ts
1263
0644
edit
dl
rm
index.js
1142
0644
edit
dl
rm
Edit:
/opt/canhelp/node_modules/@hono/zod-validator/dist/index.js
(1142B)
// src/index.ts import { validator } from "hono/validator"; import { ZodObject } from "zod"; var zValidator = (target, schema, hook) => ( // @ts-expect-error not typed well validator(target, async (value, c) => { let validatorValue = value; if (target === "header" && schema instanceof ZodObject) { const schemaKeys = Object.keys(schema.shape); const caseInsensitiveKeymap = Object.fromEntries( schemaKeys.map((key) => [key.toLowerCase(), key]) ); validatorValue = Object.fromEntries( Object.entries(value).map(([key, value2]) => [caseInsensitiveKeymap[key] || key, value2]) ); } const result = await schema.safeParseAsync(validatorValue); if (hook) { const hookResult = await hook({ data: validatorValue, ...result, target }, c); if (hookResult) { if (hookResult instanceof Response) { return hookResult; } if ("response" in hookResult) { return hookResult.response; } } } if (!result.success) { return c.json(result, 400); } return result.data; }) ); export { zValidator };
Save
cmd:
run