-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core[patch]: Add isZodSchema to core utils
- Loading branch information
1 parent
4a5cd29
commit c31a6af
Showing
4 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { type z } from "zod"; | ||
|
||
/** | ||
* Given either a Zod schema, or plain object, determine if the input is a Zod schema. | ||
* | ||
* @param {z.ZodType<RunOutput> | Record<string, any>} input | ||
* @returns {boolean} Whether or not the provided input is a Zod schema. | ||
*/ | ||
export function isZodSchema< | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
RunOutput extends Record<string, any> = Record<string, any> | ||
>( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
input: z.ZodType<RunOutput> | Record<string, any> | ||
): input is z.ZodType<RunOutput> { | ||
// Check for a characteristic method of Zod schemas | ||
return typeof (input as z.ZodType<RunOutput>)?.parse === "function"; | ||
} |