@tscircuit/footprinter 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ import { AnySoupElement } from '@tscircuit/soup';
2
+
3
+ type FootprinterParamsBuilder<K extends string> = {
4
+ [P in K | "params" | "soup"]: P extends "params" | "soup" ? Footprinter[P] : (v?: number | string) => FootprinterParamsBuilder<K>;
5
+ };
6
+ type CommonPassiveOptionKey = "metric" | "imperial" | "tht" | "p" | "pw" | "ph" | "w" | "h";
7
+ type Footprinter = {
8
+ dip: (num_pins: number) => FootprinterParamsBuilder<"w" | "p" | "id" | "od">;
9
+ cap: () => FootprinterParamsBuilder<CommonPassiveOptionKey>;
10
+ res: () => FootprinterParamsBuilder<CommonPassiveOptionKey>;
11
+ diode: () => FootprinterParamsBuilder<CommonPassiveOptionKey>;
12
+ led: () => FootprinterParamsBuilder<CommonPassiveOptionKey>;
13
+ lr: (num_pins: number) => FootprinterParamsBuilder<"w" | "l" | "pl" | "pr">;
14
+ quad: (num_pins: number) => FootprinterParamsBuilder<"w" | "l" | "square" | "pl" | "pr" | "pb" | "pt" | "p" | "pw" | "ph">;
15
+ bga: (num_pins: number) => FootprinterParamsBuilder<"grid" | "p" | "w" | "h" | "ball" | "pad" | "missing">;
16
+ params: () => any;
17
+ soup: () => AnySoupElement[];
18
+ };
19
+ declare const string: (def: string) => Footprinter;
20
+ declare const footprinter: {
21
+ (): Footprinter & {
22
+ string: typeof string;
23
+ };
24
+ string: (def: string) => Footprinter;
25
+ };
26
+ declare const fp: {
27
+ (): Footprinter & {
28
+ string: typeof string;
29
+ };
30
+ string: (def: string) => Footprinter;
31
+ };
32
+
33
+ export { type Footprinter, type FootprinterParamsBuilder, footprinter, fp, string };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@tscircuit/footprinter",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "description": "",
6
- "main": "index.js",
6
+ "main": "dist/index.cjs",
7
7
  "scripts": {
8
8
  "test": "ava",
9
9
  "build": "tsup ./src/index.ts --dts --sourcemap"
package/src/fn/dip.ts CHANGED
@@ -1,5 +1,16 @@
1
1
  import type { AnySoupElement } from "@tscircuit/soup"
2
2
  import { platedhole } from "../helpers/platedhole"
3
+ import { z } from "zod"
4
+ import { length } from "@tscircuit/soup"
5
+
6
+ const dip_def = z.object({
7
+ dip: z.literal(true),
8
+ num_pins: z.number(),
9
+ w: length,
10
+ p: length.optional(),
11
+ id: length.optional(),
12
+ od: length.optional(),
13
+ })
3
14
 
4
15
  export const getCcwDipCoords = (
5
16
  pinCount: number,
@@ -40,6 +51,7 @@ export const dip = (params: {
40
51
  id?: string | number
41
52
  od?: string | number
42
53
  }): AnySoupElement[] => {
54
+ params = dip_def.parse(params)
43
55
  const platedHoles: AnySoupElement[] = []
44
56
  for (let i = 0; i < params.num_pins; i++) {
45
57
  const { x, y } = getCcwDipCoords(
@@ -47,7 +47,7 @@ export const string = (def: string): Footprinter => {
47
47
  let fp = footprinter()
48
48
 
49
49
  const def_parts = def.split("_").map((s) => {
50
- const m = s.match(/([a-z]+)([\(\d\+].*)?/)
50
+ const m = s.match(/([a-z]+)([\(\d\.\+].*)?/)
51
51
  const [_, fn, v] = m ?? []
52
52
  return { fn: m?.[1]!, v: m?.[2]! }
53
53
  })
package/tests/dip.test.ts CHANGED
@@ -26,8 +26,8 @@ test("dip footprint", (t) => {
26
26
  )
27
27
  })
28
28
 
29
- test("dip4_w3", (t) => {
30
- const soup = fp.string("dip4_w3").soup()
29
+ test("dip4_w3.00mm", (t) => {
30
+ const soup = fp.string("dip4_w3.00mm").soup()
31
31
  const ps = toPinPositionString(soup)
32
32
 
33
33
  t.is(