Normalizes a quantity object to its base unit of measure.
Parses a quantity string into a structured object containing the numeric value and unit of measure. Handles various formats including foreign number formats (e.g., 1.234,56). Uses regex pattern matching to extract quantity and unit information.
Strips the quantity from a string. This is useful for when some suppliers don't have products listed as variants, but instead have multiple products with a quantity in the name. Using this function, we can get the name of the product without the quantity, which may be identical to the other variations. Making it easy to group the products into a single listing with multiple variants.
Standardizes a unit of measure (UOM) to its canonical form. Uses the uomAliases mapping to convert various representations to standard forms.
Converts a quantity from its current unit to a common unit of mass or volume. This is to make it easier to compare quantities of different units.
Classifies a unit of measure as mass, volume, or countable. Standardizes the
input first (via standardizeUom), so aliases like "grams" or "lbs"
are accepted. Returns undefined for unrecognized units.
Normalizes a quantity to the base unit used for per-unit cost comparison:
grams for mass, millilitres for volume, and the unchanged countable unit for
pieces/each. Unlike toBaseQuantity (which returns milligrams for mass),
this steps mass up to grams so a cost-per-gram reads naturally. Returns
undefined for an unrecognized unit or a non-positive quantity, so callers can
safely divide by the result.
Formats a unit of measure (UOM) for display.
Converts a quantity to its "standard" (metric) form, leaving metric and countable units untouched. Imperial mass (lb, oz) becomes grams (then normalized up to kg via normalizeQuantity); imperial volume (gal, qt, fl oz) becomes millilitres (then normalized up to l). Built on toBaseQuantity for the conversion factors so suppliers can present a single, comparable unit system regardless of how the source lists it.