The type of the object to be processed.
The Zod type representing the pattern for matching sub-objects.
The type of the object returned by the callback function.
The parameters for the function.
A callback function that is called for each matching sub-object and returns a new object to replace it.
The Zod pattern used to match sub-objects
within value
.
Optional
shouldThe object to be processed.
// Example usage
const obj = { a: { type: "match", data: 1 }, b: { data: 2 } }
const pattern = z.object({ type: z.literal("match") })
const result = replaceByPattern({
value: obj,
pattern,
fn: (ctx) => ({ newData: ctx.data * 2 }),
})
console.log(result)
// Output: { a: { newData: 2 }, b: { data: 2 } }
Generated using TypeDoc
Modifies an object by replacing each nested object that matches a specified Zod pattern with a new object returned by a callback function.
Ignores the root object or array.
*** Ignores any processing done by zod such as stripping away extra properties. ***