weightElement.ts 674 Bytes
export type WeightInputMode = 'net' | 'tare'

export function readWeightInputMode(cfg: Record<string, unknown> | undefined | null): WeightInputMode {
  const v = String(cfg?.weightInputMode ?? cfg?.WeightInputMode ?? 'net')
    .trim()
    .toLowerCase()
  return v === 'tare' ? 'tare' : 'net'
}

export function formatWeightDisplay(rawValue: string, unit: string): string {
  const raw = String(rawValue ?? '').trim()
  const u = String(unit ?? '').trim()
  if (!raw) return ''
  if (u && !raw.endsWith(u)) return `${raw}${u}`
  return raw
}

export function weightInputPlaceholder(mode: WeightInputMode): string {
  return mode === 'tare' ? 'Tare weight' : 'Net weight'
}