The unit of measure to classify (canonical or alias form).
The unit's kind, or undefined if the unit isn't recognized.
getUomKind("kg") // Returns "mass"
getUomKind("floz") // Returns "volume"
getUomKind("pcs") // Returns "count"
getUomKind("xyz") // Returns undefined
export function getUomKind(uom: string): UomKind | undefined {
const standardized = standardizeUom(uom);
if (!standardized) return undefined;
switch (standardized) {
case UOM.MG:
case UOM.G:
case UOM.KG:
case UOM.LB:
case UOM.OZ:
return 'mass';
case UOM.ML:
case UOM.L:
case UOM.QT:
case UOM.GAL:
case UOM.FLOZ:
return 'volume';
case UOM.PCS:
case UOM.EA:
return 'count';
default:
return undefined;
}
}
Classifies a unit of measure as mass, volume, or countable. Standardizes the input first (via standardizeUom), so aliases like
"grams"or"lbs"are accepted. Returnsundefinedfor unrecognized units.