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

Class ZodBoolean

packages/zod/src/v3/types.ts:1833–1859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1831}
1832
1833export class ZodBoolean extends ZodType<boolean, ZodBooleanDef, boolean> {
1834 _parse(input: ParseInput): ParseReturnType<boolean> {
1835 if (this._def.coerce) {
1836 input.data = Boolean(input.data);
1837 }
1838 const parsedType = this._getType(input);
1839
1840 if (parsedType !== ZodParsedType.boolean) {
1841 const ctx = this._getOrReturnCtx(input);
1842 addIssueToContext(ctx, {
1843 code: ZodIssueCode.invalid_type,
1844 expected: ZodParsedType.boolean,
1845 received: ctx.parsedType,
1846 });
1847 return INVALID;
1848 }
1849 return OK(input.data);
1850 }
1851
1852 static create = (params?: RawCreateParams & { coerce?: boolean }): ZodBoolean => {
1853 return new ZodBoolean({
1854 typeName: ZodFirstPartyTypeKind.ZodBoolean,
1855 coerce: params?.coerce || false,
1856 ...processCreateParams(params),
1857 });
1858 };
1859}
1860
1861///////////////////////////////////////
1862///////////////////////////////////////

Callers

nothing calls this directly

Calls 1

processCreateParamsFunction · 0.85

Tested by

no test coverage detected