circuit-json 0.0.433 → 0.0.434

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/dist/index.mjs CHANGED
@@ -1,221 +1,19 @@
1
- // src/utils/convert-si-unit-to-number.ts
2
- var unitMappings = {
3
- Hz: {
4
- baseUnit: "Hz",
5
- variants: {
6
- MHz: 1e6,
7
- kHz: 1e3,
8
- Hz: 1
9
- }
10
- },
11
- g: {
12
- baseUnit: "g",
13
- variants: {
14
- kg: 1e3,
15
- g: 1
16
- }
17
- },
18
- \u03A9: {
19
- baseUnit: "\u03A9",
20
- variants: {
21
- m\u03A9: 1e-3,
22
- \u03A9: 1,
23
- k\u03A9: 1e3,
24
- K\u03A9: 1e3,
25
- kohm: 1e3,
26
- M\u03A9: 1e6,
27
- G\u03A9: 1e9,
28
- T\u03A9: 1e12
29
- }
30
- },
31
- V: {
32
- baseUnit: "V",
33
- variants: {
34
- mV: 1e-3,
35
- V: 1,
36
- kV: 1e3,
37
- KV: 1e3,
38
- MV: 1e6,
39
- GV: 1e9,
40
- TV: 1e12
41
- }
42
- },
43
- A: {
44
- baseUnit: "A",
45
- variants: {
46
- \u00B5A: 1e-6,
47
- mA: 1e-3,
48
- ma: 1e-3,
49
- A: 1,
50
- kA: 1e3,
51
- MA: 1e6
52
- }
53
- },
54
- F: {
55
- baseUnit: "F",
56
- variants: {
57
- pF: 1e-12,
58
- nF: 1e-9,
59
- \u00B5F: 1e-6,
60
- uF: 1e-6,
61
- mF: 1e-3,
62
- F: 1
63
- }
64
- },
65
- ml: {
66
- baseUnit: "ml",
67
- variants: {
68
- ml: 1,
69
- mL: 1,
70
- l: 1e3,
71
- L: 1e3
72
- }
73
- },
74
- deg: {
75
- baseUnit: "deg",
76
- variants: {
77
- rad: 180 / Math.PI
78
- }
79
- },
80
- ms: {
81
- baseUnit: "ms",
82
- variants: {
83
- fs: 1e-12,
84
- ps: 1e-9,
85
- ns: 1e-6,
86
- us: 1e-3,
87
- \u00B5s: 1e-3,
88
- ms: 1,
89
- s: 1e3
90
- }
91
- },
92
- mm: {
93
- baseUnit: "mm",
94
- variants: {
95
- nm: 1e-6,
96
- \u00B5m: 1e-3,
97
- um: 1e-3,
98
- mm: 1,
99
- cm: 10,
100
- dm: 100,
101
- m: 1e3,
102
- km: 1e6,
103
- in: 25.4,
104
- ft: 304.8,
105
- IN: 25.4,
106
- FT: 304.8,
107
- yd: 914.4,
108
- mi: 1609344,
109
- mil: 0.0254
110
- }
111
- }
112
- };
113
- var unitMappingAndVariantSuffixes = /* @__PURE__ */ new Set();
114
- for (const [baseUnit, info] of Object.entries(unitMappings)) {
115
- unitMappingAndVariantSuffixes.add(baseUnit);
116
- for (const variant of Object.keys(info.variants)) {
117
- unitMappingAndVariantSuffixes.add(variant);
118
- }
119
- }
120
- function getBaseTscircuitUnit(unit) {
121
- for (const [baseUnit, info] of Object.entries(unitMappings)) {
122
- if (unit in info.variants) {
123
- return {
124
- baseUnit: info.baseUnit,
125
- conversionFactor: info.variants[unit]
126
- };
127
- }
128
- }
129
- return {
130
- baseUnit: unit,
131
- conversionFactor: 1
132
- };
133
- }
134
- var si_prefix_multiplier = {
135
- tera: 1e12,
136
- T: 1e12,
137
- giga: 1e9,
138
- G: 1e9,
139
- mega: 1e6,
140
- M: 1e6,
141
- kilo: 1e3,
142
- k: 1e3,
143
- deci: 0.1,
144
- d: 0.1,
145
- centi: 0.01,
146
- c: 0.01,
147
- milli: 1e-3,
148
- m: 1e-3,
149
- micro: 1e-6,
150
- u: 1e-6,
151
- \u00B5: 1e-6,
152
- nano: 1e-9,
153
- n: 1e-9,
154
- pico: 1e-12,
155
- p: 1e-12
156
- };
157
- function parseAndConvertSiUnit(v) {
158
- if (v === void 0 || v === null)
159
- return { parsedUnit: null, unitOfValue: null, value: null };
160
- if (typeof v === "string" && v.match(/^-?[\d\.]+$/))
161
- return {
162
- value: Number.parseFloat(v),
163
- parsedUnit: null,
164
- unitOfValue: null
165
- };
166
- if (typeof v === "number")
167
- return { value: v, parsedUnit: null, unitOfValue: null };
168
- if (typeof v === "object" && "x" in v && "y" in v) {
169
- const { parsedUnit, unitOfValue } = parseAndConvertSiUnit(v.x);
170
- const xResult = parseAndConvertSiUnit(v.x);
171
- const yResult = parseAndConvertSiUnit(v.y);
172
- if (xResult.value === null || yResult.value === null) {
173
- return { parsedUnit: null, unitOfValue: null, value: null };
174
- }
175
- return {
176
- parsedUnit,
177
- unitOfValue,
178
- value: {
179
- x: xResult.value,
180
- y: yResult.value
181
- }
182
- };
183
- }
184
- const reversed_input_string = v.toString().split("").reverse().join("");
185
- const unit_reversed = reversed_input_string.match(/[^\d\s]+/)?.[0];
186
- if (!unit_reversed) {
187
- throw new Error(`Could not determine unit: "${v}"`);
188
- }
189
- const unit = unit_reversed.split("").reverse().join("");
190
- const numberPart = v.slice(0, -unit.length);
191
- if (unit in si_prefix_multiplier && !unitMappingAndVariantSuffixes.has(unit)) {
192
- const siMultiplier = si_prefix_multiplier[unit];
193
- return {
194
- parsedUnit: null,
195
- unitOfValue: null,
196
- value: Number.parseFloat(numberPart) * siMultiplier
197
- };
198
- }
199
- const { baseUnit, conversionFactor } = getBaseTscircuitUnit(unit);
200
- return {
201
- parsedUnit: unit,
202
- unitOfValue: baseUnit,
203
- value: conversionFactor * Number.parseFloat(numberPart)
204
- };
205
- }
206
-
207
1
  // src/units/index.ts
