@tmlmt/cooklang-parser 1.4.4 → 2.0.1

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/dist/index.d.cts CHANGED
@@ -125,6 +125,11 @@ declare class Recipe {
125
125
  clone(): Recipe;
126
126
  }
127
127
 
128
+ interface Quantity {
129
+ value: FixedValue | Range;
130
+ unit?: string;
131
+ }
132
+
128
133
  /**
129
134
  * Represents the metadata of a recipe.
130
135
  * @category Types
@@ -145,22 +150,47 @@ interface Metadata {
145
150
  /** The author of the recipe. */
146
151
  author?: string;
147
152
  /** The number of servings the recipe makes.
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
153
+ * Should be either a number or a string which starts with a number
154
+ * (which will be used for scaling) followed by a comma and then
155
+ * whatever you want.
156
+ *
157
+ * Interchangeable with `yield` or `serves`. If multiple ones are defined,
158
+ * the prevailance order for the number which will used for scaling
159
+ * is `servings` \> `yield` \> `serves`.
149
160
  *
150
- * Interchangeable with `yield` or `serves`. If multiple ones are defined, the latest one will be used for scaling */
151
- servings?: string;
161
+ * @example
162
+ * ```yaml
163
+ * servings: 4
164
+ * ```
165
+ *
166
+ * @example
167
+ * ```yaml
168
+ * servings: 2, a few
169
+ * ```
170
+ */
171
+ servings?: number | string;
152
172
  /** The yield of the recipe.
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
173
+ * Should be either a number or a string which starts with a number
174
+ * (which will be used for scaling) followed by a comma and then
175
+ * whatever you want.
154
176
  *
155
- * Interchangeable with `servings` or `serves`. If multiple ones are defined, the latest one will be used for scaling
177
+ * Interchangeable with `servings` or `serves`. If multiple ones are defined,
178
+ * the prevailance order for the number which will used for scaling
179
+ * is `servings` \> `yield` \> `serves`. See {@link Metadata.servings | servings}
180
+ * for examples.
156
181
  */
157
- yield?: string;
182
+ yield?: number | string;
158
183
  /** The number of people the recipe serves.
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
184
+ * Should be either a number or a string which starts with a number
185
+ * (which will be used for scaling) followed by a comma and then
186
+ * whatever you want.
160
187
  *
161
- * Interchangeable with `servings` or `yield`. If multiple ones are defined, the latest one will be used for scaling
188
+ * Interchangeable with `servings` or `yield`. If multiple ones are defined,
189
+ * the prevailance order for the number which will used for scaling
190
+ * is `servings` \> `yield` \> `serves`. See {@link Metadata.servings | servings}
191
+ * for examples.
162
192
  */
163
- serves?: string;
193
+ serves?: number | string;
164
194
  /** The course of the recipe. */
165
195
  course?: string;
166
196
  /** The category of the recipe. */
@@ -256,6 +286,41 @@ interface Range {
256
286
  min: DecimalValue | FractionValue;
257
287
  max: DecimalValue | FractionValue;
258
288
  }
289
+ /**
290
+ * Represents a contributor to an ingredient's total quantity
291
+ * @category Types
292
+ */
293
+ interface QuantityPart extends Quantity {
294
+ /** - If _true_, the quantity will scale
295
+ * - If _false_, the quantity is fixed
296
+ */
297
+ scalable: boolean;
298
+ }
299
+ /**
300
+ * Represents a possible state modifier or other flag for an ingredient in a recipe
301
+ * @category Types
302
+ */
303
+ type IngredientFlag = "optional" | "hidden" | "recipe";
304
+ /**
305
+ * Represents the collection of possible additional metadata for an ingredient in a recipe
306
+ * @category Types
307
+ */
308
+ interface IngredientExtras {
309
+ /**
310
+ * The path of the ingredient-recipe, relative to the present recipe
311
+ * Used if: the ingredient is a recipe
312
+ *
313
+ * @example
314
+ * ```cooklang
315
+ * Take @./essentials/doughs/pizza dough{1} out of the freezer and let it unfreeze overnight
316
+ * ```
317
+ * Would lead to:
318
+ * ```yaml
319
+ * path: 'essentials/doughts/pizza dough.cook'
320
+ * ```
321
+ */
322
+ path: string;
323
+ }
259
324
  /**
260
325
  * Represents an ingredient in a recipe.
261
326
  * @category Types
@@ -267,14 +332,14 @@ interface Ingredient {
267
332
  quantity?: FixedValue | Range;
268
333
  /** The unit of the ingredient. */
269
334
  unit?: string;
335
+ /** The array of contributors to the ingredient's total quantity. */
336
+ quantityParts?: QuantityPart[];
270
337
  /** The preparation of the ingredient. */
271
338
  preparation?: string;
