new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Zod · all subjects

codecs & bidirectional transforms

4 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Codecs implement bidirectional transformations

Codecs (introduced in zod@4.1) are schemas that implement bidirectional transformations between two other schemas. Created with z.codec(inputSchema, outputSchema, { decode, encode }). The decode function transforms input to output (used by .parse()), and encode transforms output back to input. Use z.invertCodec() to swap input and output schemas.

z.decode() for type-safe codec input

Unlike .parse() which accepts unknown input, z.decode() expects a strongly-typed input. For codec stringToDate: z.decode(stringToDate, "2024-01-15T10:30:00.000Z") expects a string input type.

z.encode() for codec reverse transformation

Use z.encode(codec, value) to perform the reverse transformation on a codec. Example: z.encode(stringToDate, new Date("2024-01-15")) returns "2024-01-15T00:00:00.000Z".

Common codec implementations available

Zod provides implementations for commonly-used codecs: stringToNumber, stringToInt, stringToBigInt, numberToBigInt, isoDatetimeToDate, epochSecondsToDate, epochMillisToDate, jsonCodec, utf8ToBytes, bytesToUtf8, base64ToBytes, base64urlToBytes, hexToBytes, stringToURL, stringToHttpURL, uriComponent, stringToBoolean. These are documented on the Codecs page.

Give your agent this brain