parse-ingredient - v3.0.0
    Preparing search index...

    Interface ParseIngredientOptions

    Options available to parseIngredient.

    interface ParseIngredientOptions {
        additionalUOMs?: UnitOfMeasureDefinitions;
        allowLeadingOf?: boolean;
        decimalSeparator?: "." | ",";
        descriptionMeasurements?: boolean;
        descriptionStripPrefixes?: readonly (string | RegExp)[];
        groupHeaderPatterns?: readonly (string | RegExp)[];
        ignoreUOMs?: readonly string[];
        includeMeta?: boolean;
        leadingQuantityPrefixes?: readonly (string | RegExp)[];
        measurementUnits?: MeasurementUnitFilter;
        normalizeUOM?: boolean;
        partialUnitMatching?: boolean;
        rangeSeparators?: readonly (string | RegExp)[];
        round?: number | false;
        trailingQuantityContext?: readonly string[];
    }
    Index
    additionalUOMs?: UnitOfMeasureDefinitions

    An object that matches the format of unitsOfMeasure. Keys that match any in unitsOfMeasure will be used instead of the default, and any others will be added to the list of known units of measure when parsing ingredients.

    {}
    
    allowLeadingOf?: boolean

    If true, ingredient descriptions that start with "of " will not be modified. (By default, a leading "of " will be removed from all descriptions.)

    false
    
    decimalSeparator?: "." | ","

    The character used as a decimal separator in numeric quantities. Use "," for European-style decimal commas (e.g., "1,5" for 1.5).

    "."
    
    descriptionMeasurements?: boolean

    When true, each ingredient gets a descriptionMeasurements array holding the quantity/unit pairs found within its description — e.g. the 1 1/2-inch in "1 pound beef, cut into 1 1/2-inch cubes".

    The description is scanned, not the source line, so the ingredient's own quantity and unit are never re-reported.

    false
    
    descriptionStripPrefixes?: readonly (string | RegExp)[]

    Words or patterns to strip from the beginning of ingredient descriptions. Commonly used to remove "of" from phrases like "1 cup of sugar". Strings are matched as whole words followed by whitespace. RegExp patterns are used as-is for more complex matching (e.g., French elisions).

    ['of']
    
    ['of', 'de', /d[eu]?\s/iu, new RegExp("de\\s+l[ae']?\\s*", "iu")]
    
    groupHeaderPatterns?: readonly (string | RegExp)[]

    Patterns to identify group headers (e.g., "For the icing:"). Strings are treated as prefix patterns (matched at the start of the line followed by whitespace). RegExp patterns are used as-is for more complex matching.

    ['For']
    
    ['For', 'Für', /^Pour\s/iu]
    
    ignoreUOMs?: readonly string[]

    An array of strings to ignore as units of measure when parsing ingredients.

    parseIngredient('2 small eggs', {
    ignoreUOMs: ['small', 'medium', 'large']
    })
    // [
    // {
    // quantity: 2,
    // quantity2: null,
    // unitOfMeasure: null,
    // unitOfMeasureID: null,
    // description: 'small eggs',
    // isGroupHeader: false,
    // }
    // ]
    []
    
    includeMeta?: boolean

    If true, include a meta property on each ingredient containing the original text, original index, and other metadata.

    false
    
    leadingQuantityPrefixes?: readonly (string | RegExp)[]

    Words or patterns to strip from the beginning of a quantity expression. Useful for approximation prefixes like "about 2 cups", "ca. 200 g", or range modifiers like "bis zu 3 EL".

    List longer/more-specific patterns before shorter ones (e.g., ['ca.', 'ca'] instead of ['ca', 'ca.']) since regex alternation matches left-to-right.

    []
    
    ['about', 'approx.', 'ca.', 'etwa', 'bis zu']
    
    measurementUnits?: MeasurementUnitFilter

    Which units count as a description measurement. Has no effect unless descriptionMeasurements is true.

    Note that piece, pinch, large, etc. are real units, so with the default of 'all', "cut into 4 pieces" is a measurement. Use 'convertible' to see only units convertUnit can act on.

    'all'
    
    normalizeUOM?: boolean

    Converts the unit of measure (unitOfMeasure property) of each ingredient to its long, singular form. For example, "ml" becomes "milliliter" and "cups" becomes "cup".

    false
    
    partialUnitMatching?: boolean

    When true, if normal whitespace-based parsing fails to identify a unit of measure, the parser scans the description for known UOM strings registered via additionalUOMs. Useful for CJK languages where words are not separated by spaces.

    false
    
    rangeSeparators?: readonly (string | RegExp)[]

    Words or patterns to identify ranges between quantities (e.g., "1 to 2", "1 or 2"). Strings are matched as whole words followed by whitespace. RegExp patterns are used as-is for more complex matching.

    ['to', 'or']
    
    ['to', 'or', 'bis', 'oder', 'à']
    
    round?: number | false

    Round parsed quantities to this many decimal places, or false to disable rounding. Forwarded to numericQuantity.

    With the default of 3, "1 11/16" yields 1.688; with false it yields 1.6875.

    3
    
    trailingQuantityContext?: readonly string[]

    Words that indicate a trailing quantity extraction context. Used to identify patterns like "Juice of 3 lemons" or "Peels from 5 oranges".

    ['from', 'of']
    
    ['from', 'of', 'von', 'de']