2
+ import { parseAndConvertSiUnit } from "format-si-unit";
208
3
  import { z } from "zod";
209
- var resistance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
210
- var capacitance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value).transform((value) => {
4
+ import {
5
+ parseAndConvertSiUnit as parseAndConvertSiUnit2
6
+ } from "format-si-unit";
7
+ var resistance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v, "\u03A9").value);
8
+ var capacitance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v, "F").value).transform((value) => {
211
9
  return Number.parseFloat(value.toPrecision(12));
212
10
  });
213
- var inductance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
214
- var voltage = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
11
+ var inductance = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v, "H").value);
12
+ var voltage = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v, "V").value);
215
13
  var length = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
216
- var frequency = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
14
+ var frequency = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v, "Hz").value);
217
15
  var distance = length;
218
- var current = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
16
+ var current = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v, "A").value);
219
17
  var duration_ms = z.string().or(z.number()).transform((v) => parseAndConvertSiUnit(v).value);
220
18
  var time = duration_ms;
221
19
  var ms = duration_ms;
@@ -959,7 +757,12 @@ var source_simple_voltage_source = source_component_base.extend({
959
757
  peak_to_peak_voltage: voltage.optional(),
960
758
  wave_shape: z51.enum(["sinewave", "square", "triangle", "sawtooth"]).optional(),
961
759
  phase: rotation.optional(),
962
- duty_cycle: z51.number().optional().describe("Duty cycle as a fraction (0 to 1)")
760
+ duty_cycle: z51.number().optional().describe("Duty cycle as a fraction (0 to 1)"),
761
+ pulse_delay: ms.optional(),
762
+ rise_time: ms.optional(),
763
+ fall_time: ms.optional(),
764
+ pulse_width: ms.optional(),
765
+ period: ms.optional()
963
766
  });
