circuit-json-to-spice 0.0.1

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.
Files changed (33) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/biome.json +49 -0
  4. package/bun.lockb +0 -0
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.js +3 -0
  7. package/docs/CIRCUIT_JSON_PCB_OVERVIEW.md +340 -0
  8. package/docs/CIRCUIT_JSON_SOURCE_COMPONENT_OVERVIEW.md +151 -0
  9. package/docs/SPICE_SUMMARY.txt +248 -0
  10. package/lib/index.ts +1 -0
  11. package/lib/spice-classes/SpiceComponent.ts +0 -0
  12. package/lib/spice-classes/SpiceModel.ts +0 -0
  13. package/lib/spice-classes/SpiceNetlist.ts +9 -0
  14. package/lib/spice-classes/SpiceNode.ts +1 -0
  15. package/lib/spice-classes/SpiceSubcircuit.ts +0 -0
  16. package/lib/spice-commands/BJTCommand.ts +34 -0
  17. package/lib/spice-commands/BaseSpiceCommand.ts +6 -0
  18. package/lib/spice-commands/CapacitorCommand.ts +41 -0
  19. package/lib/spice-commands/CurrentSourceCommand.ts +35 -0
  20. package/lib/spice-commands/DiodeCommand.ts +27 -0
  21. package/lib/spice-commands/InductorCommand.ts +33 -0
  22. package/lib/spice-commands/InductorCouplingCommand.ts +21 -0
  23. package/lib/spice-commands/JFETCommand.ts +28 -0
  24. package/lib/spice-commands/MOSFETCommand.ts +67 -0
  25. package/lib/spice-commands/ResistorCommand.ts +28 -0
  26. package/lib/spice-commands/SubcircuitCallCommand.ts +21 -0
  27. package/lib/spice-commands/TransmissionLineCommand.ts +46 -0
  28. package/lib/spice-commands/VoltageControlledSwitchCommand.ts +31 -0
  29. package/lib/spice-commands/VoltageSourceCommand.ts +35 -0
  30. package/lib/spice-commands/index.ts +14 -0
  31. package/lib/spice-utils/convertSpiceNetlistToString.ts +3 -0
  32. package/package.json +18 -0
  33. package/tsconfig.json +27 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 tscircuit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # circuit-json-to-spice
