@tmlmt/cooklang-parser 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,35 +2,34 @@
2
2
 
3
3
  A typescript library to parse and manipulate [cooklang](https://cooklang.org/) recipes.
4
4
 
5
+ <picture><img src="https://badges.ws/maintenance/yes/2025" /></picture>
6
+ <picture><img src="https://badges.ws/npm/dt/@tmlmt/cooklang-parser" /></picture>
7
+ <picture><img src="https://badges.ws/npm/l/@tmlmt/cooklang-parser" /></picture>
8
+ <picture><img src="https://badges.ws/github/release/tmlmt/cooklang-parser" /></picture>
9
+ [<img src="https://badges.ws/badge/documentation-5672CD?icon=vitepress" />](https://cooklang-parser.tmlmt.com)
10
+
5
11
  ## Introduction
6
12
 
7
13
  This library provides a set of tools to work with recipes written in the Cooklang format. It allows you to parse recipes, extract ingredients, cookware, and timers, scale recipes, and generate shopping lists.
8
14
 
9
- The documentation is available at [https://cooklang-parser.tmlmt.com](https://cooklang-parser.tmlmt.com) (work in progress)
10
-
11
15
  ## Features
12
16
 
13
17
  - **Cooklang Compliant:** Fully compliant with the Cooklang specifications.
14
- - **Recipe Parsing:** Parse Cooklang recipes to extract metadata, ingredients, cookware, timers, and steps. Several extensions on top of the original cooklang specifications:
15
- - **Useful modifiers:** in line with the same in the canonical cooklang parser in Rust ([cooklang-rs](https://github.com/cooklang/cooklang-rs/blob/main/extensions.md))
16
- - `@`: referenced recipe
17
- - `&`: referenced ingredient (quantities will be added)
18
- - `-`: hidden ingredient
19
- - `?`: optional ingredient
20
- - **Range values:**
21
- - `@eggs{2-4}` will show eggs as an ingredient with a quantity range of 2 to 4
22
- - `@water{1%L} and @&water{1/4-1/2%L}` will show water as an ingredient with a quantity range of 1.25 to 1.5 L
23
- - Also works with Cookware and Timers
18
+ - **Recipe Parsing:** Parse Cooklang recipes to extract metadata, ingredients, cookware, timers, and steps.
19
+ Several extensions on top of the original cooklang specifications
20
+ and [detailed in the docs](https://cooklang-parser.tmlmt.com/guide-extensions).
24
21
  - **Recipe Scaling:** Scale recipes by a given factor.
25
22
  - **Shopping Lists:** Generate shopping lists from one or more recipes.
26
- - **Aisle Configuration:** Categorize shopping list ingredients based on a custom aisle configuration.
23
+ - **Category Configuration:** Categorize shopping list ingredients based on a custom category configuration.
27
24
  - **Typescript:** Written in Typescript, providing type safety for all the data structures.
28
25
 
29
26
  ## Quick start
30
27
 
31
- Install the package with your favorite package manager e.g. `npm install @tmlmt/cooklang-parser`
28
+ - Install the package with your favorite package manager, e.g.:
29
+
30
+ `npm install @tmlmt/cooklang-parser`
32
31
 
33
- To get started, you can use the `Recipe` class to parse a cooklang recipe:
32
+ - Use the `Recipe` class to parse a cooklang recipe:
34
33
 
35
34
  ```typescript
36
35
  import { Recipe } from "@tmlmt/cooklang-parser";
@@ -52,50 +51,18 @@ Serve hot.
52
51
  const recipe = new Recipe(recipeString);
53
52
 
54
53
  console.log(recipe.metadata.title); // "Pancakes"
55
- console.log(recipe.ingredients);
56
- console.log(recipe.cookware);
57
- console.log(recipe.timers);
58
- ```
59
-
60
- You can also create a shopping list from multiple recipes:
61
-
62
- ```typescript
63
- import { ShoppingList, Recipe } from "@tmlmt/cooklang-parser";
64
-
65
- const recipe1 = new Recipe(/* ... */);
66
- const recipe2 = new Recipe(/* ... */);
67
-
68
- const shoppingList = new ShoppingList();
69
- shoppingList.add_recipe(recipe1);
70
- shoppingList.add_recipe(recipe2);
71
-
72
- console.log(shoppingList.ingredients);
54
+ console.log(recipe.ingredients); // [{ name: "eggs", ...}, ...]
55
+ console.log(recipe.cookware); // [{ name: "pan", ...}]
56
+ console.log(recipe.timers); // [{ duration: 15, unit: "minutes", name: undefined}]
73
57
  ```
74
58
 
75
- And you can categorize those ingredients according to an aisle configuration defined in the cooklang format:
76
-
77
- ```typescript
78
- const shoppingList = `
79
- [Dairy]
80
- milk
81
- butter
82
-
83
- [Bakery]
84
- flour
85
- sugar
86
- `;
87
-
88
- shoppingList.set_aisle_config(aisleConfig);
89
- shoppingList.categorize();
90
-
91
- console.log(shoppingList.categories);
92
- ```
59
+ - Browse the [API Reference](https://cooklang-parser.tmlmt.com/api/classes/Recipe) to discover all functionalities
93
60
 
94
61
  ## Future plans
95
62
 
96
- I plan to further develop features depending on the needs I will encounter in using this library in a practical application. The current todo includes:
63
+ I plan to further develop features depending on the needs or bugs I will encounter in using this library in a practical application. Current backlog is as follows:
97
64
 
98
- - Ingredients aliases. See issue tmlmt/cooklang-parser#5
65
+ - Pantry parsing and basic functions (e.g. take pantry into account when creating a shopping list)
99
66
 
100
67
  ## Test coverage
101
68
 
@@ -103,8 +70,6 @@ This project includes a test setup aimed at eventually ensuring reliable parsing
103
70
 
104
71
  You can run the tests yourself by cloning the repository and running `pnpm test`. To see the coverage report, run `pnpm test:coverage`.
105
72
 
106
- If you find any issue with your own examples of recipes, feel free to open an Issue and if you want to help fix it, to submit a Pull Request.
107
-
108
- ## License
73
+ ## Contributing
109
74
 
110
- MIT
75
+ If you find any issue with your own examples of recipes, feel free to open an Issue and if you want to help fix it, to submit a Pull Request.