Files
admin-web/src/modules/overseas-warehouse/dispatchPhysicalWeight.ts
T

23 lines
726 B
TypeScript
Raw Normal View History

const kilogramsToPounds = 2.2046226218
export function physicalWeightKg(value: unknown): number | null {
if (value == null || value === '') return null
const number = Number(value)
return Number.isFinite(number) && number > 0 ? number : null
}
export function physicalWeightLb(value: unknown): number | null {
const weight = physicalWeightKg(value)
return weight === null ? null : weight * kilogramsToPounds
}
export function totalPhysicalWeightLb(items: readonly ({ grossWeightKg?: number | null } | undefined)[]): number | null {
let total = 0
for (const item of items) {
const weight = physicalWeightLb(item?.grossWeightKg)
if (weight === null) return null
total += weight
}
return total
}