@tscircuit/parts-engine 0.0.3 → 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.
- package/index.ts +1 -1
- package/lib/jlc-parts-engine.ts +17 -16
- package/package.json +1 -1
- package/tests/jlc-parts-engine.test.ts +31 -2
package/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./lib/jlc-parts-engine"
|
|
1
|
+
export * from "./lib/jlc-parts-engine"
|
package/lib/jlc-parts-engine.ts
CHANGED
|
@@ -33,7 +33,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
return {
|
|
36
|
-
jlcpcb: resistors.map((r: any) => `C${r.lcsc}`).slice(0, 3),
|
|
36
|
+
jlcpcb: (resistors ?? []).map((r: any) => `C${r.lcsc}`).slice(0, 3),
|
|
37
37
|
}
|
|
38
38
|
} else if (
|
|
39
39
|
sourceComponent.type === "source_component" &&
|
|
@@ -48,7 +48,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
48
48
|
})
|
|
49
49
|
|
|
50
50
|
return {
|
|
51
|
-
jlcpcb: capacitors.map((c: any) => `C${c.lcsc}`).slice(0, 3),
|
|
51
|
+
jlcpcb: (capacitors ?? []).map((c: any) => `C${c.lcsc}`).slice(0, 3),
|
|
52
52
|
}
|
|
53
53
|
} else if (
|
|
54
54
|
sourceComponent.type === "source_component" &&
|
|
@@ -72,7 +72,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
72
72
|
},
|
|
73
73
|
)
|
|
74
74
|
return {
|
|
75
|
-
jlcpcb: headers.map((h: any) => `C${h.lcsc}`).slice(0, 3),
|
|
75
|
+
jlcpcb: (headers ?? []).map((h: any) => `C${h.lcsc}`).slice(0, 3),
|
|
76
76
|
}
|
|
77
77
|
} else if (
|
|
78
78
|
sourceComponent.type === "source_component" &&
|
|
@@ -83,7 +83,9 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
83
83
|
package: footprinterString,
|
|
84
84
|
})
|
|
85
85
|
return {
|
|
86
|
-
jlcpcb: potentiometers
|
|
86
|
+
jlcpcb: (potentiometers ?? [])
|
|
87
|
+
.map((p: any) => `C${p.lcsc}`)
|
|
88
|
+
.slice(0, 3),
|
|
87
89
|
}
|
|
88
90
|
} else if (
|
|
89
91
|
sourceComponent.type === "source_component" &&
|
|
@@ -93,7 +95,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
93
95
|
package: footprinterString,
|
|
94
96
|
})
|
|
95
97
|
return {
|
|
96
|
-
jlcpcb: diodes.map((d: any) => `C${d.lcsc}`).slice(0, 3),
|
|
98
|
+
jlcpcb: (diodes ?? []).map((d: any) => `C${d.lcsc}`).slice(0, 3),
|
|
97
99
|
}
|
|
98
100
|
} else if (
|
|
99
101
|
sourceComponent.type === "source_component" &&
|
|
@@ -103,7 +105,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
103
105
|
package: footprinterString,
|
|
104
106
|
})
|
|
105
107
|
return {
|
|
106
|
-
jlcpcb: chips.map((c: any) => `C${c.lcsc}`).slice(0, 3),
|
|
108
|
+
jlcpcb: (chips ?? []).map((c: any) => `C${c.lcsc}`).slice(0, 3),
|
|
107
109
|
}
|
|
108
110
|
} else if (
|
|
109
111
|
sourceComponent.type === "source_component" &&
|
|
@@ -114,7 +116,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
114
116
|
transistor_type: sourceComponent.transistor_type,
|
|
115
117
|
})
|
|
116
118
|
return {
|
|
117
|
-
jlcpcb: transistors.map((t: any) => `C${t.lcsc}`).slice(0, 3),
|
|
119
|
+
jlcpcb: (transistors ?? []).map((t: any) => `C${t.lcsc}`).slice(0, 3),
|
|
118
120
|
}
|
|
119
121
|
} else if (
|
|
120
122
|
sourceComponent.type === "source_component" &&
|
|
@@ -125,7 +127,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
125
127
|
package: footprinterString,
|
|
126
128
|
})
|
|
127
129
|
return {
|
|
128
|
-
jlcpcb: power_sources.map((p: any) => `C${p.lcsc}`).slice(0, 3),
|
|
130
|
+
jlcpcb: (power_sources ?? []).map((p: any) => `C${p.lcsc}`).slice(0, 3),
|
|
129
131
|
}
|
|
130
132
|
} else if (
|
|
131
133
|
sourceComponent.type === "source_component" &&
|
|
@@ -136,7 +138,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
136
138
|
package: footprinterString,
|
|
137
139
|
})
|
|
138
140
|
return {
|
|
139
|
-
jlcpcb: inductors.map((i: any) => `C${i.lcsc}`).slice(0, 3),
|
|
141
|
+
jlcpcb: (inductors ?? []).map((i: any) => `C${i.lcsc}`).slice(0, 3),
|
|
140
142
|
}
|
|
141
143
|
} else if (
|
|
142
144
|
sourceComponent.type === "source_component" &&
|
|
@@ -148,7 +150,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
148
150
|
package: footprinterString,
|
|
149
151
|
})
|
|
150
152
|
return {
|
|
151
|
-
jlcpcb: crystals.map((c: any) => `C${c.lcsc}`).slice(0, 3),
|
|
153
|
+
jlcpcb: (crystals ?? []).map((c: any) => `C${c.lcsc}`).slice(0, 3),
|
|
152
154
|
}
|
|
153
155
|
} else if (
|
|
154
156
|
sourceComponent.type === "source_component" &&
|
|
@@ -160,7 +162,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
160
162
|
channel_type: sourceComponent.channel_type,
|
|
161
163
|
})
|
|
162
164
|
return {
|
|
163
|
-
jlcpcb: mosfets.map((m: any) => `C${m.lcsc}`).slice(0, 3),
|
|
165
|
+
jlcpcb: (mosfets ?? []).map((m: any) => `C${m.lcsc}`).slice(0, 3),
|
|
164
166
|
}
|
|
165
167
|
} else if (
|
|
166
168
|
sourceComponent.type === "source_component" &&
|
|
@@ -171,7 +173,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
171
173
|
package: footprinterString,
|
|
172
174
|
})
|
|
173
175
|
return {
|
|
174
|
-
jlcpcb: resonators.map((r: any) => `C${r.lcsc}`).slice(0, 3),
|
|
176
|
+
jlcpcb: (resonators ?? []).map((r: any) => `C${r.lcsc}`).slice(0, 3),
|
|
175
177
|
}
|
|
176
178
|
} else if (
|
|
177
179
|
sourceComponent.type === "source_component" &&
|
|
@@ -182,10 +184,9 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
182
184
|
package: footprinterString,
|
|
183
185
|
})
|
|
184
186
|
return {
|
|
185
|
-
jlcpcb: switches.map((s: any) => `C${s.lcsc}`).slice(0, 3),
|
|
187
|
+
jlcpcb: (switches ?? []).map((s: any) => `C${s.lcsc}`).slice(0, 3),
|
|
186
188
|
}
|
|
187
|
-
}
|
|
188
|
-
else if (
|
|
189
|
+
} else if (
|
|
189
190
|
sourceComponent.type === "source_component" &&
|
|
190
191
|
sourceComponent.ftype === "simple_led"
|
|
191
192
|
) {
|
|
@@ -193,7 +194,7 @@ export const jlcPartsEngine: PartsEngine = {
|
|
|
193
194
|
package: footprinterString,
|
|
194
195
|
})
|
|
195
196
|
return {
|
|
196
|
-
jlcpcb: leds.map((l: any) => `C${l.lcsc}`).slice(0, 3),
|
|
197
|
+
jlcpcb: (leds ?? []).map((l: any) => `C${l.lcsc}`).slice(0, 3),
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
200
|
return {}
|
package/package.json
CHANGED
|
@@ -22,7 +22,11 @@ describe("jlcPartsEngine", () => {
|
|
|
22
22
|
if (url.includes("/potentiometers/")) {
|
|
23
23
|
return {
|
|
24
24
|
json: async () => ({
|
|
25
|
-
potentiometers: [
|
|
25
|
+
potentiometers: [
|
|
26
|
+
{ lcsc: "1234" },
|
|
27
|
+
{ lcsc: "5678" },
|
|
28
|
+
{ lcsc: "9012" },
|
|
29
|
+
],
|
|
26
30
|
}),
|
|
27
31
|
} as Response
|
|
28
32
|
}
|
|
@@ -57,7 +61,11 @@ describe("jlcPartsEngine", () => {
|
|
|
57
61
|
if (url.includes("/power_sources/")) {
|
|
58
62
|
return {
|
|
59
63
|
json: async () => ({
|
|
60
|
-
power_sources: [
|
|
64
|
+
power_sources: [
|
|
65
|
+
{ lcsc: "7890" },
|
|
66
|
+
{ lcsc: "1234" },
|
|
67
|
+
{ lcsc: "5678" },
|
|
68
|
+
],
|
|
61
69
|
}),
|
|
62
70
|
} as Response
|
|
63
71
|
}
|
|
@@ -365,4 +373,25 @@ describe("jlcPartsEngine", () => {
|
|
|
365
373
|
|
|
366
374
|
expect(result).toEqual({})
|
|
367
375
|
})
|
|
376
|
+
|
|
377
|
+
test("should handle missing API data", async () => {
|
|
378
|
+
globalThis.fetch = (async () => ({
|
|
379
|
+
json: async () => ({}),
|
|
380
|
+
})) as unknown as typeof fetch
|
|
381
|
+
|
|
382
|
+
const resistor: AnySourceComponent = {
|
|
383
|
+
type: "source_component",
|
|
384
|
+
ftype: "simple_resistor",
|
|
385
|
+
resistance: 1000,
|
|
386
|
+
source_component_id: "source_component_0",
|
|
387
|
+
name: "R2",
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const result = await jlcPartsEngine.findPart({
|
|
391
|
+
sourceComponent: resistor,
|
|
392
|
+
footprinterString: "0603",
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
expect(result).toEqual({ jlcpcb: [] })
|
|
396
|
+
})
|
|
368
397
|
})
|