964
767
  expectTypesMatch(
965
768
  true
@@ -3650,7 +3453,12 @@ var simulation_ac_voltage_source = z162.object({
3650
3453
  peak_to_peak_voltage: voltage.optional(),
3651
3454
  wave_shape: wave_shape.optional(),
3652
3455
  phase: rotation.optional(),
3653
- duty_cycle: percentage.optional()
3456
+ duty_cycle: percentage.optional(),
3457
+ pulse_delay: ms.optional(),
3458
+ rise_time: ms.optional(),
3459
+ fall_time: ms.optional(),
3460
+ pulse_width: ms.optional(),
3461
+ period: ms.optional()
3654
3462
  }).describe("Defines an AC voltage source for simulation");
3655
3463
  var simulation_voltage_source = z162.union([simulation_dc_voltage_source, simulation_ac_voltage_source]).describe("Defines a voltage source for simulation");
3656
3464
  expectTypesMatch(true);
@@ -3712,6 +3520,12 @@ var experiment_type = z164.union([
3712
3520
  z164.literal("spice_transient_analysis"),
3713
3521
  z164.literal("spice_ac_analysis")
3714
3522
  ]);
3523
+ var spice_simulation_options = z164.object({
3524
+ method: z164.enum(["trap", "gear"]).optional(),
3525
+ reltol: z164.union([z164.number(), z164.string()]).optional(),
3526
+ abstol: z164.union([z164.number(), z164.string()]).optional(),
3527
+ vntol: z164.union([z164.number(), z164.string()]).optional()
3528
+ }).describe("SPICE solver options for a simulation experiment");
3715
3529
  var simulation_experiment = z164.object({
3716
3530
  type: z164.literal("simulation_experiment"),
3717
3531
  simulation_experiment_id: getZodPrefixedIdWithDefault(
@@ -3721,7 +3535,8 @@ var simulation_experiment = z164.object({
3721
3535
  experiment_type,
3722
3536
  time_per_step: duration_ms.optional(),
3723
3537
  start_time_ms: ms.optional(),
3724
- end_time_ms: ms.optional()
3538
+ end_time_ms: ms.optional(),
3539
+ spice_options: spice_simulation_options.optional()
3725
3540
  }).describe("Defines a simulation experiment configuration");
3726
3541
  expectTypesMatch(true);
3727
3542
 
@@ -4042,6 +3857,7 @@ export {
4042
3857
  manufacturing_drc_properties,
4043
3858
  ms,
4044
3859
  ninePointAnchor,
3860
+ parseAndConvertSiUnit2 as parseAndConvertSiUnit,
4045
3861
  pcbRenderLayer,
4046
3862
  pcb_autorouting_error,
4047
3863
  pcb_board,
@@ -4231,6 +4047,7 @@ export {
4231
4047
  source_simple_voltage_source,
4232
4048
  source_trace,
4233
4049
  source_trace_not_connected_error,
4050
+ spice_simulation_options,
4234
4051
  supplier_footprint_mismatch_warning,
4235
4052
  supplier_name,
4236
4053
  time,