( schema: T, )
| 11 | } from "zod"; |
| 12 | |
| 13 | export function getOptions<T extends ZodSchema>( |
| 14 | schema: T, |
| 15 | ): undefined | z.infer<T>[] { |
| 16 | if (schema instanceof z.ZodLiteral) { |
| 17 | return [schema.value] as z.infer<T>[]; |
| 18 | } else if (schema instanceof z.ZodEnum) { |
| 19 | return schema.options as z.infer<T>[]; |
| 20 | } else if (schema instanceof z.ZodBoolean) { |
| 21 | return [false, true] as z.infer<T>[]; |
| 22 | } else if (schema instanceof z.ZodUnion) { |
| 23 | return (schema.options as ZodSchema[]) |
| 24 | .flatMap(getOptions) |
| 25 | .filter((it) => it !== undefined) as z.infer<T>[]; |
| 26 | } |
| 27 | return undefined; |
| 28 | } |
| 29 | |
| 30 | export function getZodType(schema: ZodTypeAny): ZodFirstPartyTypeKind { |
| 31 | // oxlint-disable-next-line typescript/no-unsafe-assignment typescript/no-unsafe-member-access |
no outgoing calls
no test coverage detected