mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-27 19:54:56 +01:00
wip: zen
This commit is contained in:
11
packages/console/core/src/util/fn.ts
Normal file
11
packages/console/core/src/util/fn.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user