All files / src/data UnitsLibrary.ts

65% Statements 13/20
63.63% Branches 7/11
100% Functions 2/2
69.23% Lines 9/13

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              15645x 15618x                     15645x 16069x 15618x 15618x       598x 598x 601x                
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 {
  if (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;
}