Blame view

.pnpm-store/v11/projects/0e47ef389c0c12bdfaeb86af6e6a20bb/src/utils/weightElement.ts 674 Bytes
383e20a3   杨鑫   拉取
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  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'
  }