@tmlmt/cooklang-parser 3.0.0-alpha.19 → 3.0.0-alpha.20

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
@@ -299,16 +299,17 @@ interface MetadataSource {
299
299
  author?: string;
300
300
  }
301
301
  /**
302
- * Represents scaling variable information for a recipe.
302
+ * Represents a yield metadata value for a recipe.
303
+ * Supports plain quantities (e.g. `yield: 300%g`), complex format with
304
+ * surrounding text (e.g. `yield: about {{300%g}} of bread`), or simple
305
+ * numbers (e.g. `yield: 2`).
303
306
  * @category Types
304
307
  */
305
- interface MetadataScalingVar extends QuantityWithPlainUnit {
306
- /** The text before the scaling variable. */
308
+ interface Yield extends QuantityWithPlainUnit {
309
+ /** The text before the scaling variable (complex `{{}}` format). */
307
310
  textBefore?: string;
308
- /** The text after the scaling variable. */
311
+ /** The text after the scaling variable (complex `{{}}` format). */
309
312
  textAfter?: string;
310
- /** The text precising a numerical scaling variable. */
311
- text?: string;
312
313
  }
313
314
  /**
314
315
  * Represents time information for a recipe.
@@ -333,7 +334,7 @@ interface MetadataObject {
333
334
  * Represents any value that can appear in recipe metadata.
334
335
  * @category Types
335
336
  */
336
- type MetadataValue = string | number | (string | number)[] | MetadataObject | MetadataSource | MetadataTime | MetadataScalingVar | undefined;
337
+ type MetadataValue = string | number | (string | number)[] | MetadataObject | MetadataSource | MetadataTime | Yield | undefined;
337
338
  /**
338
339
  * Represents the metadata of a recipe.
339
340
  * @category Types
@@ -351,55 +352,54 @@ interface Metadata {
351
352
  /** The author of the recipe (separate from source author). */
352
353
  author?: string;
353
354
  /** The number of servings the recipe makes.
354
- * Can be given either as:
355
- * - a number
356
- * - a string which starts with a number (which will be used for scaling) followed by a comma and then whatever you want
357
- * - or an arbitrary scalable number, optionally preceded and/or followed by text.
355
+ * Stored as a number when the value is numeric, or as a string when non-numeric
356
+ * (e.g. `servings: two`). Non-numeric values default the internal scaling baseline to 1.
358
357
  *
359
- * Interchangeable with `yield` or `serves`. If multiple ones are defined,
360
- * the prevailance order for the number which will used for scaling
361
- * is `servings` \> `yield` \> `serves`.
358
+ * Interchangeable with `yield` or `serves` for the purpose of setting
359
+ * {@link Recipe.servings}. If multiple ones are defined, the prevalence
360
+ * order is `servings` \> `serves` \> `yield`.
362
361
  *
363
362
  * @example
364
363
  * ```yaml
365
364
  * servings: 4
366
365
  * ```
366
+ */
367
+ servings?: number | string;
368
+ /** The yield of the recipe.
369
+ * Can be given as:
370
+ * - a plain quantity with optional unit: `yield: 300%g` or `yield: 2`
371
+ * - a complex format with `{{}}` and optional surrounding text:
372
+ * `yield: about {{300%g}} of bread`
373
+ *
374
+ * Interchangeable with `servings` or `serves` for the purpose of setting
375
+ * {@link Recipe.servings}. If multiple ones are defined, the prevalence
376
+ * order is `servings` \> `serves` \> `yield`.
367
377
  *
368
378
  * @example
369
379
  * ```yaml
370
- * servings: 2, a few
380
+ * yield: 300%g
371
381
  * ```
372
382
  *
373
- * * @example
383
+ * @example
374
384
  * ```yaml
375
- * servings: {{1.5%kg}} of bread
385
+ * yield: about {{300%g}} of bread
376
386
  * ```
377
387
  */
378
- servings?: MetadataScalingVar;
379
- /** The yield of the recipe.
380
- * Can be given either as:
381
- * - a number
382
- * - a string which starts with a number (which will be used for scaling) followed by a comma and then whatever you want
383
- * - or an arbitrary scalable number, optionally preceded and/or followed by text.
384
- *
385
- * Interchangeable with `servings` or `serves`. If multiple ones are defined,
386
- * the prevailance order for the number which will used for scaling
387
- * is `servings` \> `yield` \> `serves`. See {@link Metadata.servings | servings}
388
- * for examples.
389
- */
390
- yield?: MetadataScalingVar;
388
+ yield?: Yield;
391
389
  /** The number of people the recipe serves.
392
- * Can be given either as:
393
- * - a number
394
- * - a string which starts with a number (which will be used for scaling) followed by a comma and then whatever you want
395
- * - or an arbitrary scalable number, optionally preceded and/or followed by text.
390
+ * Stored as a number when the value is numeric, or as a string when non-numeric
391
+ * (e.g. `serves: two`). Non-numeric values default the internal scaling baseline to 1.
392
+ *
393
+ * Interchangeable with `servings` or `yield` for the purpose of setting
394
+ * {@link Recipe.servings}. If multiple ones are defined, the prevalence
395
+ * order is `servings` \> `serves` \> `yield`.
396
396
  *
397
- * Interchangeable with `servings` or `yield`. If multiple ones are defined,
398
- * the prevailance order for the number which will used for scaling
399
- * is `servings` \> `yield` \> `serves`. See {@link Metadata.servings | servings}
400
- * for examples.
397
+ * @example
398
+ * ```yaml
399
+ * serves: 4
400
+ * ```
401
401
  */
402
- serves?: MetadataScalingVar;
402
+ serves?: number | string;
403
403
  /** The course of the recipe. */
404
404
  course?: string;
405
405
  /** The category of the recipe. */
@@ -1439,7 +1439,7 @@ declare class Pantry {
1439
1439
  * 14141 = { name = "Big pack", size = "6%kg", price = 10 }
1440
1440
  * `
1441
1441
  * const catalog = new ProductCatalog(catalog);
1442
- * const eggs = catalog.find("oeuf");
1442
+ * const eggs = catalog.products.find(p => p.ingredientName === "eggs");
1443
1443
  * ```
1444
1444
  */
1445
1445
  declare class ProductCatalog {
@@ -1543,19 +1543,6 @@ declare class ShoppingList {
1543
1543
  * and updates the resultingPantry to reflect consumed stock.
1544
1544
  */
1545
1545
  private applyPantrySubtraction;
1546
- /**
1547
- * Builds a ratio map from equivalence lists.
1548
- * For each equivalence list, stores ratio = equiv_value / primary_value
1549
- * for every pair of units, so equivalents can be recomputed after
1550
- * pantry subtraction modifies primary quantities.
1551
- */
1552
- private static buildEquivalenceRatioMap;
1553
- /**
1554
- * Recomputes equivalent quantities from current primary values and stored ratios.
1555
- * For each equivalent unit in equivUnits, new_value = Σ (primary_value × ratio[equivUnit][primaryUnit]).
1556
- * Returns undefined if all equivalents compute to zero.
1557
- */
1558
- private static recomputeEquivalents;
1559
1546
  /**
1560
1547
  * Adds a recipe to the shopping list, then automatically
1561
1548
  * recalculates the quantities and recategorize the ingredients.
@@ -2085,4 +2072,4 @@ declare class NoShoppingListForCartError extends Error {
2085
2072
  constructor();
2086
2073
  }
2087
2074
 
2088
- export { type AddedIngredient, type AddedRecipe, type AddedRecipeOptions, type AlternativeIngredientRef, type AndGroup, type ArbitraryScalable, type ArbitraryScalableItem, type CartContent, type CartMatch, type CartMisMatch, type CategorizedIngredients, type Category, CategoryConfig, type CategoryIngredient, type Cookware, type CookwareFlag, type CookwareItem, type DecimalValue, type FixedNumericValue, type FixedValue, type FlatAndGroup, type FlatGroup, type FlatOrGroup, type FractionValue, type GetIngredientQuantitiesOptions, type Group, type Ingredient, type IngredientAlternative, type IngredientAlternativeBase, type IngredientExtras, type IngredientFlag, type IngredientItem, type IngredientQuantityAndGroup, type IngredientQuantityGroup, type MaybeNestedAndGroup, type MaybeNestedGroup, type MaybeNestedOrGroup, type MaybeScalableQuantity, type Metadata, type MetadataObject, type MetadataScalingVar, type MetadataSource, type MetadataTime, type MetadataValue, NoProductCatalogForCartError, type NoProductMatchErrorCode, NoShoppingListForCartError, type Note, type NoteItem, type OrGroup, Pantry, type PantryItem, type PantryItemToml, type PantryOptions, ProductCatalog, type ProductMatch, type ProductMisMatch, type ProductOption, type ProductOptionBase, type ProductOptionCore, type ProductSelection, type ProductSize, type QuantityBase, type QuantityWithExtendedUnit, type QuantityWithPlainUnit, type QuantityWithUnitDef, type QuantityWithUnitLike, type Range, type RawQuantityGroup, Recipe, type RecipeAlternatives, type RecipeChoices, type RecipeWithFactor, type RecipeWithServings, Section, ShoppingCart, type ShoppingCartOptions, type ShoppingCartSummary, ShoppingList, type SpecificUnitSystem, type Step, type StepItem, type TextAttribute, type TextItem, type TextValue, type Timer, type TimerItem, type ToBaseBySystem, type Unit, type UnitDefinition, type UnitDefinitionLike, type UnitFractionConfig, type UnitSystem, type UnitType, type WithOptionalQuantity, convertQuantityToSystem, formatExtendedQuantity, formatItemQuantity, formatNumericValue, formatQuantity, formatQuantityWithUnit, formatSingleValue, formatUnit, getEffectiveChoices, hasAlternatives, isAlternativeSelected, isAndGroup, isGroupedItem, isSectionActive, isSimpleGroup, isStepActive, renderFractionAsVulgar };
2075
+ export { type AddedIngredient, type AddedRecipe, type AddedRecipeOptions, type AlternativeIngredientRef, type AndGroup, type ArbitraryScalable, type ArbitraryScalableItem, type CartContent, type CartMatch, type CartMisMatch, type CategorizedIngredients, type Category, CategoryConfig, type CategoryIngredient, type Cookware, type CookwareFlag, type CookwareItem, type DecimalValue, type FixedNumericValue, type FixedValue, type FlatAndGroup, type FlatGroup, type FlatOrGroup, type FractionValue, type GetIngredientQuantitiesOptions, type Group, type Ingredient, type IngredientAlternative, type IngredientAlternativeBase, type IngredientExtras, type IngredientFlag, type IngredientItem, type IngredientQuantityAndGroup, type IngredientQuantityGroup, type MaybeNestedAndGroup, type MaybeNestedGroup, type MaybeNestedOrGroup, type MaybeScalableQuantity, type Metadata, type MetadataObject, type MetadataSource, type MetadataTime, type MetadataValue, NoProductCatalogForCartError, type NoProductMatchErrorCode, NoShoppingListForCartError, type Note, type NoteItem, type OrGroup, Pantry, type PantryItem, type PantryItemToml, type PantryOptions, ProductCatalog, type ProductMatch, type ProductMisMatch, type ProductOption, type ProductOptionBase, type ProductOptionCore, type ProductSelection, type ProductSize, type QuantityBase, type QuantityWithExtendedUnit, type QuantityWithPlainUnit, type QuantityWithUnitDef, type QuantityWithUnitLike, type Range, type RawQuantityGroup, Recipe, type RecipeAlternatives, type RecipeChoices, type RecipeWithFactor, type RecipeWithServings, Section, ShoppingCart, type ShoppingCartOptions, type ShoppingCartSummary, ShoppingList, type SpecificUnitSystem, type Step, type StepItem, type TextAttribute, type TextItem, type TextValue, type Timer, type TimerItem, type ToBaseBySystem, type Unit, type UnitDefinition, type UnitDefinitionLike, type UnitFractionConfig, type UnitSystem, type UnitType, type WithOptionalQuantity, type Yield, convertQuantityToSystem, formatExtendedQuantity, formatItemQuantity, formatNumericValue, formatQuantity, formatQuantityWithUnit, formatSingleValue, formatUnit, getEffectiveChoices, hasAlternatives, isAlternativeSelected, isAndGroup, isGroupedItem, isSectionActive, isSimpleGroup, isStepActive, renderFractionAsVulgar };
package/dist/index.d.ts CHANGED
@@ -299,16 +299,17 @@ interface MetadataSource {
299
299
  author?: string;
300
300
  }
301
301
  /**
302
- * Represents scaling variable information for a recipe.
302
+ * Represents a yield metadata value for a recipe.
303
+ * Supports plain quantities (e.g. `yield: 300%g`), complex format with
304
+ * surrounding text (e.g. `yield: about {{300%g}} of bread`), or simple
305
+ * numbers (e.g. `yield: 2`).
303
306
  * @category Types
304
307
  */
305
- interface MetadataScalingVar extends QuantityWithPlainUnit {
306
- /** The text before the scaling variable. */
308
+ interface Yield extends QuantityWithPlainUnit {
309
+ /** The text before the scaling variable (complex `{{}}` format). */
307
310
  textBefore?: string;
308
- /** The text after the scaling variable. */
311
+ /** The text after the scaling variable (complex `{{}}` format). */
309
312
  textAfter?: string;
310
- /** The text precising a numerical scaling variable. */
311
- text?: string;
312
313
  }
313
314
  /**
314
315
  * Represents time information for a recipe.
@@ -333,7 +334,7 @@ interface MetadataObject {
333
334
  * Represents any value that can appear in recipe metadata.
334
335
  * @category Types
335
336
  */
336
- type MetadataValue = string | number | (string | number)[] | MetadataObject | MetadataSource | MetadataTime | MetadataScalingVar | undefined;
337
+ type MetadataValue = string | number | (string | number)[] | MetadataObject | MetadataSource | MetadataTime | Yield | undefined;
337
338
  /**
338
339
  * Represents the metadata of a recipe.
339
340
  * @category Types
@@ -351,55 +352,54 @@ interface Metadata {
351
352
  /** The author of the recipe (separate from source author). */
352
353
  author?: string;
353
354
  /** The number of servings the recipe makes.
354
- * Can be given either as:
355
- * - a number
356
- * - a string which starts with a number (which will be used for scaling) followed by a comma and then whatever you want
357
- * - or an arbitrary scalable number, optionally preceded and/or followed by text.
355
+ * Stored as a number when the value is numeric, or as a string when non-numeric
356
+ * (e.g. `servings: two`). Non-numeric values default the internal scaling baseline to 1.
358
357
  *
359
- * Interchangeable with `yield` or `serves`. If multiple ones are defined,
360
- * the prevailance order for the number which will used for scaling
361
- * is `servings` \> `yield` \> `serves`.
358
+ * Interchangeable with `yield` or `serves` for the purpose of setting
359
+ * {@link Recipe.servings}. If multiple ones are defined, the prevalence
360
+ * order is `servings` \> `serves` \> `yield`.
362
361
  *
363
362
  * @example
364
363
  * ```yaml
365
364
  * servings: 4
366
365
  * ```
366
+ */
367
+ servings?: number | string;
368
+ /** The yield of the recipe.
369
+ * Can be given as:
370
+ * - a plain quantity with optional unit: `yield: 300%g` or `yield: 2`
371
+ * - a complex format with `{{}}` and optional surrounding text:
372
+ * `yield: about {{300%g}} of bread`
373
+ *
374
+ * Interchangeable with `servings` or `serves` for the purpose of setting
375
+ * {@link Recipe.servings}. If multiple ones are defined, the prevalence
376
+ * order is `servings` \> `serves` \> `yield`.
367
377
  *
368
378
  * @example
369
379
  * ```yaml
370
- * servings: 2, a few
380
+ * yield: 300%g
371
381
  * ```
372
382
  *
373
- * * @example
383
+ * @example
374
384
  * ```yaml
375
- * servings: {{1.5%kg}} of bread
385
+ * yield: about {{300%g}} of bread
376
386
  * ```
377
387
  */
378
- servings?: MetadataScalingVar;
379
- /** The yield of the recipe.
380
- * Can be given either as:
381
- * - a number
382
- * - a string which starts with a number (which will be used for scaling) followed by a comma and then whatever you want
383
- * - or an arbitrary scalable number, optionally preceded and/or followed by text.
384
- *
385
- * Interchangeable with `servings` or `serves`. If multiple ones are defined,
386
- * the prevailance order for the number which will used for scaling
387
- * is `servings` \> `yield` \> `serves`. See {@link Metadata.servings | servings}
388
- * for examples.
389
- */
390
- yield?: MetadataScalingVar;
388
+ yield?: Yield;
391
389
  /** The number of people the recipe serves.
392
- * Can be given either as:
393
- * - a number
394
- * - a string which starts with a number (which will be used for scaling) followed by a comma and then whatever you want
395
- * - or an arbitrary scalable number, optionally preceded and/or followed by text.
390
+ * Stored as a number when the value is numeric, or as a string when non-numeric
391
+ * (e.g. `serves: two`). Non-numeric values default the internal scaling baseline to 1.
392
+ *
393
+ * Interchangeable with `servings` or `yield` for the purpose of setting
394
+ * {@link Recipe.servings}. If multiple ones are defined, the prevalence
395
+ * order is `servings` \> `serves` \> `yield`.
396
396
  *
397
- * Interchangeable with `servings` or `yield`. If multiple ones are defined,
398
- * the prevailance order for the number which will used for scaling
399
- * is `servings` \> `yield` \> `serves`. See {@link Metadata.servings | servings}
400
- * for examples.
397
+ * @example
398
+ * ```yaml
399
+ * serves: 4
400
+ * ```
401
401
  */
402
- serves?: MetadataScalingVar;
402
+ serves?: number | string;
403
403
  /** The course of the recipe. */
404
404
  course?: string;
405
405
  /** The category of the recipe. */
@@ -1439,7 +1439,7 @@ declare class Pantry {
1439
1439
  * 14141 = { name = "Big pack", size = "6%kg", price = 10 }
1440
1440
  * `
1441
1441
  * const catalog = new ProductCatalog(catalog);
1442
- * const eggs = catalog.find("oeuf");
1442
+ * const eggs = catalog.products.find(p => p.ingredientName === "eggs");
1443
1443
  * ```
1444
1444
  */
1445
1445
  declare class ProductCatalog {
@@ -1543,19 +1543,6 @@ declare class ShoppingList {
1543
1543
  * and updates the resultingPantry to reflect consumed stock.
1544
1544
  */
1545
1545
  private applyPantrySubtraction;
1546
- /**
1547
- * Builds a ratio map from equivalence lists.
1548
- * For each equivalence list, stores ratio = equiv_value / primary_value
1549
- * for every pair of units, so equivalents can be recomputed after
1550
- * pantry subtraction modifies primary quantities.
1551
- */
1552
- private static buildEquivalenceRatioMap;
1553
- /**
1554
- * Recomputes equivalent quantities from current primary values and stored ratios.
1555
- * For each equivalent unit in equivUnits, new_value = Σ (primary_value × ratio[equivUnit][primaryUnit]).
1556
- * Returns undefined if all equivalents compute to zero.
1557
- */
1558
- private static recomputeEquivalents;
1559
1546
  /**
1560
1547
  * Adds a recipe to the shopping list, then automatically
1561
1548
  * recalculates the quantities and recategorize the ingredients.
@@ -2085,4 +2072,4 @@ declare class NoShoppingListForCartError extends Error {
2085
2072
  constructor();
2086
2073
  }
2087
2074
 
2088
- export { type AddedIngredient, type AddedRecipe, type AddedRecipeOptions, type AlternativeIngredientRef, type AndGroup, type ArbitraryScalable, type ArbitraryScalableItem, type CartContent, type CartMatch, type CartMisMatch, type CategorizedIngredients, type Category, CategoryConfig, type CategoryIngredient, type Cookware, type CookwareFlag, type CookwareItem, type DecimalValue, type FixedNumericValue, type FixedValue, type FlatAndGroup, type FlatGroup, type FlatOrGroup, type FractionValue, type GetIngredientQuantitiesOptions, type Group, type Ingredient, type IngredientAlternative, type IngredientAlternativeBase, type IngredientExtras, type IngredientFlag, type IngredientItem, type IngredientQuantityAndGroup, type IngredientQuantityGroup, type MaybeNestedAndGroup, type MaybeNestedGroup, type MaybeNestedOrGroup, type MaybeScalableQuantity, type Metadata, type MetadataObject, type MetadataScalingVar, type MetadataSource, type MetadataTime, type MetadataValue, NoProductCatalogForCartError, type NoProductMatchErrorCode, NoShoppingListForCartError, type Note, type NoteItem, type OrGroup, Pantry, type PantryItem, type PantryItemToml, type PantryOptions, ProductCatalog, type ProductMatch, type ProductMisMatch, type ProductOption, type ProductOptionBase, type ProductOptionCore, type ProductSelection, type ProductSize, type QuantityBase, type QuantityWithExtendedUnit, type QuantityWithPlainUnit, type QuantityWithUnitDef, type QuantityWithUnitLike, type Range, type RawQuantityGroup, Recipe, type RecipeAlternatives, type RecipeChoices, type RecipeWithFactor, type RecipeWithServings, Section, ShoppingCart, type ShoppingCartOptions, type ShoppingCartSummary, ShoppingList, type SpecificUnitSystem, type Step, type StepItem, type TextAttribute, type TextItem, type TextValue, type Timer, type TimerItem, type ToBaseBySystem, type Unit, type UnitDefinition, type UnitDefinitionLike, type UnitFractionConfig, type UnitSystem, type UnitType, type WithOptionalQuantity, convertQuantityToSystem, formatExtendedQuantity, formatItemQuantity, formatNumericValue, formatQuantity, formatQuantityWithUnit, formatSingleValue, formatUnit, getEffectiveChoices, hasAlternatives, isAlternativeSelected, isAndGroup, isGroupedItem, isSectionActive, isSimpleGroup, isStepActive, renderFractionAsVulgar };
2075
+ export { type AddedIngredient, type AddedRecipe, type AddedRecipeOptions, type AlternativeIngredientRef, type AndGroup, type ArbitraryScalable, type ArbitraryScalableItem, type CartContent, type CartMatch, type CartMisMatch, type CategorizedIngredients, type Category, CategoryConfig, type CategoryIngredient, type Cookware, type CookwareFlag, type CookwareItem, type DecimalValue, type FixedNumericValue, type FixedValue, type FlatAndGroup, type FlatGroup, type FlatOrGroup, type FractionValue, type GetIngredientQuantitiesOptions, type Group, type Ingredient, type IngredientAlternative, type IngredientAlternativeBase, type IngredientExtras, type IngredientFlag, type IngredientItem, type IngredientQuantityAndGroup, type IngredientQuantityGroup, type MaybeNestedAndGroup, type MaybeNestedGroup, type MaybeNestedOrGroup, type MaybeScalableQuantity, type Metadata, type MetadataObject, type MetadataSource, type MetadataTime, type MetadataValue, NoProductCatalogForCartError, type NoProductMatchErrorCode, NoShoppingListForCartError, type Note, type NoteItem, type OrGroup, Pantry, type PantryItem, type PantryItemToml, type PantryOptions, ProductCatalog, type ProductMatch, type ProductMisMatch, type ProductOption, type ProductOptionBase, type ProductOptionCore, type ProductSelection, type ProductSize, type QuantityBase, type QuantityWithExtendedUnit, type QuantityWithPlainUnit, type QuantityWithUnitDef, type QuantityWithUnitLike, type Range, type RawQuantityGroup, Recipe, type RecipeAlternatives, type RecipeChoices, type RecipeWithFactor, type RecipeWithServings, Section, ShoppingCart, type ShoppingCartOptions, type ShoppingCartSummary, ShoppingList, type SpecificUnitSystem, type Step, type StepItem, type TextAttribute, type TextItem, type TextValue, type Timer, type TimerItem, type ToBaseBySystem, type Unit, type UnitDefinition, type UnitDefinitionLike, type UnitFractionConfig, type UnitSystem, type UnitType, type WithOptionalQuantity, type Yield, convertQuantityToSystem, formatExtendedQuantity, formatItemQuantity, formatNumericValue, formatQuantity, formatQuantityWithUnit, formatSingleValue, formatUnit, getEffectiveChoices, hasAlternatives, isAlternativeSelected, isAndGroup, isGroupedItem, isSectionActive, isSimpleGroup, isStepActive, renderFractionAsVulgar };