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 🙏

© 2024 – Pkg Stats / Ryan Hefner

recipes-parser

v1.3.9

Published

A library to parse recipes (string text entry) and exctract aliments, units and weights

Downloads

270

Readme

recipes-parser

coverage coverage coverage coverage

Parse recipes instructions (string text entry) and extract ingredients, units and quantity.

Features

  • Based on NLP (natural language processing) and pegsjs library
  • Available in English and French, but has support for custom languages

Install

npm install recipes-parser --save

Usage

import fs from "fs";
import * as path from "path";
import RecipesParser from "recipes-parser";

import units from "recipes-parser/lib/nlp/en/units.json";
import globalUnit from "recipes-parser/lib/nlp/en/global_unit.json";
const rules = fs.readFileSync(
  path.join(__dirname, `node_modules/recipes-parser/nlp/en/rules.pegjs`),
  {
    encoding: "utf8",
  }
);

const parser = new RecipesParser(rules, units, globalUnit);

const results = parser.getIngredientsFromText(
  ["3 cl. fresh raspberries"],
  true
);

getIngredientsFromText(instructions: string[], returnUnitKey?: boolean): object: IRecipeResult[]

instructions

The list of instructions. Supports NLP queries.

returnUnitKey

If true return the matched key, if false return the matched text.

IRecipeResult {
  result?: { // the result when matched OK
    instruction: string; // the instruction parsed
    unit: string; // the unit matched
    amount: number; ; // the quantity calculated
    ingredient: string; // the quantity matched
  };
  unknown: {  // the result matched OK
    instruction?: string;   // the instructon parsed
    reasons?: UNKNOWN_REASONS[]; // the array of reasons why matched is OK
  };
}

enum UNKNOWN_REASONS {
  PARSING = "mismatch during parsing",
  PARSING_AMOUNT = "unknown amount",
  PARSING_UNIT = "unknown unit",
  NO_ENTRY = "unavailable ingredient"
}

Examples

Simple number detection: 1 kilogram of chicken

{
  "result": {
    "ingredient": "chicken",
    "unit": "kg",
    "amount": 1
  }
}

Fraction number detection: 1/2 kilogram of chicken

{
  "result": {
    "ingredient": "chicken",
    "unit": "kg",
    "amount": 0.5
  }
}

Approximation number detection: 2-3 teaspoons of sugar

{
  "result": {
    "ingredient": "sugar",
    "unit": "teaspoon",
    "amount": 2.5
  }
}

Word number detection: Seven teaspoons of sugar

{
  "result": {
    "ingredient": "sugar",
    "unit": "teaspoon",
    "amount": 7
  }
}

Word and fraction number detection: 5 1/2 liter of milk

{
  "result": {
    "ingredient": "milk",
    "unit": "liter",
    "amount": 2.5
  }
}

Word and number detection: 5 quarter of orange

{
  "result": {
    "ingredient": "orange",
    "unit": "undefined",
    "amount": 1.25
  }
}

Abbreviation units detection: 5 tbsp of milk

{
  "result": {
    "ingredient": "orange",
    "unit": "tablespoon",
    "amount": 1.25
  }
}

License

MIT