diff --git a/src/fn/index.ts b/src/fn/index.ts index b5904c5b..2d635853 100644 --- a/src/fn/index.ts +++ b/src/fn/index.ts @@ -84,3 +84,4 @@ export { sot343 } from "./sot343" export { m2host } from "./m2host" export { mountedpcbmodule } from "./mountedpcbmodule" export { to92l } from "./to92l" +export { pdip } from "./pdip" diff --git a/src/fn/pdip.ts b/src/fn/pdip.ts new file mode 100644 index 00000000..ab8a51ce --- /dev/null +++ b/src/fn/pdip.ts @@ -0,0 +1,24 @@ +import { dip, extendDipDef } from "./dip" +import { z } from "zod" + +export const pdip_def = extendDipDef({ w: "300mil", p: "2.54mm" }).extend({ + fn: z.string(), +}) + +export const pdip = (raw_params: { + pdip: true + num_pins: number + w: number + p?: number + id?: string | number + od?: string | number +}) => { + return dip({ + dip: true, + num_pins: raw_params.num_pins, + w: raw_params.w, + p: raw_params.p, + id: raw_params.id, + od: raw_params.od, + }) +} diff --git a/src/footprinter.ts b/src/footprinter.ts index ac09348d..458d2d96 100644 --- a/src/footprinter.ts +++ b/src/footprinter.ts @@ -40,6 +40,9 @@ export type Footprinter = { dip: ( num_pins?: number, ) => FootprinterParamsBuilder<"w" | "p" | "id" | "od" | "wide" | "narrow"> + pdip: ( + num_pins?: number, + ) => FootprinterParamsBuilder<"w" | "p" | "id" | "od" | "wide" | "narrow"> cap: () => FootprinterParamsBuilder crystal: ( num_pins?: number, diff --git a/tests/pdip.test.ts b/tests/pdip.test.ts new file mode 100644 index 00000000..79824add --- /dev/null +++ b/tests/pdip.test.ts @@ -0,0 +1,35 @@ +import { test, expect } from "bun:test" +import { convertCircuitJsonToPcbSvg } from "circuit-to-svg" +import { fp } from "../src/footprinter" +import type { AnyCircuitElement } from "circuit-json" + +test("pdip8", () => { + const circuitJson = fp.string("pdip8").circuitJson() as AnyCircuitElement[] + const svgContent = convertCircuitJsonToPcbSvg(circuitJson) + expect(svgContent).toMatchSvgSnapshot(import.meta.path, "pdip8") +}) + +test("pdip8 matches dip8 with same defaults", () => { + const pdipJson = fp.string("pdip8").json() + const dipJson = fp.string("dip8").json() + + expect(pdipJson.num_pins).toBe(8) + expect(pdipJson.w).toBe(dipJson.w) + expect(pdipJson.p).toBe(dipJson.p) + expect(pdipJson.id).toBe(dipJson.id) + expect(pdipJson.od).toBe(dipJson.od) +}) + +test("pdip8 with custom width", () => { + const circuitJson = fp + .string("pdip8_w7.62mm") + .circuitJson() as AnyCircuitElement[] + const svgContent = convertCircuitJsonToPcbSvg(circuitJson) + expect(svgContent).toMatchSvgSnapshot(import.meta.path, "pdip8_w7.62mm") +}) + +test("pdip14", () => { + const circuitJson = fp.string("pdip14").circuitJson() as AnyCircuitElement[] + const svgContent = convertCircuitJsonToPcbSvg(circuitJson) + expect(svgContent).toMatchSvgSnapshot(import.meta.path, "pdip14") +})