diff --git a/lib/components/battery.ts b/lib/components/battery.ts new file mode 100644 index 0000000..b8b84a9 --- /dev/null +++ b/lib/components/battery.ts @@ -0,0 +1,36 @@ +import { z } from "zod" +import { + commonComponentProps, + lrPins, + lrPolarPins, + type CommonComponentProps, +} from "lib/common/layout" +import { expectTypesMatch } from "lib/typecheck" + +/** @deprecated use battery_capacity from circuit-json when circuit-json is updated */ +const capacity = z + .number() + .or(z.string().endsWith("mAh")) + .transform((v) => { + if (typeof v === "string") { + const valString = v.replace("mAh", "") + const num = Number.parseFloat(valString) + if (Number.isNaN(num)) { + throw new Error("Invalid capacity") + } + return num + } + return v + }) + .describe("Battery capacity in mAh") + +export interface BatteryProps extends CommonComponentProps { + capacity?: number | string +} + +export const batteryProps = commonComponentProps.extend({ + capacity: capacity.optional(), +}) +export const batteryPins = lrPolarPins + +expectTypesMatch>(true) diff --git a/lib/index.ts b/lib/index.ts index 8f459ba..4f786f3 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -61,6 +61,7 @@ export * from "./components/solderpaste" export * from "./components/hole" export * from "./components/trace" export * from "./components/footprint" +export * from "./components/battery" export const inductorProps = commonComponentProps.extend({ inductance,