cross-stitch - v2.0.0
    Preparing search index...

    Function encodePattern

    Public entry point (cross-stitch). Exposes the blessed surface: the validate/serialize facade, the derived-data helpers, and every type needed to describe and work with a pattern - none of which require importing Zod. The Zod schema objects themselves (for composition with .pick / .extend or direct .safeParse) are published separately on the cross-stitch/schema subpath.

    • Serialize a validated pattern to a JSON string. Throws if given an invalid pattern; use encodePatternSafe for a non-throwing variant.

      Parameters

      • pattern: {
            colors: {
                hex?: string;
                id: number & $brand<"ColorId">;
                name: string;
                strands: {
                    brand:
                        | "Anchor"
                        | "Appletons"
                        | "Cosmo"
                        | "DMC"
                        | "J&P Coats"
                        | "Kreinik"
                        | "Madeira"
                        | "Presencia"
                        | "Sullivans"
                        | "Unbranded";
                    code: string;
                    hex?: string;
                    name: string;
                    strandCount: number;
                }[];
                symbol: string;
            }[];
            fabric?: { count: number; hex?: string; kind?: string };
            metadata?: {
                author?: string;
                copyright?: string;
                notes?: string;
                title?: string;
            };
            schemaVersion: 1;
            stitches: (
                | {
                    colorId: number & $brand<"ColorId">;
                    kind: "full";
                    x: number & $brand<"CellCoordinate">;
                    y: number & $brand<"CellCoordinate">;
                }
                | {
                    angle: "tl-br"
                    | "bl-tr";
                    colorId: number & $brand<"ColorId">;
                    kind: "half";
                    x: number & $brand<"CellCoordinate">;
                    y: number & $brand<"CellCoordinate">;
                }
                | {
                    colorId: number & $brand<"ColorId">;
                    kind: "quarter";
                    placement: "top-right" | "bottom-right" | "bottom-left" | "top-left";
                    x: number & $brand<"CellCoordinate">;
                    y: number & $brand<"CellCoordinate">;
                }
                | {
                    angle: "tl-br"
                    | "bl-tr";
                    colorId: number & $brand<"ColorId">;
                    kind: "three-quarter";
                    placement: "top-right" | "bottom-right" | "bottom-left" | "top-left";
                    x: number & $brand<"CellCoordinate">;
                    y: number & $brand<"CellCoordinate">;
                }
                | {
                    colorId: number & $brand<"ColorId">;
                    from: {
                        x: number & $brand<"SegmentCoordinate">;
                        y: number & $brand<"SegmentCoordinate">;
                    };
                    kind: "back";
                    to: {
                        x: number & $brand<"SegmentCoordinate">;
                        y: number & $brand<"SegmentCoordinate">;
                    };
                }
                | {
                    colorId: number & $brand<"ColorId">;
                    from: {
                        x: number & $brand<"SegmentCoordinate">;
                        y: number & $brand<"SegmentCoordinate">;
                    };
                    kind: "long";
                    to: {
                        x: number & $brand<"SegmentCoordinate">;
                        y: number & $brand<"SegmentCoordinate">;
                    };
                }
            )[];
        }

        The validated pattern to serialize.

      Returns string

      The pattern as a JSON string.