272
- /** Whether the ingredient is optional. */
273
- optional?: boolean;
274
- /** Whether the ingredient is hidden. */
275
- hidden?: boolean;
276
- /** Whether the ingredient is a recipe. */
277
- isRecipe?: boolean;
339
+ /** A list of potential state modifiers or other flags for the ingredient */
340
+ flags?: IngredientFlag[];
341
+ /** The collection of potential additional metadata for the ingredient */
342
+ extras?: IngredientExtras;
278
343
  }
279
344
  /**
280
345
  * Represents a timer in a recipe.
@@ -295,7 +360,7 @@ interface Timer {
295
360
  interface TextItem {
296
361
  /** The type of the item. */
297
362
  type: "text";
298
- /** The value of the item. */
363
+ /** The content of the text item. */
299
364
  value: string;
300
365
  }
301
366
  /**
@@ -305,14 +370,14 @@ interface TextItem {
305
370
  interface IngredientItem {
306
371
  /** The type of the item. */
307
372
  type: "ingredient";
308
- /** The value of the item. */
309
- value: number;
310
- /** The alias/name of the ingredient as it should be displayed in the preparation */
373
+ /** The index of the ingredient, within the {@link Recipe.ingredients | list of ingredients} */
374
+ index: number;
375
+ /** Index of the quantity part corresponding to this item / this occurence
376
+ * of the ingredient, which may be referenced elsewhere. */
377
+ quantityPartIndex?: number;
378
+ /** The alias/name of the ingredient as it should be displayed in the preparation
379
+ * for this occurence */
311
380
  displayName: string;
312
- /** Quantity specific to this step item for this ingredient which may also be referenced elsewhere */
313
- itemQuantity?: FixedValue | Range;
314
- /** Unit specific to this step item for this ingredient which may also be referenced elsewhere */
315
- itemUnit?: string;
316
381
  }
317
382
  /**
318
383
  * Represents a cookware item in a recipe step.
@@ -321,10 +386,11 @@ interface IngredientItem {
321
386
  interface CookwareItem {
322
387
  /** The type of the item. */
323
388
  type: "cookware";
324
- /** The value of the item. */
325
- value: number;
326
- /** Quantity specific to this step item for this cookware which may also be referenced elsewhere */
327
- itemQuantity?: FixedValue | Range;
389
+ /** The index of the cookware, within the {@link Recipe.cookware | list of cookware} */
390
+ index: number;
391
+ /** Index of the quantity part corresponding to this item / this occurence
392
+ * of the cookware, which may be referenced elsewhere. */
393
+ quantityPartIndex?: number;
328
394
  }
329
395
  /**
330
396
  * Represents a timer item in a recipe step.
@@ -333,8 +399,8 @@ interface CookwareItem {
333
399
  interface TimerItem {
334
400
  /** The type of the item. */
335
401
  type: "timer";
336
- /** The value of the item. */
337
- value: number;
402
+ /** The index of the timer, within the {@link Recipe.timers | list of timers} */
403
+ index: number;
338
404
  }
339
405
  /**
340
406
  * Represents an item in a recipe step.
@@ -359,6 +425,11 @@ interface Note {
359
425
  /** The content of the note. */
360
426
  note: string;
361
427
  }
428
+ /**
429
+ * Represents a possible state modifier or other flag for cookware used in a recipe
430
+ * @category Types
431
+ */
432
+ type CookwareFlag = "optional" | "hidden";
362
433
  /**
363
434
  * Represents a piece of cookware in a recipe.
364
435
  * @category Types
@@ -368,10 +439,10 @@ interface Cookware {
368
439
  name: string;
369
440
  /** The quantity of cookware */
370
441
  quantity?: FixedValue | Range;
371
- /** Whether the cookware is optional. */
372
- optional?: boolean;
373
- /** Whether the cookware is hidden. */
374
- hidden?: boolean;
442
+ /** The array of contributors to the cookware's total quantity. */
443
+ quantityParts?: (FixedValue | Range)[];
444
+ /** A list of potential state modifiers or other flags for the cookware */
445
+ flags: CookwareFlag[];
375
446
  }
376
447
  /**
377
448
  * Represents categorized ingredients.
@@ -535,4 +606,4 @@ declare class ShoppingList {
535
606
  categorize(): void;
536
607
  }
537
608
 
538
- 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 };
609
+ export { type AddedRecipe, type CategorizedIngredients, type Category, CategoryConfig, type CategoryIngredient, type Cookware, type CookwareFlag, type CookwareItem, type DecimalValue, type FixedValue, type FractionValue, type Ingredient, type IngredientExtras, type IngredientFlag, type IngredientItem, type Item, type Metadata, type Note, type QuantityPart, type Range, Recipe, Section, ShoppingList, type Step, type TextItem, type TextValue, type Timer, type TimerItem };
package/dist/index.d.ts CHANGED
@@ -125,6 +125,11 @@ declare class Recipe {
125
125
  clone(): Recipe;
126
126
  }
127
127
 
128
+ interface Quantity {
129
+ value: FixedValue | Range;
130
+ unit?: string;
131
+ }
132
+
128
133
  /**
129
134
  * Represents the metadata of a recipe.
130
135
  * @category Types
@@ -145,22 +150,47 @@ interface Metadata {
145
150
  /** The author of the recipe. */
