npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@jclind/ingredient-parser

v1.3.4

Published

Parses given sentence including ingredient information and attempts to return quantity, measurement and ingredient data

Downloads

1,754

Readme

@jclind/ingredient-parser

npm version license

A TypeScript package for parsing ingredient strings and retrieving structured ingredient data from the Spoonacular API.

Built on top of recipe-ingredient-parser-v3. If you only need ingredient parsing without ingredient metadata, nutrition, or API lookups, you may prefer using that package directly.

Installation

npm install @jclind/ingredient-parser

Quick Start

import { ingredientParser } from '@jclind/ingredient-parser'

const result = await ingredientParser('1 cup rice, washed', 'YOUR_API_KEY', {
  returnNutritionData: true,
})

console.log(result)

API

ingredientParser(ingredientString, apiKey, options?)

Parses an ingredient string and returns both the parsed ingredient data and ingredient metadata retrieved from Spoonacular.

import { ingredientParser } from '@jclind/ingredient-parser'

ingredientParser(
  ingredientString: string,
  apiKey: string,
  options?: {
    returnNutritionData?: boolean
    imageSize?: '100x100' | '250x250' | '500x500'
    serverUrl?: string
  }
): Promise<IngredientResponse>

| Parameter | Type | Required | Description | | ------------------ | -------- | -------- | ------------------------------------------------------- | | ingredientString | string | Yes | Ingredient string formatted like 2 cups onions, diced | | apiKey | string | Yes | Your Spoonacular API key | | options | object | No | Additional parsing options |

Options

| Option | Type | Default | Description | | --------------------- | --------------------------------------- | ----------- | ------------------------------------------------------------- | | returnNutritionData | boolean | false | Includes Spoonacular nutrition data in ingredientData | | imageSize | '100x100' \| '250x250' \| '500x500' | '100x100' | Size of the ingredient image returned in imagePath | | serverUrl | string | — | Override the default proxy server URL used to call Spoonacular |


parseIngredientString(ingredientString)

Parses an ingredient string locally without any network calls. Use this when you only need quantity, unit, and ingredient name extraction.

import { parseIngredientString } from '@jclind/ingredient-parser'

parseIngredientString(ingredientString: string): ParsedIngredient
parseIngredientString('1 cup rice, washed')
// {
//   quantity: 1,
//   unit: 'cup',
//   unitPlural: 'cups',
//   symbol: 'c',
//   ingredient: 'rice',
//   originalIngredientString: '1 cup rice, washed',
//   minQty: 1,
//   maxQty: 1,
//   comment: 'washed'
// }

Response Structure

ingredientParser returns a discriminated union. On success, ingredientData is always present. On error, error is present and ingredientData is null.

// Success
{
  parsedIngredient: ParsedIngredient
  ingredientData: IngredientData
  id?: string
}

// Error
{
  error: { message: string }
  parsedIngredient: ParsedIngredient
  ingredientData: null
  id?: string
}

parsedIngredient

{
  quantity: 1,
  unit: 'cup',
  unitPlural: 'cups',
  symbol: 'c',
  ingredient: 'rice',
  originalIngredientString: '1 cup rice, washed',
  minQty: 1,
  maxQty: 1,
  comment: 'washed'
}

ingredientData

{
  ingredientId: 20444,
  originalName: 'rice',
  name: 'rice',
  amount: 1,
  possibleUnits: ['g', 'oz', 'cup'],
  consistency: 'solid',
  shoppingListUnits: ['ounces', 'pounds'],
  aisle: 'Pasta and Rice',
  image: 'uncooked-white-rice.png',
  imagePath: 'https://spoonacular.com/cdn/ingredients_100x100/uncooked-white-rice.png',
  nutrition?: {
    nutrients: [...],
    properties: [...],
    flavonoids: [...],
    caloricBreakdown: {...},
    weightPerServing: {...}
  },
  totalPriceUSACents: 75.71
}

Error Handling

The function returns an error object (and ingredientData: null) when the ingredient cannot be identified or the API key is invalid. parsedIngredient is always populated.

Unknown Ingredient

const result = await ingredientParser('Invalid Text', 'YOUR_API_KEY')

/*
{
  error: { message: 'Ingredient not formatted correctly or Ingredient Unknown. Please pass ingredient comments/instructions after a comma' },
  ingredientData: null,
  parsedIngredient: {
    quantity: null,
    unit: null,
    unitPlural: null,
    symbol: null,
    ingredient: 'Invalid Text',
    originalIngredientString: 'Invalid Text',
    minQty: null,
    maxQty: null,
    comment: null
  }
}
*/

Invalid API Key

const result = await ingredientParser('1 cup rice', 'INVALID_KEY')

/*
{
  error: { message: 'API Key Not Valid' },
  ingredientData: null,
  parsedIngredient: {
    quantity: 1,
    unit: 'cup',
    unitPlural: 'cups',
    symbol: 'c',
    ingredient: 'rice',
    originalIngredientString: '1 cup rice',
    minQty: 1,
    maxQty: 1,
    comment: null
  }
}
*/

TypeScript

This package ships with full TypeScript definitions. No additional @types package required.

import {
  ingredientParser,
  parseIngredientString,
  ParsedIngredient,
  IngredientData,
  IngredientResponse,
} from '@jclind/ingredient-parser'

const result: IngredientResponse = await ingredientParser(
  '1 cup rice, washed',
  'YOUR_API_KEY'
)

if ('error' in result) {
  console.error(result.error.message)
} else {
  const parsed: ParsedIngredient = result.parsedIngredient
  const data: IngredientData = result.ingredientData
}

Notes

  • A valid Spoonacular API key is required for ingredient lookups via ingredientParser.
  • parseIngredientString works offline with no API key.
  • Nutrition data is optional and disabled by default to reduce API usage.
  • parsedIngredient is always populated, even when the API call fails.

Issues & Contributing

Found a bug or have a feature request? Open an issue on GitHub. PRs are welcome.