diff --git a/lib/index.ts b/lib/index.ts index ed08f393..776df41d 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -8,6 +8,7 @@ export * from "./hooks/use-diode" export * from "./hooks/use-led" export * from "./hooks/use-resistor" export * from "./utils/public-exports" +export * from "./sel" // Allows easier introspection of render process export * from "./components/base-components/Renderable" diff --git a/lib/sel/index.ts b/lib/sel/index.ts new file mode 100644 index 00000000..1b5183b8 --- /dev/null +++ b/lib/sel/index.ts @@ -0,0 +1 @@ +export * from "./sel" diff --git a/lib/sel/sel-utility-types.ts b/lib/sel/sel-utility-types.ts new file mode 100644 index 00000000..0ae23103 --- /dev/null +++ b/lib/sel/sel-utility-types.ts @@ -0,0 +1,189 @@ +export type Nums16 = + | "1" + | "2" + | "3" + | "4" + | "5" + | "6" + | "7" + | "8" + | "9" + | "10" + | "11" + | "12" + | "13" + | "14" + | "15" + | "16" + +export type Nums40 = + | "1" + | "2" + | "3" + | "4" + | "5" + | "6" + | "7" + | "8" + | "9" + | "10" + | "11" + | "12" + | "13" + | "14" + | "15" + | "16" + | "17" + | "18" + | "19" + | "20" + | "21" + | "22" + | "23" + | "24" + | "25" + | "26" + | "27" + | "28" + | "29" + | "30" + | "31" + | "32" + | "33" + | "34" + | "35" + | "36" + | "37" + | "38" + | "39" + | "40" + +export type PinNumbers100 = + | "pin1" + | "pin2" + | "pin3" + | "pin4" + | "pin5" + | "pin6" + | "pin7" + | "pin8" + | "pin9" + | "pin10" + | "pin11" + | "pin12" + | "pin13" + | "pin14" + | "pin15" + | "pin16" + | "pin17" + | "pin18" + | "pin19" + | "pin20" + | "pin21" + | "pin22" + | "pin23" + | "pin24" + | "pin25" + | "pin26" + | "pin27" + | "pin28" + | "pin29" + | "pin30" + | "pin31" + | "pin32" + | "pin33" + | "pin34" + | "pin35" + | "pin36" + | "pin37" + | "pin38" + | "pin39" + | "pin40" + | "pin41" + | "pin42" + | "pin43" + | "pin44" + | "pin45" + | "pin46" + | "pin47" + | "pin48" + | "pin49" + | "pin50" + | "pin51" + | "pin52" + | "pin53" + | "pin54" + | "pin55" + | "pin56" + | "pin57" + | "pin58" + | "pin59" + | "pin60" + | "pin61" + | "pin62" + | "pin63" + | "pin64" + | "pin65" + | "pin66" + | "pin67" + | "pin68" + | "pin69" + | "pin70" + | "pin71" + | "pin72" + | "pin73" + | "pin74" + | "pin75" + | "pin76" + | "pin77" + | "pin78" + | "pin79" + | "pin80" + | "pin81" + | "pin82" + | "pin83" + | "pin84" + | "pin85" + | "pin86" + | "pin87" + | "pin88" + | "pin89" + | "pin90" + | "pin91" + | "pin92" + | "pin93" + | "pin94" + | "pin95" + | "pin96" + | "pin97" + | "pin98" + | "pin99" + | "pin100" + +export type CommonPinNames = + | "pos" + | "neg" + | "V5" + | "V3_3" + | "VCC" + | "VDD" + | "GND" + | `D${Nums40}` + | `GP${Nums40}` + | `GPIO${Nums40}` + | "DP" + | "DN" + | "VIN" + | "VOUT" + | "VREF" + | "VIN" + | "VOUT" + | "VREF" + | "VIN" + | "VOUT" + | "VREF" + | `A${Nums40}` + | `B${Nums40}` + | PinNumbers100 + +export type TransistorPinNames = "base" | "collector" | "emitter" diff --git a/lib/sel/sel.ts b/lib/sel/sel.ts new file mode 100644 index 00000000..bfa914a2 --- /dev/null +++ b/lib/sel/sel.ts @@ -0,0 +1,68 @@ +import type { + CommonPinNames, + Nums16, + Nums40, + PinNumbers100, + TransistorPinNames, +} from "./sel-utility-types" + +type NonPolarizedSel = Record< + `R${Nums40}` | `SW${Nums40}`, + { + pin1: string + pin2: string + pos: string + neg: string + } +> + +type PolarizedSel = Record< + | `C${Nums40}` + | `L${Nums40}` + | `LED${Nums40}` + | `D${Nums40}` + | `Y${Nums40}` + | `B${Nums16}`, + { + pin1: string + pin2: string + anode: string + cathode: string + pos: string + neg: string + } +> + +type TransistorSel = Record<`Q${Nums40}`, Record> + +type JumperSel = Record<`J${Nums40}`, Record> + +type ChipSel = Record<`U${Nums40}`, Record> + +type NetSel = Record<"net", Record<"VCC" | "GND" | "VDD", string>> + +export type Sel = NonPolarizedSel & + PolarizedSel & + TransistorSel & + JumperSel & + ChipSel & + NetSel + +export const sel: Sel = new Proxy( + {}, + { + get: (_, prop1: string) => { + return new Proxy( + {}, + { + get: (_, prop2: string) => { + if (prop1 === "net") { + return `net.${prop2}` + } + return `.${prop1} > .${prop2}` + }, + }, + ) + }, + }, +) as any diff --git a/tests/sel/sel1.test.ts b/tests/sel/sel1.test.ts new file mode 100644 index 00000000..8ce6703a --- /dev/null +++ b/tests/sel/sel1.test.ts @@ -0,0 +1,29 @@ +import { sel } from "lib/sel" +import { test, expect } from "bun:test" + +test("sel1 - sel.R1.pos = .R1 > .pos", () => { + expect(sel.R1.pos).toBe(".R1 > .pos") +}) + +test("sel1 - sel.U1.VCC = .U1 > .VCC", () => { + expect(sel.U1.VCC).toBe(".U1 > .VCC") +}) + +test("sel1 - invalid refdes", () => { + // @ts-expect-error + const someval = sel.ASDF1.pin1 +}) + +test("sel1 - invalid net", () => { + // @ts-expect-error + const someval = sel.net.ASDF1 +}) + +test("sel1 - invalid pin number", () => { + // @ts-expect-error + const someval = sel.R1.pin3 +}) + +test("sel1 - sel.net.VCC = net.VCC", () => { + expect(sel.net.VCC).toBe("net.VCC") +})