146
151
  author?: string;
147
152
  /** The number of servings the recipe makes.
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
153
+ * Should be either a number or a string which starts with a number
154
+ * (which will be used for scaling) followed by a comma and then
155
+ * whatever you want.
156
+ *
157
+ * Interchangeable with `yield` or `serves`. If multiple ones are defined,
158
+ * the prevailance order for the number which will used for scaling
159
+ * is `servings` \> `yield` \> `serves`.
149
160
  *
150
- * Interchangeable with `yield` or `serves`. If multiple ones are defined, the latest one will be used for scaling */
151
- servings?: string;
161
+ * @example
162
+ * ```yaml
163
+ * servings: 4
164
+ * ```
165
+ *
166
+ * @example
167
+ * ```yaml
168
+ * servings: 2, a few
169
+ * ```
170
+ */
171
+ servings?: number | string;
152
172
  /** The yield of the recipe.
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
173
+ * Should be either a number or a string which starts with a number
174
+ * (which will be used for scaling) followed by a comma and then
175
+ * whatever you want.
154
176
  *
155
- * Interchangeable with `servings` or `serves`. If multiple ones are defined, the latest one will be used for scaling
177
+ * Interchangeable with `servings` or `serves`. If multiple ones are defined,
178
+ * the prevailance order for the number which will used for scaling
179
+ * is `servings` \> `yield` \> `serves`. See {@link Metadata.servings | servings}
180
+ * for examples.
156
181
  */
157
- yield?: string;
182
+ yield?: number | string;
158
183
  /** The number of people the recipe serves.
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
184
+ * Should be either a number or a string which starts with a number
185
+ * (which will be used for scaling) followed by a comma and then
186
+ * whatever you want.
160
187
  *
161
- * Interchangeable with `servings` or `yield`. If multiple ones are defined, the latest one will be used for scaling
188
+ * Interchangeable with `servings` or `yield`. If multiple ones are defined,
189
+ * the prevailance order for the number which will used for scaling
190
+ * is `servings` \> `yield` \> `serves`. See {@link Metadata.servings | servings}
191
+ * for examples.
162
192
  */
163
- serves?: string;
193
+ serves?: number | string;
164
194
  /** The course of the recipe. */
165
195
  course?: string;
166
196
  /** The category of the recipe. */
@@ -256,6 +286,41 @@ interface Range {
256
286
  min: DecimalValue | FractionValue;
257
287
  max: DecimalValue | FractionValue;
258
288
  }
289
+ /**
290
+ * Represents a contributor to an ingredient's total quantity
291
+ * @category Types
292
+ */
293
+ interface QuantityPart extends Quantity {
294
+ /** - If _true_, the quantity will scale
295
+ * - If _false_, the quantity is fixed
296
+ */
297
+ scalable: boolean;
298
+ }
299
+ /**
300
+ * Represents a possible state modifier or other flag for an ingredient in a recipe
301
+ * @category Types
302
+ */
303
+ type IngredientFlag = "optional" | "hidden" | "recipe";
304
+ /**
305
+ * Represents the collection of possible additional metadata for an ingredient in a recipe
306
+ * @category Types
307
+ */
308
+ interface IngredientExtras {
309
+ /**
310
+ * The path of the ingredient-recipe, relative to the present recipe
311
+ * Used if: the ingredient is a recipe
312
+ *
313
+ * @example
314
+ * ```cooklang
315
+ * Take @./essentials/doughs/pizza dough{1} out of the freezer and let it unfreeze overnight
316
+ * ```
317
+ * Would lead to:
318
+ * ```yaml
319
+ * path: 'essentials/doughts/pizza dough.cook'
320
+ * ```
321
+ */
322
+ path: string;
323
+ }
259
324
  /**
260
325
  * Represents an ingredient in a recipe.
261
326
  * @category Types
@@ -267,14 +332,14 @@ interface Ingredient {
267
332
  quantity?: FixedValue | Range;
268
333
  /** The unit of the ingredient. */
269
334
  unit?: string;
335
+ /** The array of contributors to the ingredient's total quantity. */
336
+ quantityParts?: QuantityPart[];
270
337
  /** The preparation of the ingredient. */
271
338
  preparation?: string;
