MCPcopy
hub / github.com/colinhacks/zod / getParsedType

Function getParsedType

packages/zod/src/v3/helpers/util.ts:175–224  ·  view source on GitHub ↗
(data: any)

Source from the content-addressed store, hash-verified

173export type ZodParsedType = keyof typeof ZodParsedType;
174
175export const getParsedType = (data: any): ZodParsedType => {
176 const t = typeof data;
177
178 switch (t) {
179 case "undefined":
180 return ZodParsedType.undefined;
181
182 case "string":
183 return ZodParsedType.string;
184
185 case "number":
186 return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
187
188 case "boolean":
189 return ZodParsedType.boolean;
190
191 case "function":
192 return ZodParsedType.function;
193
194 case "bigint":
195 return ZodParsedType.bigint;
196
197 case "symbol":
198 return ZodParsedType.symbol;
199
200 case "object":
201 if (Array.isArray(data)) {
202 return ZodParsedType.array;
203 }
204 if (data === null) {
205 return ZodParsedType.null;
206 }
207 if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
208 return ZodParsedType.promise;
209 }
210 if (typeof Map !== "undefined" && data instanceof Map) {
211 return ZodParsedType.map;
212 }
213 if (typeof Set !== "undefined" && data instanceof Set) {
214 return ZodParsedType.set;
215 }
216 if (typeof Date !== "undefined" && data instanceof Date) {
217 return ZodParsedType.date;
218 }
219 return ZodParsedType.object;
220
221 default:
222 return ZodParsedType.unknown;
223 }
224};

Callers 7

_getTypeFunction · 0.50
_getOrReturnCtxFunction · 0.50
_processInputParamsFunction · 0.50
safeParseFunction · 0.50
"~validate"Function · 0.50
safeParseAsyncFunction · 0.50
mergeValuesFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected