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

    Interface ParseIngredientOptions

    Options available to parseIngredient.

    interface ParseIngredientOptions {
        additionalUOMs?: UnitOfMeasureDefinitions;
        allowLeadingOf?: boolean;
        decimalSeparator?: "." | ",";
        descriptionStripPrefixes?: (string | RegExp)[];
        groupHeaderPatterns?: (string | RegExp)[];
        ignoreUOMs?: string[];
        includeMeta?: boolean;
        normalizeUOM?: boolean;
        partialUnitMatching?: boolean;
        rangeSeparators?: (string | RegExp)[];
        trailingQuantityContext?: string[];
    }
    Index

    Properties

    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).

    "."
    
    descriptionStripPrefixes?: (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?: (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?: 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
    
    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?: (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', 'à']
    
    trailingQuantityContext?: 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']