@tmlmt/cooklang-parser 1.2.5 → 1.3.0
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 +11 -47
- package/dist/index.cjs +49 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +131 -60
- package/dist/index.d.ts +131 -60
- package/dist/index.js +48 -43
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Represents a recipe section
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* Wrapped as a _Class_ and not defined as a simple _Type_ to expose some useful helper
|
|
5
|
+
* classes (e.g. {@link Section.isBlank | isBlank()})
|
|
6
|
+
*
|
|
5
7
|
* @category Types
|
|
6
8
|
*/
|
|
7
9
|
declare class Section {
|
|
8
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The name of the section. Can be an empty string for the default (first) section.
|
|
12
|
+
* @defaultValue `""`
|
|
13
|
+
*/
|
|
9
14
|
name: string;
|
|
10
15
|
/** An array of steps and notes that make up the content of the section. */
|
|
11
16
|
content: (Step | Note)[];
|
|
@@ -23,37 +28,63 @@ declare class Section {
|
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
/**
|
|
26
|
-
*
|
|
31
|
+
* Recipe parser.
|
|
32
|
+
*
|
|
33
|
+
* ## Usage
|
|
34
|
+
*
|
|
35
|
+
* You can either directly provide the recipe string when creating the instance
|
|
36
|
+
* e.g. `const recipe = new Recipe('Add @eggs{3}')`, or create it first and then pass
|
|
37
|
+
* the recipe string to the {@link Recipe.parse | parse()} method.
|
|
38
|
+
*
|
|
39
|
+
* Look at the [properties](#properties) to see how the recipe's properties are parsed.
|
|
40
|
+
*
|
|
27
41
|
* @category Classes
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { Recipe } from "@tmlmt/cooklang-parser";
|
|
46
|
+
*
|
|
47
|
+
* const recipeString = `
|
|
48
|
+
* ---
|
|
49
|
+
* title: Pancakes
|
|
50
|
+
* tags: [breakfast, easy]
|
|
51
|
+
* ---
|
|
52
|
+
* Crack the @eggs{3} with @flour{100%g} and @milk{200%mL}
|
|
53
|
+
*
|
|
54
|
+
* Melt some @butter{50%g} in a #pan on medium heat.
|
|
55
|
+
*
|
|
56
|
+
* Cook for ~{5%minutes} on each side.
|
|
57
|
+
* `
|
|
58
|
+
* const recipe = new Recipe(recipeString);
|
|
59
|
+
* ```
|
|
28
60
|
*/
|
|
29
61
|
declare class Recipe {
|
|
30
62
|
/**
|
|
31
|
-
* The recipe
|
|
32
|
-
* @see {@link Metadata}
|
|
63
|
+
* The parsed recipe metadata.
|
|
33
64
|
*/
|
|
34
65
|
metadata: Metadata;
|
|
35
66
|
/**
|
|
36
|
-
* The recipe
|
|
37
|
-
* @see {@link Ingredient}
|
|
67
|
+
* The parsed recipe ingredients.
|
|
38
68
|
*/
|
|
39
69
|
ingredients: Ingredient[];
|
|
40
70
|
/**
|
|
41
|
-
* The recipe
|
|
42
|
-
* @see {@link Section}
|
|
71
|
+
* The parsed recipe sections.
|
|
43
72
|
*/
|
|
44
73
|
sections: Section[];
|
|
45
74
|
/**
|
|
46
|
-
* The recipe
|
|
47
|
-
* @see {@link Cookware}
|
|
75
|
+
* The parsed recipe cookware.
|
|
48
76
|
*/
|
|
49
77
|
cookware: Cookware[];
|
|
50
78
|
/**
|
|
51
|
-
* The recipe
|
|
52
|
-
* @see {@link Timer}
|
|
79
|
+
* The parsed recipe timers.
|
|
53
80
|
*/
|
|
54
81
|
timers: Timer[];
|
|
55
82
|
/**
|
|
56
|
-
* The recipe
|
|
83
|
+
* The parsed recipe servings. Used for scaling. Parsed from one of
|
|
84
|
+
* {@link Metadata.servings}, {@link Metadata.yield} or {@link Metadata.serves}
|
|
85
|
+
* metadata fields.
|
|
86
|
+
*
|
|
87
|
+
* @see {@link Recipe.scaleBy | scaleBy()} and {@link Recipe.scaleTo | scaleTo()} methods
|
|
57
88
|
*/
|
|
58
89
|
servings?: number;
|
|
59
90
|
/**
|
|
@@ -67,9 +98,12 @@ declare class Recipe {
|
|
|
67
98
|
*/
|
|
68
99
|
parse(content: string): void;
|
|
69
100
|
/**
|
|
70
|
-
* Scales the recipe to a new number of servings.
|
|
101
|
+
* Scales the recipe to a new number of servings. In practice, it calls
|
|
102
|
+
* {@link Recipe.scaleBy | scaleBy} with a factor corresponding to the ratio between `newServings`
|
|
103
|
+
* and the recipe's {@link Recipe.servings | servings} value.
|
|
71
104
|
* @param newServings - The new number of servings.
|
|
72
105
|
* @returns A new Recipe instance with the scaled ingredients.
|
|
106
|
+
* @throws `Error` if the recipe does not contains an initial {@link Recipe.servings | servings} value
|
|
73
107
|
*/
|
|
74
108
|
scaleTo(newServings: number): Recipe;
|
|
75
109
|
/**
|
|
@@ -112,16 +146,19 @@ interface Metadata {
|
|
|
112
146
|
author?: string;
|
|
113
147
|
/** The number of servings the recipe makes.
|
|
114
148
|
* Complex info can be given, as long as the first part before a comma has a numerical value, which will be used for scaling
|
|
149
|
+
*
|
|
115
150
|
* Interchangeable with `yield` or `serves`. If multiple ones are defined, the latest one will be used for scaling */
|
|
116
151
|
servings?: string;
|
|
117
152
|
/** The yield of the recipe.
|
|
118
|
-
*
|
|
119
|
-
*
|
|
153
|
+
* Complex info can be given, as long as the first part before a comma has a numerical value, which will be used for scaling
|
|
154
|
+
*
|
|
155
|
+
* Interchangeable with `servings` or `serves`. If multiple ones are defined, the latest one will be used for scaling
|
|
120
156
|
*/
|
|
121
157
|
yield?: string;
|
|
122
158
|
/** The number of people the recipe serves.
|
|
123
|
-
*
|
|
124
|
-
*
|
|
159
|
+
* Complex info can be given, as long as the first part before a comma has a numerical value, which will be used for scaling
|
|
160
|
+
*
|
|
161
|
+
* Interchangeable with `servings` or `yield`. If multiple ones are defined, the latest one will be used for scaling
|
|
125
162
|
*/
|
|
126
163
|
serves?: string;
|
|
127
164
|
/** The course of the recipe. */
|
|
@@ -174,16 +211,6 @@ interface Metadata {
|
|
|
174
211
|
/** The introduction of the recipe. */
|
|
175
212
|
introduction?: string;
|
|
176
213
|
}
|
|
177
|
-
/**
|
|
178
|
-
* Represents the extracted metadata from a recipe.
|
|
179
|
-
* @category Types
|
|
180
|
-
*/
|
|
181
|
-
interface MetadataExtract {
|
|
182
|
-
/** The metadata of the recipe. */
|
|
183
|
-
metadata: Metadata;
|
|
184
|
-
/** The number of servings the recipe makes. Used for scaling */
|
|
185
|
-
servings?: number;
|
|
186
|
-
}
|
|
187
214
|
/**
|
|
188
215
|
* Represents a quantity described by text, e.g. "a pinch"
|
|
189
216
|
* @category Types
|
|
@@ -351,7 +378,6 @@ interface Cookware {
|
|
|
351
378
|
* @category Types
|
|
352
379
|
*/
|
|
353
380
|
interface CategorizedIngredients {
|
|
354
|
-
/** The category of the ingredients. */
|
|
355
381
|
[category: string]: Ingredient[];
|
|
356
382
|
}
|
|
357
383
|
/**
|
|
@@ -365,78 +391,122 @@ interface AddedRecipe {
|
|
|
365
391
|
factor: number;
|
|
366
392
|
}
|
|
367
393
|
/**
|
|
368
|
-
* Represents an ingredient in
|
|
394
|
+
* Represents an ingredient in a category.
|
|
369
395
|
* @category Types
|
|
370
396
|
*/
|
|
371
|
-
interface
|
|
397
|
+
interface CategoryIngredient {
|
|
372
398
|
/** The name of the ingredient. */
|
|
373
399
|
name: string;
|
|
374
400
|
/** The aliases of the ingredient. */
|
|
375
401
|
aliases: string[];
|
|
376
402
|
}
|
|
377
403
|
/**
|
|
378
|
-
* Represents a category of
|
|
404
|
+
* Represents a category of ingredients.
|
|
379
405
|
* @category Types
|
|
380
406
|
*/
|
|
381
|
-
interface
|
|
407
|
+
interface Category {
|
|
382
408
|
/** The name of the category. */
|
|
383
409
|
name: string;
|
|
384
410
|
/** The ingredients in the category. */
|
|
385
|
-
ingredients:
|
|
411
|
+
ingredients: CategoryIngredient[];
|
|
386
412
|
}
|
|
387
413
|
|
|
388
414
|
/**
|
|
389
|
-
*
|
|
415
|
+
* Parser for category configurations specified à-la-cooklang.
|
|
416
|
+
*
|
|
417
|
+
* ## Usage
|
|
418
|
+
*
|
|
419
|
+
* You can either directly provide the category configuration string when creating the instance
|
|
420
|
+
* e.g. `const categoryConfig = new CategoryConfig(<...>)`, or create it first and then pass
|
|
421
|
+
* the category configuration string to the {@link CategoryConfig.parse | parse()} method.
|
|
422
|
+
*
|
|
423
|
+
* The initialized `CategoryConfig` can then be fed to a {@link ShoppingList}
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* import { CategoryConfig } from @tmlmt/cooklang-parser;
|
|
428
|
+
*
|
|
429
|
+
* const categoryConfigString = `
|
|
430
|
+
* [Dairy]
|
|
431
|
+
* milk
|
|
432
|
+
* butter
|
|
433
|
+
*
|
|
434
|
+
* [Bakery]
|
|
435
|
+
* flour
|
|
436
|
+
* sugar`;
|
|
437
|
+
*
|
|
438
|
+
* const categoryConfig = new CategoryConfig(categoryConfigString);
|
|
439
|
+
* ```
|
|
440
|
+
*
|
|
441
|
+
* @see [Category Configuration](https://cooklang.org/docs/spec/#shopping-lists) section of the cooklang specs
|
|
442
|
+
*
|
|
390
443
|
* @category Classes
|
|
391
444
|
*/
|
|
392
|
-
declare class
|
|
445
|
+
declare class CategoryConfig {
|
|
393
446
|
/**
|
|
394
|
-
* The categories of
|
|
395
|
-
* @see {@link AisleCategory}
|
|
447
|
+
* The parsed categories of ingredients.
|
|
396
448
|
*/
|
|
397
|
-
categories:
|
|
449
|
+
categories: Category[];
|
|
398
450
|
/**
|
|
399
|
-
* Creates a new
|
|
400
|
-
* @param config - The
|
|
451
|
+
* Creates a new CategoryConfig instance.
|
|
452
|
+
* @param config - The category configuration to parse.
|
|
401
453
|
*/
|
|
402
454
|
constructor(config?: string);
|
|
403
455
|
/**
|
|
404
|
-
* Parses
|
|
405
|
-
*
|
|
456
|
+
* Parses a category configuration from a string into property
|
|
457
|
+
* {@link CategoryConfig.categories | categories}
|
|
458
|
+
* @param config - The category configuration to parse.
|
|
406
459
|
*/
|
|
407
460
|
parse(config: string): void;
|
|
408
461
|
}
|
|
409
462
|
|
|
410
463
|
/**
|
|
411
|
-
*
|
|
464
|
+
* Shopping List generator.
|
|
465
|
+
*
|
|
466
|
+
* ## Usage
|
|
467
|
+
*
|
|
468
|
+
* - Create a new ShoppingList instance with an optional category configuration (see {@link ShoppingList."constructor" | constructor})
|
|
469
|
+
* - Add recipes, scaling them as needed (see {@link ShoppingList.add_recipe | add_recipe()})
|
|
470
|
+
* - Categorize the ingredients (see {@link ShoppingList.categorize | categorize()})
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
*
|
|
474
|
+
* ```typescript
|
|
475
|
+
* import * as fs from "fs";
|
|
476
|
+
* import { ShoppingList } from @tmlmt/cooklang-parser;
|
|
477
|
+
*
|
|
478
|
+
* const categoryConfig = fs.readFileSync("./myconfig.txt", "utf-8")
|
|
479
|
+
* const recipe1 = new Recipe(fs.readFileSync("./myrecipe.cook", "utf-8"));
|
|
480
|
+
* const shoppingList = new ShoppingList();
|
|
481
|
+
* shoppingList.set_category_config(categoryConfig);
|
|
482
|
+
* shoppingList.add_recipe(recipe1);
|
|
483
|
+
* shoppingList.categorize();
|
|
484
|
+
* ```
|
|
485
|
+
*
|
|
412
486
|
* @category Classes
|
|
413
487
|
*/
|
|
414
488
|
declare class ShoppingList {
|
|
415
489
|
/**
|
|
416
490
|
* The ingredients in the shopping list.
|
|
417
|
-
* @see {@link Ingredient}
|
|
418
491
|
*/
|
|
419
492
|
ingredients: Ingredient[];
|
|
420
493
|
/**
|
|
421
494
|
* The recipes in the shopping list.
|
|
422
|
-
* @see {@link AddedRecipe}
|
|
423
495
|
*/
|
|
424
496
|
recipes: AddedRecipe[];
|
|
425
497
|
/**
|
|
426
|
-
* The
|
|
427
|
-
* @see {@link AisleConfig}
|
|
498
|
+
* The category configuration for the shopping list.
|
|
428
499
|
*/
|
|
429
|
-
|
|
500
|
+
category_config?: CategoryConfig;
|
|
430
501
|
/**
|
|
431
502
|
* The categorized ingredients in the shopping list.
|
|
432
|
-
* @see {@link CategorizedIngredients}
|
|
433
503
|
*/
|
|
434
504
|
categories?: CategorizedIngredients;
|
|
435
505
|
/**
|
|
436
|
-
* Creates a new ShoppingList instance
|
|
437
|
-
* @param
|
|
506
|
+
* Creates a new ShoppingList instance
|
|
507
|
+
* @param category_config_str - The category configuration to parse.
|
|
438
508
|
*/
|
|
439
|
-
constructor(
|
|
509
|
+
constructor(category_config_str?: string | CategoryConfig);
|
|
440
510
|
private calculate_ingredients;
|
|
441
511
|
/**
|
|
442
512
|
* Adds a recipe to the shopping list.
|
|
@@ -450,15 +520,16 @@ declare class ShoppingList {
|
|
|
450
520
|
*/
|
|
451
521
|
remove_recipe(index: number): void;
|
|
452
522
|
/**
|
|
453
|
-
* Sets the
|
|
454
|
-
*
|
|
523
|
+
* Sets the category configuration for the shopping list
|
|
524
|
+
* and automatically categorize current ingredients from the list.
|
|
525
|
+
* @param config - The category configuration to parse.
|
|
455
526
|
*/
|
|
456
|
-
|
|
527
|
+
set_category_config(config: string | CategoryConfig): void;
|
|
457
528
|
/**
|
|
458
529
|
* Categorizes the ingredients in the shopping list
|
|
459
|
-
* Will use the
|
|
530
|
+
* Will use the category config if any, otherwise all ingredients will be placed in the "other" category
|
|
460
531
|
*/
|
|
461
532
|
categorize(): void;
|
|
462
533
|
}
|
|
463
534
|
|
|
464
|
-
export { type AddedRecipe, type
|
|
535
|
+
export { type AddedRecipe, type CategorizedIngredients, type Category, CategoryConfig, type CategoryIngredient, type Cookware, type CookwareItem, type DecimalValue, type FixedValue, type FractionValue, type Ingredient, type IngredientItem, type Item, type Metadata, type Note, type Range, Recipe, Section, ShoppingList, type Step, type TextItem, type TextValue, type Timer, type TimerItem };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Represents a recipe section
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* Wrapped as a _Class_ and not defined as a simple _Type_ to expose some useful helper
|
|
5
|
+
* classes (e.g. {@link Section.isBlank | isBlank()})
|
|
6
|
+
*
|
|
5
7
|
* @category Types
|
|
6
8
|
*/
|
|
7
9
|
declare class Section {
|
|
8
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The name of the section. Can be an empty string for the default (first) section.
|
|
12
|
+
* @defaultValue `""`
|
|
13
|
+
*/
|
|
9
14
|
name: string;
|
|
10
15
|
/** An array of steps and notes that make up the content of the section. */
|
|
11
16
|
content: (Step | Note)[];
|
|
@@ -23,37 +28,63 @@ declare class Section {
|
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
/**
|
|
26
|
-
*
|
|
31
|
+
* Recipe parser.
|
|
32
|
+
*
|
|
33
|
+
* ## Usage
|
|
34
|
+
*
|
|
35
|
+
* You can either directly provide the recipe string when creating the instance
|
|
36
|
+
* e.g. `const recipe = new Recipe('Add @eggs{3}')`, or create it first and then pass
|
|
37
|
+
* the recipe string to the {@link Recipe.parse | parse()} method.
|
|
38
|
+
*
|
|
39
|
+
* Look at the [properties](#properties) to see how the recipe's properties are parsed.
|
|
40
|
+
*
|
|
27
41
|
* @category Classes
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { Recipe } from "@tmlmt/cooklang-parser";
|
|
46
|
+
*
|
|
47
|
+
* const recipeString = `
|
|
48
|
+
* ---
|
|
49
|
+
* title: Pancakes
|
|
50
|
+
* tags: [breakfast, easy]
|
|
51
|
+
* ---
|
|
52
|
+
* Crack the @eggs{3} with @flour{100%g} and @milk{200%mL}
|
|
53
|
+
*
|
|
54
|
+
* Melt some @butter{50%g} in a #pan on medium heat.
|
|
55
|
+
*
|
|
56
|
+
* Cook for ~{5%minutes} on each side.
|
|
57
|
+
* `
|
|
58
|
+
* const recipe = new Recipe(recipeString);
|
|
59
|
+
* ```
|
|
28
60
|
*/
|
|
29
61
|
declare class Recipe {
|
|
30
62
|
/**
|
|
31
|
-
* The recipe
|
|
32
|
-
* @see {@link Metadata}
|
|
63
|
+
* The parsed recipe metadata.
|
|
33
64
|
*/
|
|
34
65
|
metadata: Metadata;
|
|
35
66
|
/**
|
|
36
|
-
* The recipe
|
|
37
|
-
* @see {@link Ingredient}
|
|
67
|
+
* The parsed recipe ingredients.
|
|
38
68
|
*/
|
|
39
69
|
ingredients: Ingredient[];
|
|
40
70
|
/**
|
|
41
|
-
* The recipe
|
|
42
|
-
* @see {@link Section}
|
|
71
|
+
* The parsed recipe sections.
|
|
43
72
|
*/
|
|
44
73
|
sections: Section[];
|
|
45
74
|
/**
|
|
46
|
-
* The recipe
|
|
47
|
-
* @see {@link Cookware}
|
|
75
|
+
* The parsed recipe cookware.
|
|
48
76
|
*/
|
|
49
77
|
cookware: Cookware[];
|
|
50
78
|
/**
|
|
51
|
-
* The recipe
|
|
52
|
-
* @see {@link Timer}
|
|
79
|
+
* The parsed recipe timers.
|
|
53
80
|
*/
|
|
54
81
|
timers: Timer[];
|
|
55
82
|
/**
|
|
56
|
-
* The recipe
|
|
83
|
+
* The parsed recipe servings. Used for scaling. Parsed from one of
|
|
84
|
+
* {@link Metadata.servings}, {@link Metadata.yield} or {@link Metadata.serves}
|
|
85
|
+
* metadata fields.
|
|
86
|
+
*
|
|
87
|
+
* @see {@link Recipe.scaleBy | scaleBy()} and {@link Recipe.scaleTo | scaleTo()} methods
|
|
57
88
|
*/
|
|
58
89
|
servings?: number;
|
|
59
90
|
/**
|
|
@@ -67,9 +98,12 @@ declare class Recipe {
|
|
|
67
98
|
*/
|
|
68
99
|
parse(content: string): void;
|
|
69
100
|
/**
|
|
70
|
-
* Scales the recipe to a new number of servings.
|
|
101
|
+
* Scales the recipe to a new number of servings. In practice, it calls
|
|
102
|
+
* {@link Recipe.scaleBy | scaleBy} with a factor corresponding to the ratio between `newServings`
|
|
103
|
+
* and the recipe's {@link Recipe.servings | servings} value.
|
|
71
104
|
* @param newServings - The new number of servings.
|
|
72
105
|
* @returns A new Recipe instance with the scaled ingredients.
|
|
106
|
+
* @throws `Error` if the recipe does not contains an initial {@link Recipe.servings | servings} value
|
|
73
107
|
*/
|
|
74
108
|
scaleTo(newServings: number): Recipe;
|
|
75
109
|
/**
|
|
@@ -112,16 +146,19 @@ interface Metadata {
|
|
|
112
146
|
author?: string;
|
|
113
147
|
/** The number of servings the recipe makes.
|
|
114
148
|
* Complex info can be given, as long as the first part before a comma has a numerical value, which will be used for scaling
|
|
149
|
+
*
|
|
115
150
|
* Interchangeable with `yield` or `serves`. If multiple ones are defined, the latest one will be used for scaling */
|
|
116
151
|
servings?: string;
|
|
117
152
|
/** The yield of the recipe.
|
|
118
|
-
*
|
|
119
|
-
*
|
|
153
|
+
* Complex info can be given, as long as the first part before a comma has a numerical value, which will be used for scaling
|
|
154
|
+
*
|
|
155
|
+
* Interchangeable with `servings` or `serves`. If multiple ones are defined, the latest one will be used for scaling
|
|
120
156
|
*/
|
|
121
157
|
yield?: string;
|
|
122
158
|
/** The number of people the recipe serves.
|
|
123
|
-
*
|
|
124
|
-
*
|
|
159
|
+
* Complex info can be given, as long as the first part before a comma has a numerical value, which will be used for scaling
|
|
160
|
+
*
|
|
161
|
+
* Interchangeable with `servings` or `yield`. If multiple ones are defined, the latest one will be used for scaling
|
|
125
162
|
*/
|
|
126
163
|
serves?: string;
|
|
127
164
|
/** The course of the recipe. */
|
|
@@ -174,16 +211,6 @@ interface Metadata {
|
|
|
174
211
|
/** The introduction of the recipe. */
|
|
175
212
|
introduction?: string;
|
|
176
213
|
}
|
|
177
|
-
/**
|
|
178
|
-
* Represents the extracted metadata from a recipe.
|
|
179
|
-
* @category Types
|
|
180
|
-
*/
|
|
181
|
-
interface MetadataExtract {
|
|
182
|
-
/** The metadata of the recipe. */
|
|
183
|
-
metadata: Metadata;
|
|
184
|
-
/** The number of servings the recipe makes. Used for scaling */
|
|
185
|
-
servings?: number;
|
|
186
|
-
}
|
|
187
214
|
/**
|
|
188
215
|
* Represents a quantity described by text, e.g. "a pinch"
|
|
189
216
|
* @category Types
|
|
@@ -351,7 +378,6 @@ interface Cookware {
|
|
|
351
378
|
* @category Types
|
|
352
379
|
*/
|
|
353
380
|
interface CategorizedIngredients {
|
|
354
|
-
/** The category of the ingredients. */
|
|
355
381
|
[category: string]: Ingredient[];
|
|
356
382
|
}
|
|
357
383
|
/**
|
|
@@ -365,78 +391,122 @@ interface AddedRecipe {
|
|
|
365
391
|
factor: number;
|
|
366
392
|
}
|
|
367
393
|
/**
|
|
368
|
-
* Represents an ingredient in
|
|
394
|
+
* Represents an ingredient in a category.
|
|
369
395
|
* @category Types
|
|
370
396
|
*/
|
|
371
|
-
interface
|
|
397
|
+
interface CategoryIngredient {
|
|
372
398
|
/** The name of the ingredient. */
|
|
373
399
|
name: string;
|
|
374
400
|
/** The aliases of the ingredient. */
|
|
375
401
|
aliases: string[];
|
|
376
402
|
}
|
|
377
403
|
/**
|
|
378
|
-
* Represents a category of
|
|
404
|
+
* Represents a category of ingredients.
|
|
379
405
|
* @category Types
|
|
380
406
|
*/
|
|
381
|
-
interface
|
|
407
|
+
interface Category {
|
|
382
408
|
/** The name of the category. */
|
|
383
409
|
name: string;
|
|
384
410
|
/** The ingredients in the category. */
|
|
385
|
-
ingredients:
|
|
411
|
+
ingredients: CategoryIngredient[];
|
|
386
412
|
}
|
|
387
413
|
|
|
388
414
|
/**
|
|
389
|
-
*
|
|
415
|
+
* Parser for category configurations specified à-la-cooklang.
|
|
416
|
+
*
|
|
417
|
+
* ## Usage
|
|
418
|
+
*
|
|
419
|
+
* You can either directly provide the category configuration string when creating the instance
|
|
420
|
+
* e.g. `const categoryConfig = new CategoryConfig(<...>)`, or create it first and then pass
|
|
421
|
+
* the category configuration string to the {@link CategoryConfig.parse | parse()} method.
|
|
422
|
+
*
|
|
423
|
+
* The initialized `CategoryConfig` can then be fed to a {@link ShoppingList}
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* import { CategoryConfig } from @tmlmt/cooklang-parser;
|
|
428
|
+
*
|
|
429
|
+
* const categoryConfigString = `
|
|
430
|
+
* [Dairy]
|
|
431
|
+
* milk
|
|
432
|
+
* butter
|
|
433
|
+
*
|
|
434
|
+
* [Bakery]
|
|
435
|
+
* flour
|
|
436
|
+
* sugar`;
|
|
437
|
+
*
|
|
438
|
+
* const categoryConfig = new CategoryConfig(categoryConfigString);
|
|
439
|
+
* ```
|
|
440
|
+
*
|
|
441
|
+
* @see [Category Configuration](https://cooklang.org/docs/spec/#shopping-lists) section of the cooklang specs
|
|
442
|
+
*
|
|
390
443
|
* @category Classes
|
|
391
444
|
*/
|
|
392
|
-
declare class
|
|
445
|
+
declare class CategoryConfig {
|
|
393
446
|
/**
|
|
394
|
-
* The categories of
|
|
395
|
-
* @see {@link AisleCategory}
|
|
447
|
+
* The parsed categories of ingredients.
|
|
396
448
|
*/
|
|
397
|
-
categories:
|
|
449
|
+
categories: Category[];
|
|
398
450
|
/**
|
|
399
|
-
* Creates a new
|
|
400
|
-
* @param config - The
|
|
451
|
+
* Creates a new CategoryConfig instance.
|
|
452
|
+
* @param config - The category configuration to parse.
|
|
401
453
|
*/
|
|
402
454
|
constructor(config?: string);
|
|
403
455
|
/**
|
|
404
|
-
* Parses
|
|
405
|
-
*
|
|
456
|
+
* Parses a category configuration from a string into property
|
|
457
|
+
* {@link CategoryConfig.categories | categories}
|
|
458
|
+
* @param config - The category configuration to parse.
|
|
406
459
|
*/
|
|
407
460
|
parse(config: string): void;
|
|
408
461
|
}
|
|
409
462
|
|
|
410
463
|
/**
|
|
411
|
-
*
|
|
464
|
+
* Shopping List generator.
|
|
465
|
+
*
|
|
466
|
+
* ## Usage
|
|
467
|
+
*
|
|
468
|
+
* - Create a new ShoppingList instance with an optional category configuration (see {@link ShoppingList."constructor" | constructor})
|
|
469
|
+
* - Add recipes, scaling them as needed (see {@link ShoppingList.add_recipe | add_recipe()})
|
|
470
|
+
* - Categorize the ingredients (see {@link ShoppingList.categorize | categorize()})
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
*
|
|
474
|
+
* ```typescript
|
|
475
|
+
* import * as fs from "fs";
|
|
476
|
+
* import { ShoppingList } from @tmlmt/cooklang-parser;
|
|
477
|
+
*
|
|
478
|
+
* const categoryConfig = fs.readFileSync("./myconfig.txt", "utf-8")
|
|
479
|
+
* const recipe1 = new Recipe(fs.readFileSync("./myrecipe.cook", "utf-8"));
|
|
480
|
+
* const shoppingList = new ShoppingList();
|
|
481
|
+
* shoppingList.set_category_config(categoryConfig);
|
|
482
|
+
* shoppingList.add_recipe(recipe1);
|
|
483
|
+
* shoppingList.categorize();
|
|
484
|
+
* ```
|
|
485
|
+
*
|
|
412
486
|
* @category Classes
|
|
413
487
|
*/
|
|
414
488
|
declare class ShoppingList {
|
|
415
489
|
/**
|
|
416
490
|
* The ingredients in the shopping list.
|
|
417
|
-
* @see {@link Ingredient}
|
|
418
491
|
*/
|
|
419
492
|
ingredients: Ingredient[];
|
|
420
493
|
/**
|
|
421
494
|
* The recipes in the shopping list.
|
|
422
|
-
* @see {@link AddedRecipe}
|
|
423
495
|
*/
|
|
424
496
|
recipes: AddedRecipe[];
|
|
425
497
|
/**
|
|
426
|
-
* The
|
|
427
|
-
* @see {@link AisleConfig}
|
|
498
|
+
* The category configuration for the shopping list.
|
|
428
499
|
*/
|
|
429
|
-
|
|
500
|
+
category_config?: CategoryConfig;
|
|
430
501
|
/**
|
|
431
502
|
* The categorized ingredients in the shopping list.
|
|
432
|
-
* @see {@link CategorizedIngredients}
|
|
433
503
|
*/
|
|
434
504
|
categories?: CategorizedIngredients;
|
|
435
505
|
/**
|
|
436
|
-
* Creates a new ShoppingList instance
|
|
437
|
-
* @param
|
|
506
|
+
* Creates a new ShoppingList instance
|
|
507
|
+
* @param category_config_str - The category configuration to parse.
|
|
438
508
|
*/
|
|
439
|
-
constructor(
|
|
509
|
+
constructor(category_config_str?: string | CategoryConfig);
|
|
440
510
|
private calculate_ingredients;
|
|
441
511
|
/**
|
|
442
512
|
* Adds a recipe to the shopping list.
|
|
@@ -450,15 +520,16 @@ declare class ShoppingList {
|
|
|
450
520
|
*/
|
|
451
521
|
remove_recipe(index: number): void;
|
|
452
522
|
/**
|
|
453
|
-
* Sets the
|
|
454
|
-
*
|
|
523
|
+
* Sets the category configuration for the shopping list
|
|
524
|
+
* and automatically categorize current ingredients from the list.
|
|
525
|
+
* @param config - The category configuration to parse.
|
|
455
526
|
*/
|
|
456
|
-
|
|
527
|
+
set_category_config(config: string | CategoryConfig): void;
|
|
457
528
|
/**
|
|
458
529
|
* Categorizes the ingredients in the shopping list
|
|
459
|
-
* Will use the
|
|
530
|
+
* Will use the category config if any, otherwise all ingredients will be placed in the "other" category
|
|
460
531
|
*/
|
|
461
532
|
categorize(): void;
|
|
462
533
|
}
|
|
463
534
|
|
|
464
|
-
export { type AddedRecipe, type
|
|
535
|
+
export { type AddedRecipe, type CategorizedIngredients, type Category, CategoryConfig, type CategoryIngredient, type Cookware, type CookwareItem, type DecimalValue, type FixedValue, type FractionValue, type Ingredient, type IngredientItem, type Item, type Metadata, type Note, type Range, Recipe, Section, ShoppingList, type Step, type TextItem, type TextValue, type Timer, type TimerItem };
|