Skip to content

Commit

Permalink
Battery types, batteryProps, set default unit to mAh (#63)
Browse files Browse the repository at this point in the history
* Battery types, batteryProps, set default unit to mAh

* Update lib/components/battery.ts
  • Loading branch information
seveibar authored Oct 17, 2024
1 parent 4a2e8ca commit ef9269d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/components/battery.ts
Original file line number Diff line number Diff line change
@@ -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<BatteryProps, z.input<typeof batteryProps>>(true)
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ef9269d

Please sign in to comment.