(
check?: (data: any) => any,
_params: string | CustomParams | ((input: any) => CustomParams) = {},
/**
* @deprecated
*
* Pass `fatal` into the params object instead:
*
* ```ts
* z.string().custom((val) => val.length > 5, { fatal: false })
* ```
*
*/
fatal?: boolean
)
| 4913 | } |
| 4914 | type CustomParams = CustomErrorParams & { fatal?: boolean }; |
| 4915 | export function custom<T>( |
| 4916 | check?: (data: any) => any, |
| 4917 | _params: string | CustomParams | ((input: any) => CustomParams) = {}, |
| 4918 | /** |
| 4919 | * @deprecated |
| 4920 | * |
| 4921 | * Pass `fatal` into the params object instead: |
| 4922 | * |
| 4923 | * ```ts |
| 4924 | * z.string().custom((val) => val.length > 5, { fatal: false }) |
| 4925 | * ``` |
| 4926 | * |
| 4927 | */ |
| 4928 | fatal?: boolean |
| 4929 | ): ZodType<T, ZodTypeDef, T> { |
| 4930 | if (check) |
| 4931 | return ZodAny.create().superRefine((data, ctx) => { |
| 4932 | const r = check(data); |
| 4933 | if (r instanceof Promise) { |
| 4934 | return r.then((r) => { |
| 4935 | if (!r) { |
| 4936 | const params = cleanParams(_params, data); |
| 4937 | const _fatal = params.fatal ?? fatal ?? true; |
| 4938 | ctx.addIssue({ code: "custom", ...params, fatal: _fatal }); |
| 4939 | } |
| 4940 | }); |
| 4941 | } |
| 4942 | if (!r) { |
| 4943 | const params = cleanParams(_params, data); |
| 4944 | const _fatal = params.fatal ?? fatal ?? true; |
| 4945 | ctx.addIssue({ code: "custom", ...params, fatal: _fatal }); |
| 4946 | } |
| 4947 | return; |
| 4948 | }); |
| 4949 | return ZodAny.create(); |
| 4950 | } |
| 4951 | |
| 4952 | export { ZodType as Schema, ZodType as ZodSchema }; |
| 4953 |
no test coverage detected