All files / src/data UnitsLibrary.ts

66.66% Statements 14/21
58.33% Branches 7/12
83.33% Functions 5/6
71.42% Lines 10/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37              6307x 6275x             6307x       6307x 6405x 6275x 6275x       28x 28x 28x                
import { UnitTypeEnum } from "@/api/apiStore.gen";
import unitsLibrary from "@/data/units.json";
 
/**
 * Get the available unit options for a given unit type
 */
export function GetUnitSet(unitType: UnitTypeEnum | undefined): UnitItem[] {
  if (!unitType || unitType === "dimensionless") return [];
  return unitsLibrary[unitType] || [];
}
 
/**
 * Get a unit display string for a given unit type and unit
 */
export function GetUnitDisplay(unitSet: UnitItem[], unit: string): string {
  Iif (unit == "" && unitSet.length > 0) {
    // default unit for now until they get set in the backend
    return unitSet[0].value;
  }
  if (!unit) return "Undefined";
  const unitObj = unitSet.find((u) => u.value === unit);
  Iif (!unitObj) return unit;
  return unitObj.value;
}
 
export function GetQuickUnits(unitType, unit) {
  const unitSet = unitsLibrary[unitType];
  Iif (!unitSet) return unit;
  return unitSet.find((u) => u.value === unit).label;
}
 
export function GetDefaultUnit(unitType: UnitTypeEnum) {
  const unitSet = unitsLibrary[unitType];
  Iif (!unitSet) return "";
  return unitSet[0].value;
}