@tmlmt/cooklang-parser 1.0.8 → 1.2.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.ts CHANGED
@@ -1,7 +1,24 @@
1
+ /**
2
+ * Represents a recipe section
3
+ * Wrapped as a Class and not as a simple type to expose some useful helper
4
+ * classes (e.g. `isBlank()`)
5
+ * @category Types
6
+ */
1
7
  declare class Section {
8
+ /** The name of the section. Can be an empty string for the default (first) section. */
2
9
  name: string;
10
+ /** An array of steps and notes that make up the content of the section. */
3
11
  content: (Step | Note)[];
12
+ /**
13
+ * Creates an instance of Section.
14
+ * @param name - The name of the section. Defaults to an empty string.
15
+ */
4
16
  constructor(name?: string);
17
+ /**
18
+ * Checks if the section is blank (has no name and no content).
19
+ * Used during recipe parsing
20
+ * @returns `true` if the section is blank, otherwise `false`.
21
+ */
5
22
  isBlank(): boolean;
6
23
  }
7
24
 
@@ -61,6 +78,11 @@ declare class Recipe {
61
78
  * @returns A new Recipe instance with the scaled ingredients.
62
79
  */
63
80
  scaleBy(factor: number): Recipe;
81
+ /**
82
+ * Gets the number of servings for the recipe.
83
+ * @private
84
+ * @returns The number of servings, or undefined if not set.
85
+ */
64
86
  private getServings;
65
87
  /**
66
88
  * Clones the recipe.
@@ -146,6 +168,51 @@ interface MetadataExtract {
146
168
  /** The number of servings the recipe makes. Used for scaling */
147
169
  servings?: number;
148
170
  }
171
+ /**
172
+ * Represents a quantity described by text, e.g. "a pinch"
173
+ * @category Types
174
+ */
175
+ interface TextValue {
176
+ type: "text";
177
+ value: string;
178
+ }
179
+ /**
180
+ * Represents a quantity described by a decimal number, e.g. "1.5"
181
+ * @category Types
182
+ */
183
+ interface DecimalValue {
184
+ type: "decimal";
185
+ value: number;
186
+ }
187
+ /**
188
+ * Represents a quantity described by a fraction, e.g. "1/2"
189
+ * @category Types
190
+ */
191
+ interface FractionValue {
192
+ type: "fraction";
193
+ /** The numerator of the fraction */
194
+ num: number;
195
+ /** The denominator of the fraction */
196
+ den: number;
197
+ }
198
+ /**
199
+ * Represents a single, fixed quantity.
200
+ * This can be a text, decimal, or fraction.
201
+ * @category Types
202
+ */
203
+ interface FixedValue {
204
+ type: "fixed";
205
+ value: TextValue | DecimalValue | FractionValue;
206
+ }
207
+ /**
208
+ * Represents a range of quantities, e.g. "1-2"
209
+ * @category Types
210
+ */
211
+ interface Range {
212
+ type: "range";
213
+ min: DecimalValue | FractionValue;
214
+ max: DecimalValue | FractionValue;
215
+ }
149
216
  /**
150
217
  * Represents an ingredient in a recipe.
151
218
  * @category Types
@@ -154,7 +221,7 @@ interface Ingredient {
154
221
  /** The name of the ingredient. */
155
222
  name: string;
156
223
  /** The quantity of the ingredient. */
157
- quantity?: number | string;
224
+ quantity?: FixedValue | Range;
158
225
  /** The unit of the ingredient. */
159
226
  unit?: string;
160
227
  /** The preparation of the ingredient. */
@@ -174,7 +241,7 @@ interface Timer {
174
241
  /** The name of the timer. */
175
242
  name?: string;
176
243
  /** The duration of the timer. */
177
- duration: number;
244
+ duration: FixedValue | Range;
178
245
  /** The unit of the timer. */
179
246
  unit: string;
180
247
  }
@@ -197,12 +264,12 @@ interface IngredientItem {
197
264
  type: "ingredient";
198
265
  /** The value of the item. */
199
266
  value: number;
200
- /** If this is a referenced ingredient, quantity specific to this instance */
201
- partialQuantity?: number | string;
202
- /** If this is a referenced ingredient, unit specific to this instance */
203
- partialUnit?: string;
204
- /** If this is a referenced ingredient, preparation specific to this instance */
205
- partialPreparation?: string;
267
+ /** The alias/name of the ingredient as it should be displayed in the preparation */
268
+ displayName: string;
269
+ /** Quantity specific to this step item for this ingredient which may also be referenced elsewhere */
270
+ itemQuantity?: FixedValue | Range;
271
+ /** Unit specific to this step item for this ingredient which may also be referenced elsewhere */
272
+ itemUnit?: string;
206
273
  }
207
274
  /**
208
275
  * Represents a cookware item in a recipe step.
@@ -213,6 +280,8 @@ interface CookwareItem {
213
280
  type: "cookware";
214
281
  /** The value of the item. */
215
282
  value: number;
283
+ /** Quantity specific to this step item for this cookware which may also be referenced elsewhere */
284
+ itemQuantity?: FixedValue | Range;
216
285
  }
217
286
  /**
218
287
  * Represents a timer item in a recipe step.
@@ -234,6 +303,7 @@ type Item = TextItem | IngredientItem | CookwareItem | TimerItem;
234
303
  * @category Types
235
304
  */
236
305
  interface Step {
306
+ type: "step";
237
307
  /** The items in the step. */
238
308
  items: Item[];
239
309
  }
@@ -242,6 +312,7 @@ interface Step {
242
312
  * @category Types
243
313
  */
244
314
  interface Note {
315
+ type: "note";
245
316
  /** The content of the note. */
246
317
  note: string;
247
318
  }
@@ -252,6 +323,8 @@ interface Note {
252
323
  interface Cookware {
253
324
  /** The name of the cookware. */
254
325
  name: string;
326
+ /** The quantity of cookware */
327
+ quantity?: FixedValue | Range;
255
328
  /** Whether the cookware is optional. */
256
329
  optional?: boolean;
257
330
  /** Whether the cookware is hidden. */
@@ -372,4 +445,4 @@ declare class ShoppingList {
372
445
  categorize(): void;
373
446
  }
374
447
 
375
- export { type AddedRecipe, type AisleCategory, AisleConfig, type AisleIngredient, type CategorizedIngredients, type Cookware, type CookwareItem, type Ingredient, type IngredientItem, type Item, type Metadata, type MetadataExtract, type Note, Recipe, ShoppingList, type Step, type TextItem, type Timer, type TimerItem };
448
+ export { type AddedRecipe, type AisleCategory, AisleConfig, type AisleIngredient, type CategorizedIngredients, type Cookware, type CookwareItem, type DecimalValue, type FixedValue, type FractionValue, type Ingredient, type IngredientItem, type Item, type Metadata, type MetadataExtract, type Note, type Range, Recipe, Section, ShoppingList, type Step, type TextItem, type TextValue, type Timer, type TimerItem };