@recipecloudapp/ingredient-parser
v0.1.6
Published
Lightweight ingredient line parser (shared across web, cloud, iOS)
Readme
@recipecloudapp/ingredient-parser
A lightweight, language-aware ingredient line parser.
It normalizes quantities (fractions, ranges, decimals), units (tsp/tablespoon/cup/etc.), and extracts ingredient names plus notes.
Built for use across Recipe Cloud’s web app, server functions, and iOS app (via JavaScriptCore).
Ships as ESM, CJS, and IIFE (global window.IngParser) for maximum compatibility.
Install
npm i @recipecloudapp/ingredient-parser
# or: pnpm add @recipecloudapp/ingredient-parser
# or: yarn add @recipecloudapp/ingredient-parserUsage
import { parseLine, parseLines } from '@recipecloudapp/ingredient-parser';
const node = parseLine('1/2 cup tomato sauce (no salt)');
// → {
// type: 'item',
// quantity: 0.5,
// unit: { canonical: 'cup', raw: 'cup', abbr: 'cup', display: 'cup' },
// ingredient: 'tomato sauce',
// postNote: 'no salt'
// }Or in the browser (IIFE build):
<script src="dist/index.iife.js"></script>
<script>
const result = window.IngParser.parseLines([
'1 teaspoon oregano, optional',
'For the Quick Sauce:',
'1/2 cup tomato sauce (no salt)'
]);
console.log(result.items);
</script>Features
- Parses mixed numbers, fractions, and ranges (
1 1/2,½,1–2). - Normalizes units across multiple languages (
tsp,cda,cas, etc.). - Extracts and separates ingredient name, notes, and trailing parentheticals.
- Supports group headings like
For the sauce:.
License & Copyright
© 2025 Recipe Cloud LLC. All rights reserved.
