parse-ingredient - v2.0.1
    Preparing search index...

    Function convertUnit

    • Converts a value from one unit to another.

      Parameters

      • value: number

        The numeric value to convert.

      • fromUnit: string

        The unit to convert from (unit ID, short, plural, or alternate spelling).

      • toUnit: string

        The unit to convert to (unit ID, short, plural, or alternate spelling).

      • options: ConvertUnitOptions = {}

        Conversion options.

      Returns number | null

      The converted value, or null if conversion is not possible (incompatible types, missing conversion factors, or unknown units).

      convertUnit(1, 'cup', 'milliliter') // ~236.588 (US)
      convertUnit(1, 'cup', 'milliliter', { fromSystem: 'imperial' }) // ~284.131
      convertUnit(1, 'pound', 'gram') // ~453.592
      convertUnit(1, 'cup', 'gram') // null (incompatible types)