• Modifies an object by merging additional properties returned by a callback function onto each nested object that matches a specified Zod pattern. This function performs a post-order depth-first search (DFS) traversal of the object, applying the transformation wherever the pattern matches.

    *** Ignores any processing done by zod such as stripping away extra properties. ***

    Type Parameters

    • TValue extends object

      The type of the object to be processed. Must be an object type.

    • TPattern extends ZodObject<ZodRawShape, UnknownKeysParam, ZodTypeAny, {}, {}>

      The Zod type representing the pattern for matching sub-objects within the object. Must be a Zod type that infers to a record (object) structure.

    • TReturn extends Record<string, any>

      The type of the object returned by the callback function. This type's properties are merged into the matching sub-objects.

    Parameters

    • params: {
          fn: ((ctx) => TReturn);
          pattern: TPattern;
          shouldClone?: boolean;
          value: TValue;
      }

      The parameters for the function.

      • fn: ((ctx) => TReturn)
          • (ctx): TReturn
          • A callback function that is invoked for each sub-object matching the pattern. The function should return an object whose properties will be merged into the matching sub-object.

            Parameters

            • ctx: Extract<ExtractObjectsDeep<TValue>, TypeOf<TPattern>> & Record<string, any>

            Returns TReturn

      • pattern: TPattern

        The Zod pattern used to match sub-objects within value. Sub-objects that match this pattern are transformed by the callback function.

      • Optional shouldClone?: boolean
      • value: TValue

        The object to be processed. This object is traversed to find sub-objects that match the given pattern.

    Returns SpreadDeepObject<TValue, z.infer<TPattern>, TReturn>

    • The modified object. This type is a complex type that results from recursively applying the transformation to all matching sub-objects in value.

    See demo fixture in tests/patternMatch.test.ts for example use.

Generated using TypeDoc