272
- /** Whether the ingredient is optional. */
273
- optional?: boolean;
274
- /** Whether the ingredient is hidden. */
275
- hidden?: boolean;
276
- /** Whether the ingredient is a recipe. */
277
- isRecipe?: boolean;
339
+ /** A list of potential state modifiers or other flags for the ingredient */
340
+ flags?: IngredientFlag[];
341
+ /** The collection of potential additional metadata for the ingredient */
342
+ extras?: IngredientExtras;
278
343
  }
279
344
  /**
280
345
  * Represents a timer in a recipe.
@@ -295,7 +360,7 @@ interface Timer {
295
360
  interface TextItem {
296
361
  /** The type of the item. */
297
362
  type: "text";
298
- /** The value of the item. */
363
+ /** The content of the text item. */
299
364
  value: string;
300
365
  }
301
366
  /**
@@ -305,14 +370,14 @@ interface TextItem {
305
370
  interface IngredientItem {
306
371
  /** The type of the item. */
307
372
  type: "ingredient";
308
- /** The value of the item. */
309
- value: number;
310
- /** The alias/name of the ingredient as it should be displayed in the preparation */
373
+ /** The index of the ingredient, within the {@link Recipe.ingredients | list of ingredients} */
374
+ index: number;
375
+ /** Index of the quantity part corresponding to this item / this occurence
376
+ * of the ingredient, which may be referenced elsewhere. */
377
+ quantityPartIndex?: number;
378
+ /** The alias/name of the ingredient as it should be displayed in the preparation
379
+ * for this occurence */
311
380
  displayName: string;
312
- /** Quantity specific to this step item for this ingredient which may also be referenced elsewhere */
313
- itemQuantity?: FixedValue | Range;
314
- /** Unit specific to this step item for this ingredient which may also be referenced elsewhere */
315
- itemUnit?: string;
316
381
  }
317
382
  /**
318
383
  * Represents a cookware item in a recipe step.
@@ -321,10 +386,11 @@ interface IngredientItem {
321
386
  interface CookwareItem {
322
387
  /** The type of the item. */
323
388
  type: "cookware";
324
- /** The value of the item. */
325
- value: number;
326
- /** Quantity specific to this step item for this cookware which may also be referenced elsewhere */
327
- itemQuantity?: FixedValue | Range;
389
+ /** The index of the cookware, within the {@link Recipe.cookware | list of cookware} */
390
+ index: number;
391
+ /** Index of the quantity part corresponding to this item / this occurence
392
+ * of the cookware, which may be referenced elsewhere. */
393
+ quantityPartIndex?: number;
328
394
  }
329
395
  /**
330
396
  * Represents a timer item in a recipe step.
@@ -333,8 +399,8 @@ interface CookwareItem {
333
399
  interface TimerItem {
334
400
  /** The type of the item. */
335
401
  type: "timer";
336
- /** The value of the item. */
337
- value: number;
402
+ /** The index of the timer, within the {@link Recipe.timers | list of timers} */
403
+ index: number;
338
404
  }
339
405
  /**
340
406
  * Represents an item in a recipe step.
@@ -359,6 +425,11 @@ interface Note {
359
425
  /** The content of the note. */
360
426
  note: string;
361
427
  }
428
+ /**
429
+ * Represents a possible state modifier or other flag for cookware used in a recipe
430
+ * @category Types
431
+ */
432
+ type CookwareFlag = "optional" | "hidden";
362
433
  /**
363
434
  * Represents a piece of cookware in a recipe.
364
435
  * @category Types
@@ -368,10 +439,10 @@ interface Cookware {
368
439
  name: string;
369
440
  /** The quantity of cookware */
370
441
  quantity?: FixedValue | Range;
371
- /** Whether the cookware is optional. */
372
- optional?: boolean;
373
- /** Whether the cookware is hidden. */
374
- hidden?: boolean;
442
+ /** The array of contributors to the cookware's total quantity. */
443
+ quantityParts?: (FixedValue | Range)[];
444
+ /** A list of potential state modifiers or other flags for the cookware */
445
+ flags: CookwareFlag[];
375
446
  }
376
447
  /**
377
448
  * Represents categorized ingredients.
@@ -535,4 +606,4 @@ declare class ShoppingList {
535
606
  categorize(): void;
536
607
  }
537
608
 
538
- 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 };
609
+ export { type AddedRecipe, type CategorizedIngredients, type Category, CategoryConfig, type CategoryIngredient, type Cookware, type CookwareFlag, type CookwareItem, type DecimalValue, type FixedValue, type FractionValue, type Ingredient, type IngredientExtras, type IngredientFlag, type IngredientItem, type Item, type Metadata, type Note, type QuantityPart, type Range, Recipe, Section, ShoppingList, type Step, type TextItem, type TextValue, type Timer, type TimerItem };