2
+
3
+ Convert Circuit JSON into ngspice compatible SPICE netlists
4
+
5
+ ## References
6
+
7
+ - Inspired by [https://eecircuit.com/](https://eecircuit.com/)
package/biome.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
3
+ "organizeImports": {
4
+ "enabled": true
5
+ },
6
+ "formatter": {
7
+ "enabled": true,
8
+ "indentStyle": "space"
9
+ },
10
+ "files": {
11
+ "ignore": ["cosmos-export", "dist", "package.json"]
12
+ },
13
+ "javascript": {
14
+ "formatter": {
15
+ "jsxQuoteStyle": "double",
16
+ "quoteProperties": "asNeeded",
17
+ "trailingCommas": "all",
18
+ "semicolons": "asNeeded",
19
+ "arrowParentheses": "always",
20
+ "bracketSpacing": true,
21
+ "bracketSameLine": false
22
+ }
23
+ },
24
+ "linter": {
25
+ "enabled": true,
26
+ "rules": {
27
+ "recommended": true,
28
+ "suspicious": {
29
+ "noExplicitAny": "off"
30
+ },
31
+ "complexity": {
32
+ "noForEach": "info"
33
+ },
34
+ "style": {
35
+ "noUselessElse": "off",
36
+ "noNonNullAssertion": "off",
37
+ "useNumberNamespace": "off",
38
+ "useFilenamingConvention": {
39
+ "level": "error",
40
+ "options": {
41
+ "strictCase": true,
42
+ "requireAscii": true,
43
+ "filenameCases": ["kebab-case", "export"]
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
package/bun.lockb ADDED
Binary file
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ // lib/index.ts
2
+ console.log("Hello via Bun!");
3
+ //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vbGliL2luZGV4LnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyJjb25zb2xlLmxvZyhcIkhlbGxvIHZpYSBCdW4hXCIpOyJdLAogICJtYXBwaW5ncyI6ICI7QUFBQSxRQUFRLElBQUksZ0JBQWdCOyIsCiAgIm5hbWVzIjogW10KfQo=
@@ -0,0 +1,340 @@
1
+ # Circuit JSON Specification: PCB Component Overview
2
+
3
+ > Created at 2024-10-23T22:17:25.274Z
4
+ > Latest Version: https://github.com/tscircuit/circuit-json/blob/main/docs/PCB_COMPONENT_OVERVIEW.md
5
+
6
+ Any type below can be imported from `circuit-json`. Every type has a corresponding
7
+ snake_case version which is a zod type that can be used to parse unknown json,
8
+ for example `PcbComponent` has a `pcb_component.parse` function that you
9
+ can also import.
10
+
11
+ ```ts
12
+ export interface PcbFabricationNotePath {
13
+ type: "pcb_fabrication_note_path"
14
+ pcb_fabrication_note_path_id: string
15
+ pcb_component_id: string
16
+ layer: LayerRef
17
+ route: Point[]
18
+ stroke_width: Length
19
+ color?: string
20
+ }
21
+
22
+ export interface PcbComponent {
23
+ type: "pcb_component"
24
+ pcb_component_id: string
25
+ source_component_id: string
26
+ center: Point
27
+ layer: LayerRef
28
+ rotation: Rotation
29
+ width: Length
30
+ height: Length
31
+ }
32
+
33
+ export interface PcbPortNotMatchedError {
34
+ type: "pcb_port_not_matched_error"
35
+ pcb_error_id: string
36
+ message: string
37
+ pcb_component_ids: string[]
38
+ }
39
+
40
+ export interface PcbSolderPasteCircle {
41
+ type: "pcb_solder_paste"
42
+ shape: "circle"
43
+ pcb_solder_paste_id: string
44
+ x: Distance
45
+ y: Distance
46
+ radius: number
47
+ layer: LayerRef
48
+ pcb_component_id?: string
49
+ pcb_smtpad_id?: string
50
+ }
51
+
52
+ export interface PcbSolderPasteRect {
53
+ type: "pcb_solder_paste"
54
+ shape: "rect"
55
+ pcb_solder_paste_id: string
56
+ x: Distance
57
+ y: Distance
58
+ width: number
59
+ height: number
60
+ layer: LayerRef
61
+ pcb_component_id?: string
62
+ pcb_smtpad_id?: string
63
+ }
64
+
65
+ export type PcbSolderPaste = PcbSolderPasteCircle | PcbSolderPasteRect
66
+
67
+ export interface PcbSilkscreenText {
68
+ type: "pcb_silkscreen_text"
69
+ pcb_silkscreen_text_id: string
70
+ font: "tscircuit2024"
71
+ font_size: Length
72
+ pcb_component_id: string
73
+ text: string
74
+ layer: LayerRef
75
+ is_mirrored?: boolean
76
+ anchor_position: Point
77
+ anchor_alignment:
78
+ | "center"
79
+ | "top_left"
80
+ | "top_right"
81
+ | "bottom_left"
82
+ | "bottom_right"
83
+ }
84
+
85
+ export interface PcbTraceError {
86
+ type: "pcb_trace_error"
87
+ pcb_trace_error_id: string
88
+ error_type: "pcb_trace_error"
89
+ message: string
90
+ center?: Point
91
+ pcb_trace_id: string
92
+ source_trace_id: string
93
+ pcb_component_ids: string[]
94
+ pcb_port_ids: string[]
95
+ }
96
+
97
+ export interface PcbSilkscreenPill {
98
+ type: "pcb_silkscreen_pill"
99
+ pcb_silkscreen_pill_id: string
100
+ pcb_component_id: string
101
+ center: Point
102
+ width: Length
103
+ height: Length
104
+ layer: LayerRef
105
+ }
106
+
107
+ export interface PcbPlatedHoleCircle {
108
+ type: "pcb_plated_hole"
109
+ shape: "circle"
110
+ outer_diameter: number
111
+ hole_diameter: number
112
+ x: Distance
113
+ y: Distance
114
+ layers: LayerRef[]
115
+ port_hints?: string[]
116
+ pcb_component_id?: string
117
+ pcb_port_id?: string
118
+ pcb_plated_hole_id: string
119
+ }
120
+
121
+ export interface PcbPlatedHoleOval {
122
+ type: "pcb_plated_hole"
123
+ shape: "oval" | "pill"
124
+ outer_width: number
125
+ outer_height: number
126
+ hole_width: number
127
+ hole_height: number
128
+ x: Distance
129
+ y: Distance
130
+ layers: LayerRef[]
131
+ port_hints?: string[]
132
+ pcb_component_id?: string
133
+ pcb_port_id?: string
134
+ pcb_plated_hole_id: string
135
+ }
136
+
137
+ export type PcbPlatedHole = PcbPlatedHoleCircle | PcbPlatedHoleOval
138
+
139
+ export interface PcbFabricationNoteText {
140
+ type: "pcb_fabrication_note_text"
141
+ pcb_fabrication_note_text_id: string
142
+ font: "tscircuit2024"
143
+ font_size: Length
144
+ pcb_component_id: string
145
+ text: string
146
+ layer: VisibleLayer
147
+ anchor_position: Point
148
+ anchor_alignment:
149
+ | "center"
150
+ | "top_left"
151
+ | "top_right"
152
+ | "bottom_left"
153
+ | "bottom_right"
154
+ color?: string
155
+ }
156
+
157
+ export interface PcbSilkscreenCircle {
158
+ type: "pcb_silkscreen_circle"
159
+ pcb_silkscreen_circle_id: string
160
+ pcb_component_id: string
161
+ center: Point
162
+ radius: Length
163
+ layer: VisibleLayer
164
+ }
165
+
166
+ export interface PcbSilkscreenPath {
167
+ type: "pcb_silkscreen_path"
168
+ pcb_silkscreen_path_id: string
169
+ pcb_component_id: string
170
+ layer: VisibleLayerRef
171
+ route: Point[]
172
+ stroke_width: Length
173
+ }
174
+
175
+ export interface PcbText {
176
+ type: "pcb_text"
177
+ pcb_text_id: string
178
+ text: string
179
+ center: Point
180
+ layer: LayerRef
181
+ width: Length
182
+ height: Length
183
+ lines: number
184
+ align: "bottom-left"
185
+ }
186
+
187
+ export interface PCBKeepout {
188
+ type: "pcb_keepout"
189
+ shape: "rect" | "circle"
190
+ center: Point
191
+ width?: Distance
192
+ height?: Distance
193
+ radius?: Distance
194
+ pcb_keepout_id: string
195
+ layers: string[]
196
+ description?: string
197
+ }
198
+
199
+ export interface PcbVia {
200
+ type: "pcb_via"
201
+ pcb_via_id: string
202
+ x: Distance
203
+ y: Distance
204
+ outer_diameter: Distance
205
+ hole_diameter: Distance
206
+ layers: LayerRef[]
207
+ pcb_trace_id?: string
208
+ }
209
+
210
+ export interface PcbSilkscreenOval {
211
+ type: "pcb_silkscreen_oval"
212
+ pcb_silkscreen_oval_id: string
213
+ pcb_component_id: string
214
+ center: Point
215
+ radius_x: Distance
216
+ radius_y: Distance
217
+ layer: VisibleLayer
218
+ }
219
+
220
+ export interface PcbPlacementError {
221
+ type: "pcb_placement_error"
222
+ pcb_placement_error_id: string
223
+ message: string
224
+ }
225
+
226
+ export interface PcbPort {
227
+ type: "pcb_port"
228
+ pcb_port_id: string
229
+ source_port_id: string
230
+ pcb_component_id: string
231
+ x: Distance
232
+ y: Distance
233
+ layers: LayerRef[]
234
+ }
235
+
236
+ export interface PcbSmtPadCircle {
237
+ type: "pcb_smtpad"
238
+ shape: "circle"
239
+ pcb_smtpad_id: string
240
+ x: Distance
241
+ y: Distance
242
+ radius: number
243
+ layer: LayerRef
244
+ port_hints?: string[]
245
+ pcb_component_id?: string
246
+ pcb_port_id?: string
247
+ }
248
+
249
+ export interface PcbSmtPadRect {
250
+ type: "pcb_smtpad"
251
+ shape: "rect"
252
+ pcb_smtpad_id: string
253
+ x: Distance
254
+ y: Distance
255
+ width: number
256
+ height: number
257
+ layer: LayerRef
258
+ port_hints?: string[]
259
+ pcb_component_id?: string
260
+ pcb_port_id?: string
261
+ }
262
+
263
+ export type PcbSmtPad = PcbSmtPadCircle | PcbSmtPadRect
264
+
265
+ export interface PcbSilkscreenLine {
266
+ type: "pcb_silkscreen_line"
267
+ pcb_silkscreen_line_id: string
268
+ pcb_component_id: string
269
+ stroke_width: Distance
270
+ x1: Distance
271
+ y1: Distance
272
+ x2: Distance
273
+ y2: Distance
274
+ layer: VisibleLayer
275
+ }
276
+
277
+ export interface PcbHoleCircleOrSquare {
278
+ type: "pcb_hole"
279
+ pcb_hole_id: string
280
+ hole_shape: "circle" | "square"
281
+ hole_diameter: number
282
+ x: Distance
283
+ y: Distance
284
+ }
285
+
286
+ export interface PcbHoleOval {
287
+ type: "pcb_hole"
288
+ pcb_hole_id: string
289
+ hole_shape: "oval"
290
+ hole_width: number
291
+ hole_height: number
292
+ x: Distance
293
+ y: Distance
294
+ }
295
+
296
+ export type PcbHole = PcbHoleCircleOrSquare | PcbHoleOval
297
+
298
+ export interface PcbTraceRoutePointWire {
299
+ route_type: "wire"
300
+ x: Distance
301
+ y: Distance
302
+ width: Distance
303
+ start_pcb_port_id?: string
304
+ end_pcb_port_id?: string
305
+ layer: LayerRef
306
+ }
307
+
308
+ export interface PcbTraceRoutePointVia {
309
+ route_type: "via"
310
+ x: Distance
311
+ y: Distance
312
+ from_layer: string
313
+ to_layer: string
314
+ }
315
+
316
+ export type PcbTraceRoutePoint = PcbTraceRoutePointWire | PcbTraceRoutePointVia
317
+
318
+ export interface PcbTrace {
319
+ type: "pcb_trace"
320
+ source_trace_id?: string
321
+ pcb_component_id?: string
322
+ pcb_trace_id: string
323
+ route_order_index?: number
324
+ route_thickness_mode?: "constant" | "interpolated"
325
+ should_round_corners?: boolean
326
+ route: Array<PcbTraceRoutePoint>
327
+ }
328
+
329
+ export interface PcbBoard {
330
+ type: "pcb_board"
331
+ pcb_board_id: string
332
+ width: Length
333
+ height: Length
334
+ thickness: Length
335
+ num_layers: number
336
+ center: Point
337
+ outline?: Point[]
338
+ }
339
+
340
+ ```
@@ -0,0 +1,151 @@
1
+ # Circuit JSON Specification: Source Component Overview
2
+
3
+ > Created at 2024-11-12T19:07:05.930Z
4
+ > Latest Version: https://github.com/tscircuit/circuit-json/blob/main/docs/SOURCE_COMPONENT_OVERVIEW.md
5
+
6
+ Any type below can be imported from `circuit-json`. Every type has a corresponding
7
+ snake_case version which is a zod type that can be used to parse unknown json,
8
+ for example `SourceComponent` has a `source_component.parse` function that you
9
+ can also import.
10
+
11
+ ```ts
12
+ interface SourceSimpleChip {
13
+ type: "source_component"
14
+ ftype: "simple_chip"
15
+ source_component_id: string
16
+ name: string
17
+ manufacturer_part_number?: string
18
+ supplier_part_numbers?: Partial<Record<string, string[]>>
19
+ display_value?: string
20
+ }
21
+
22
+ interface SourceSimpleInductor {
23
+ type: "source_component"
24
+ ftype: "simple_inductor"
25
+ source_component_id: string
26
+ name: string
27
+ manufacturer_part_number?: string
28
+ supplier_part_numbers?: Partial<Record<string, string[]>>
29
+ display_value?: string
30
+ inductance: number
31
+ }
32
+
33
+ interface SourceLed {
34
+ type: "source_component"
35
+ ftype: "led"
36
+ source_component_id: string
37
+ name: string
38
+ manufacturer_part_number?: string
39
+ supplier_part_numbers?: Partial<Record<string, string[]>>
40
+ display_value?: string
41
+ }
42
+
43
+ interface SourceTrace {
44
+ type: "source_trace"
45
+ source_trace_id: string
46
+ connected_source_port_ids: string[]
47
+ connected_source_net_ids: string[]
48
+ subcircuit_connectivity_map_key?: string
49
+ }
50
+
51
+ interface SourceSimpleGround {
52
+ type: "source_component"
53
+ ftype: "simple_ground"
54
+ source_component_id: string
55
+ name: string
56
+ manufacturer_part_number?: string
57
+ supplier_part_numbers?: Partial<Record<string, string[]>>
58
+ display_value?: string
59
+ }
60
+
61
+ interface SourceSimpleResistor {
62
+ type: "source_component"
63
+ ftype: "simple_resistor"
64
+ source_component_id: string
65
+ name: string
66
+ manufacturer_part_number?: string
67
+ supplier_part_numbers?: Partial<Record<string, string[]>>
68
+ display_value?: string
69
+ resistance: number
70
+ }
71
+
72
+ interface SourceSimpleBattery {
73
+ type: "source_component"
74
+ ftype: "simple_battery"
75
+ source_component_id: string
76
+ name: string
77
+ manufacturer_part_number?: string
78
+ supplier_part_numbers?: Partial<Record<string, string[]>>
79
+ display_value?: string
80
+ capacity: number
81
+ }
82
+
83
+ interface SourceNet {
84
+ type: "source_net"
85
+ source_net_id: string
86
+ name: string
87
+ member_source_group_ids: string[]
88
+ is_power?: boolean
89
+ is_ground?: boolean
90
+ is_digital_signal?: boolean
91
+ is_analog_signal?: boolean
92
+ trace_width?: number
93
+ }
94
+
95
+ interface SourceSimpleDiode {
96
+ type: "source_component"
97
+ ftype: "simple_diode"
98
+ source_component_id: string
99
+ name: string
100
+ manufacturer_part_number?: string
101
+ supplier_part_numbers?: Partial<Record<string, string[]>>
102
+ display_value?: string
103
+ }
104
+
105
+ interface SourceGroup {
106
+ type: "source_group"
107
+ source_group_id: string
108
+ name?: string
109
+ }
110
+
111
+ interface SourcePort {
112
+ type: "source_port"
113
+ pin_number?: number
114
+ port_hints?: string[]
115
+ name: string
116
+ source_port_id: string
117
+ source_component_id: string
118
+ }
119
+
120
+ interface SourceSimplePowerSource {
121
+ type: "source_component"
122
+ ftype: "simple_power_source"
123
+ source_component_id: string
124
+ name: string
125
+ manufacturer_part_number?: string
126
+ supplier_part_numbers?: Partial<Record<string, string[]>>
127
+ display_value?: string
128
+ voltage: number
129
+ }
130
+
131
+ interface SourceSimpleCapacitor {
132
+ type: "source_component"
133
+ ftype: "simple_capacitor"
134
+ source_component_id: string
135
+ name: string
136
+ manufacturer_part_number?: string
137
+ supplier_part_numbers?: Partial<Record<string, string[]>>
138
+ display_value?: string
139
+ capacitance: number
140
+ }
141
+
142
+ interface SourceComponentBase {
143
+ type: "source_component"
144
+ ftype?: string
145
+ source_component_id: string
146
+ name: string
147
+ manufacturer_part_number?: string
148
+ supplier_part_numbers?: Partial<Record<string, string[]>>
149
+ display_value?: string
150
+ }
151
+ ```