Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,17 @@ export const footprinter = (): Footprinter & {
} else {
target[prop] = true
target.fn = prop
if (prop === "res" || prop === "cap") {
if (
prop === "res" ||
prop === "cap" ||
prop === "led" ||
prop === "diode"
) {
if (v) {
if (typeof v === "string" && v.includes("_metric")) {
target.metric = v.split("_metric")[0]
} else {
target.imperial = v // e.g., res0402, cap0603 etc.
target.imperial = v // e.g., res0402, cap0603, led0805 etc.
}
}
} else {
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/diode0402_string.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/__snapshots__/diode0805_string.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/__snapshots__/diode1206_string.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/__snapshots__/led0402_string.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/__snapshots__/led0805_string.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/__snapshots__/led1206_string.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions tests/diode-string-parsing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("diode0402 string produces 2 SMT pads with correct imperial size", () => {
const soup = fp.string("diode0402").circuitJson()
const pads = soup.filter((e: any) => e.type === "pcb_smtpad")
expect(pads).toHaveLength(2)

const pad1 = pads.find((p: any) => p.port_hints?.includes("1"))
expect(pad1).toBeDefined()
expect(pad1!.width).toBeCloseTo(0.54, 1)
expect(pad1!.height).toBeCloseTo(0.64, 1)

const svgContent = convertCircuitJsonToPcbSvg(soup)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "diode0402_string")
})
16 changes: 16 additions & 0 deletions tests/diode-string-parsing2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect, test } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("diode0805 string produces 2 SMT pads with correct imperial size", () => {
const soup = fp.string("diode0805").circuitJson()
const pads = soup.filter((e: any) => e.type === "pcb_smtpad")
expect(pads).toHaveLength(2)

const pad1 = pads.find((p: any) => p.port_hints?.includes("1"))
expect(pad1!.width).toBeCloseTo(1.025, 2)
expect(pad1!.height).toBeCloseTo(1.4, 1)

const svgContent = convertCircuitJsonToPcbSvg(soup)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "diode0805_string")
})
12 changes: 12 additions & 0 deletions tests/diode-string-parsing3.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect, test } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("diode1206 string produces 2 SMT pads", () => {
const soup = fp.string("diode1206").circuitJson()
const pads = soup.filter((e: any) => e.type === "pcb_smtpad")
expect(pads).toHaveLength(2)

const svgContent = convertCircuitJsonToPcbSvg(soup)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "diode1206_string")
})
19 changes: 19 additions & 0 deletions tests/diode-string-parsing4.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect, test } from "bun:test"
import { fp } from "../src/footprinter"

test("diode string matches diode builder API output", () => {
const fromString = fp.string("diode0603").circuitJson()
const fromBuilder = fp().diode().imperial("0603").circuitJson()

const stringPads = fromString.filter((e: any) => e.type === "pcb_smtpad")
const builderPads = fromBuilder.filter((e: any) => e.type === "pcb_smtpad")

expect(stringPads).toHaveLength(builderPads.length)

for (let i = 0; i < stringPads.length; i++) {
expect(stringPads[i].x).toBeCloseTo(builderPads[i].x, 5)
expect(stringPads[i].y).toBeCloseTo(builderPads[i].y, 5)
expect(stringPads[i].width).toBeCloseTo(builderPads[i].width, 5)
expect(stringPads[i].height).toBeCloseTo(builderPads[i].height, 5)
}
})
8 changes: 8 additions & 0 deletions tests/diode-string-parsing5.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, test } from "bun:test"
import { fp } from "../src/footprinter"

test("diode0402_metric string uses metric lookup", () => {
const params = fp.string("diode1005_metric").params()
expect(params.metric).toBe("1005")
expect(params.fn).toBe("diode")
})
8 changes: 8 additions & 0 deletions tests/diode-string-parsing6.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, test } from "bun:test"
import { fp } from "../src/footprinter"

test("diode0603_tht string produces through-hole pads", () => {
const soup = fp.string("diode0603_tht").circuitJson()
const holes = soup.filter((e: any) => e.type === "pcb_plated_hole")
expect(holes).toHaveLength(2)
})
19 changes: 19 additions & 0 deletions tests/led-string-parsing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect, test } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("led0402 string produces 2 SMT pads with correct imperial size", () => {
const soup = fp.string("led0402").circuitJson()
const pads = soup.filter((e: any) => e.type === "pcb_smtpad")
expect(pads).toHaveLength(2)

const pad1 = pads.find((p: any) => p.port_hints?.includes("1"))
const pad2 = pads.find((p: any) => p.port_hints?.includes("2"))
expect(pad1).toBeDefined()
expect(pad2).toBeDefined()
expect(pad1!.width).toBeCloseTo(0.54, 1)
expect(pad1!.height).toBeCloseTo(0.64, 1)

const svgContent = convertCircuitJsonToPcbSvg(soup)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "led0402_string")
})
16 changes: 16 additions & 0 deletions tests/led-string-parsing2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect, test } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("led0805 string produces 2 SMT pads with correct imperial size", () => {
const soup = fp.string("led0805").circuitJson()
const pads = soup.filter((e: any) => e.type === "pcb_smtpad")
expect(pads).toHaveLength(2)

const pad1 = pads.find((p: any) => p.port_hints?.includes("1"))
expect(pad1!.width).toBeCloseTo(1.025, 2)
expect(pad1!.height).toBeCloseTo(1.4, 1)

const svgContent = convertCircuitJsonToPcbSvg(soup)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "led0805_string")
})
12 changes: 12 additions & 0 deletions tests/led-string-parsing3.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect, test } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("led1206 string produces 2 SMT pads", () => {
const soup = fp.string("led1206").circuitJson()
const pads = soup.filter((e: any) => e.type === "pcb_smtpad")
expect(pads).toHaveLength(2)

const svgContent = convertCircuitJsonToPcbSvg(soup)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "led1206_string")
})
19 changes: 19 additions & 0 deletions tests/led-string-parsing4.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect, test } from "bun:test"
import { fp } from "../src/footprinter"

test("led string matches led builder API output", () => {
const fromString = fp.string("led0603").circuitJson()
const fromBuilder = fp().led().imperial("0603").circuitJson()

const stringPads = fromString.filter((e: any) => e.type === "pcb_smtpad")
const builderPads = fromBuilder.filter((e: any) => e.type === "pcb_smtpad")

expect(stringPads).toHaveLength(builderPads.length)

for (let i = 0; i < stringPads.length; i++) {
expect(stringPads[i].x).toBeCloseTo(builderPads[i].x, 5)
expect(stringPads[i].y).toBeCloseTo(builderPads[i].y, 5)
expect(stringPads[i].width).toBeCloseTo(builderPads[i].width, 5)
expect(stringPads[i].height).toBeCloseTo(builderPads[i].height, 5)
}
})
8 changes: 8 additions & 0 deletions tests/led-string-parsing5.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, test } from "bun:test"
import { fp } from "../src/footprinter"

test("led0402_metric string uses metric lookup", () => {
const params = fp.string("led1005_metric").params()
expect(params.metric).toBe("1005")
expect(params.fn).toBe("led")
})
Loading