Simple recipe ingredient parser. Parses a single line of text into a JavaScript Object that represents the best guess at what the ingredient line should be.
Works in any browser that supports Array.forEach, Array.reduce, and Object.keys.
I'm building a recipe management application and there were no good ingredient parsers in existence that worked in the browser. So, I wrote one.
npm install ingredientparser
- Breaks up the input string on whitespace characters (space and tab)
- Checks for and concatenates numeric or fractional values
- Checks for optional or (optional)
- Checks for "to taste"
- Checks for text in ()'s to find preparation steps
- Removes all noise words
- Returns the resulting object
<amount> <unit> [of] (<prep>) <ingredient> optional|(optional) (<prep>)
var ing = require('ingredientparser');
console.log(ing.parse('1 cup brown sugar'));
Outputs:
{ amount: '1',
unit: 'Cup',
name: 'brown sugar' }
mocha test
or
npm test
Found a bug, submit a new issue along with a failing test. If you feel really nice and want a thank you, submit a pull request to resolve it as well.