mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-28 21:24:19 +01:00
12 lines
321 B
TypeScript
12 lines
321 B
TypeScript
import { z } from "zod"
|
|
|
|
export function fn<T extends z.ZodType, Result>(schema: T, cb: (input: z.infer<T>) => Result) {
|
|
const result = (input: z.infer<T>) => {
|
|
const parsed = schema.parse(input)
|
|
return cb(parsed)
|
|
}
|
|
result.force = (input: z.infer<T>) => cb(input)
|
|
result.schema = schema
|
|
return result
|
|
}
|