diff --git a/src/fn/pad.ts b/src/fn/pad.ts index 4bce6f0a..3081f3fd 100644 --- a/src/fn/pad.ts +++ b/src/fn/pad.ts @@ -7,8 +7,12 @@ import { mm } from "@tscircuit/mm" import { base_def } from "../helpers/zod/base_def" export const pad_def = base_def.extend({ - w: length, - h: length, + w: length.optional(), + h: length.optional(), + width: length.optional(), + height: length.optional(), + s: length.optional(), + size: length.optional(), }) export type PadDef = z.input @@ -16,9 +20,10 @@ export type PadDef = z.input export const pad = ( params: PadDef, ): { circuitJson: AnySoupElement[]; parameters: PadDef } => { - const { w, h } = params - const width = mm(w) - const height = mm(h) + const width = mm(params.w ?? params.width ?? params.s ?? params.size ?? "1mm") + const height = mm( + params.h ?? params.height ?? params.s ?? params.size ?? "1mm", + ) return { circuitJson: [ diff --git a/tests/pad-bare-string.test.ts b/tests/pad-bare-string.test.ts new file mode 100644 index 00000000..b30f6685 --- /dev/null +++ b/tests/pad-bare-string.test.ts @@ -0,0 +1,20 @@ +import { test, expect } from "bun:test" +import { fp } from "../src" + +test("pad bare string defaults to 1mm dimensions (#788)", () => { + const circuitJson = fp.string("pad").circuitJson() + + const smtpads = circuitJson.filter((e) => e.type === "pcb_smtpad") as any[] + expect(smtpads.length).toBe(1) + expect(smtpads[0].width).toBe(1) + expect(smtpads[0].height).toBe(1) +}) + +test("pad with specified dimensions parses properly", () => { + const circuitJson = fp.string("pad_w2mm_h3mm").circuitJson() + + const smtpads = circuitJson.filter((e) => e.type === "pcb_smtpad") as any[] + expect(smtpads.length).toBe(1) + expect(smtpads[0].width).toBe(2) + expect(smtpads[0].height).toBe(3) +})