{"id":21448945,"url":"https://github.com/charlie85270/recipes-parser","last_synced_at":"2025-07-14T20:31:29.204Z","repository":{"id":44273676,"uuid":"256333077","full_name":"Charlie85270/recipes-parser","owner":"Charlie85270","description":"Natural language parser for recipes and lists of ingredients, units and quantity","archived":false,"fork":false,"pushed_at":"2023-11-16T22:10:35.000Z","size":1391,"stargazers_count":38,"open_issues_count":17,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-29T08:18:34.749Z","etag":null,"topics":["cooking","ingredient","ingredients","ingredients-list","parser","recipes","recipes-parser"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Charlie85270.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-16T21:24:12.000Z","updated_at":"2025-01-16T17:58:49.000Z","dependencies_parsed_at":"2023-02-05T05:46:16.964Z","dependency_job_id":null,"html_url":"https://github.com/Charlie85270/recipes-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Charlie85270/recipes-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Charlie85270%2Frecipes-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Charlie85270%2Frecipes-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Charlie85270%2Frecipes-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Charlie85270%2Frecipes-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Charlie85270","download_url":"https://codeload.github.com/Charlie85270/recipes-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Charlie85270%2Frecipes-parser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265344829,"owners_count":23750566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cooking","ingredient","ingredients","ingredients-list","parser","recipes","recipes-parser"],"created_at":"2024-11-23T03:17:37.091Z","updated_at":"2025-07-14T20:31:28.836Z","avatar_url":"https://github.com/Charlie85270.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# recipes-parser\n\n![coverage](https://raw.githubusercontent.com/Charlie85270/recipes-parser/5653f5424d15d5e8ddce3d09c35170f41f0ea062/coverage/badge-branches.svg \"coverage\") ![coverage](https://raw.githubusercontent.com/Charlie85270/recipes-parser/5653f5424d15d5e8ddce3d09c35170f41f0ea062/coverage/badge-functions.svg \"coverage\") ![coverage](https://raw.githubusercontent.com/Charlie85270/recipes-parser/5653f5424d15d5e8ddce3d09c35170f41f0ea062/coverage/badge-lines.svg \"coverage\") ![coverage](https://raw.githubusercontent.com/Charlie85270/recipes-parser/5653f5424d15d5e8ddce3d09c35170f41f0ea062/coverage/badge-statements.svg \"coverage\")\n\nParse recipes instructions (string text entry) and extract ingredients, units and quantity.\n\n## Features\n\n- Based on NLP (natural language processing) and [pegsjs](https://github.com/pegjs/pegjs \"pegsjs\") library\n- Available in English and French, but has support for custom languages\n\n## Install\n\n```sh\nnpm install recipes-parser --save\n```\n\n## Usage\n\n```ts\nimport fs from \"fs\";\nimport * as path from \"path\";\nimport RecipesParser from \"recipes-parser\";\n\nimport units from \"recipes-parser/lib/nlp/en/units.json\";\nimport globalUnit from \"recipes-parser/lib/nlp/en/global_unit.json\";\nconst rules = fs.readFileSync(\n  path.join(__dirname, `node_modules/recipes-parser/nlp/en/rules.pegjs`),\n  {\n    encoding: \"utf8\",\n  }\n);\n\nconst parser = new RecipesParser(rules, units, globalUnit);\n\nconst results = parser.getIngredientsFromText(\n  [\"3 cl. fresh raspberries\"],\n  true\n);\n```\n\n### `getIngredientsFromText(instructions: string[], returnUnitKey?: boolean): object: IRecipeResult[]`\n\n### instructions\n\nThe list of instructions. Supports NLP queries.\n\n### returnUnitKey\n\nIf true return the matched key, if false return the matched text.\n\n```ts\nIRecipeResult {\n  result?: { // the result when matched OK\n    instruction: string; // the instruction parsed\n    unit: string; // the unit matched\n    amount: number; ; // the quantity calculated\n    ingredient: string; // the quantity matched\n  };\n  unknown: {  // the result matched OK\n    instruction?: string;   // the instructon parsed\n    reasons?: UNKNOWN_REASONS[]; // the array of reasons why matched is OK\n  };\n}\n\nenum UNKNOWN_REASONS {\n  PARSING = \"mismatch during parsing\",\n  PARSING_AMOUNT = \"unknown amount\",\n  PARSING_UNIT = \"unknown unit\",\n  NO_ENTRY = \"unavailable ingredient\"\n}\n\n```\n\n#### Examples\n\nSimple number detection: **1 kilogram of chicken**\n\n```json\n{\n  \"result\": {\n    \"ingredient\": \"chicken\",\n    \"unit\": \"kg\",\n    \"amount\": 1\n  }\n}\n```\n\nFraction number detection: **1/2 kilogram of chicken**\n\n```json\n{\n  \"result\": {\n    \"ingredient\": \"chicken\",\n    \"unit\": \"kg\",\n    \"amount\": 0.5\n  }\n}\n```\n\nApproximation number detection: **2-3 teaspoons of sugar**\n\n```json\n{\n  \"result\": {\n    \"ingredient\": \"sugar\",\n    \"unit\": \"teaspoon\",\n    \"amount\": 2.5\n  }\n}\n```\n\nWord number detection: **Seven teaspoons of sugar**\n\n```json\n{\n  \"result\": {\n    \"ingredient\": \"sugar\",\n    \"unit\": \"teaspoon\",\n    \"amount\": 7\n  }\n}\n```\n\nWord and fraction number detection: **5 1/2 liter of milk**\n\n```json\n{\n  \"result\": {\n    \"ingredient\": \"milk\",\n    \"unit\": \"liter\",\n    \"amount\": 2.5\n  }\n}\n```\n\nWord and number detection: **5 quarter of orange**\n\n```json\n{\n  \"result\": {\n    \"ingredient\": \"orange\",\n    \"unit\": \"undefined\",\n    \"amount\": 1.25\n  }\n}\n```\n\nAbbreviation units detection: **5 tbsp of milk**\n\n```json\n{\n  \"result\": {\n    \"ingredient\": \"orange\",\n    \"unit\": \"tablespoon\",\n    \"amount\": 1.25\n  }\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlie85270%2Frecipes-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharlie85270%2Frecipes-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlie85270%2Frecipes-parser/lists"}