tscircuit/autorouting-dataset-01
This code manages the hardware and electronic components for circuit design and PCB layout, defining components like resistors, capacitors, transistors, connectors, and footprints, and providing tools for component placement, PCB topology, and electrical connections.
- Version
- 1.0.102
- License
- unset
- Stars
- 4
scripts/random-circuits/getFootprinterPinNames.ts
import { fp } from "@tscircuit/footprinter"
/**
* Builds a pin list from a footprinter circuit JSON.
*/
export const getFootprinterPinNames = (footprint: string): string[] => {
const circuitJson = fp.string(footprint).circuitJson()
const numericPinHints = new Set<string>()
const namedPinHints = new Set<string>()
let padCount = 0
for (const element of circuitJson) {
const typed = element as { type?: string; port_hints?: string[] }
if (typed.type === "pcb_smtpad" || typed.type === "pcb_plated_hole") {
padCount += 1
}
if (Array.isArray(typed.port_hints)) {
for (const hint of typed.port_hints) {
const hintString = String(hint)
if (/^\d+$/.test(hintString)) {
numericPinHints.add(hintString)
} else {
namedPinHints.add(hintString)
}
}
}
}
switch (true) {
case numericPinHints.size > 0:
return [...numericPinHints]
.map((value) => Number(value))
.sort((a, b) => a - b)
.map((value) => `pin${value}`)
case namedPinHints.size > 0:
return [...namedPinHints]
case padCount > 0:
return Array.from({ length: padCount }, (_, index) => `pin${index + 1}`)
default:
return []
}
}