@tmlmt/cooklang-parser 3.0.0-alpha.12 → 3.0.0-alpha.13
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.cjs +228 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -53
- package/dist/index.d.ts +68 -53
- package/dist/index.js +228 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -154,7 +154,7 @@ declare class Recipe {
|
|
|
154
154
|
* Quantities are grouped by their alternative signature and summed using addEquivalentsAndSimplify.
|
|
155
155
|
* @internal
|
|
156
156
|
*/
|
|
157
|
-
private
|
|
157
|
+
private _populateIngredientQuantities;
|
|
158
158
|
/**
|
|
159
159
|
* Gets ingredients with their quantities populated, optionally filtered by section/step
|
|
160
160
|
* and respecting user choices for alternatives.
|
|
@@ -237,6 +237,42 @@ declare class Recipe {
|
|
|
237
237
|
clone(): Recipe;
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Represents source attribution information for a recipe.
|
|
242
|
+
* @category Types
|
|
243
|
+
*/
|
|
244
|
+
interface MetadataSource {
|
|
245
|
+
/** The name of the source (e.g., "New York Times Cooking"). */
|
|
246
|
+
name?: string;
|
|
247
|
+
/** The URL of the source recipe. */
|
|
248
|
+
url?: string;
|
|
249
|
+
/** The author at the source. */
|
|
250
|
+
author?: string;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Represents time information for a recipe.
|
|
254
|
+
* @category Types
|
|
255
|
+
*/
|
|
256
|
+
interface MetadataTime {
|
|
257
|
+
/** The preparation time (not parsed into DateTime format). */
|
|
258
|
+
prep?: string;
|
|
259
|
+
/** The cooking time (not parsed into DateTime format). */
|
|
260
|
+
cook?: string;
|
|
261
|
+
/** The total time required (not parsed into DateTime format). */
|
|
262
|
+
total?: string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Represents a nested metadata object with arbitrary keys.
|
|
266
|
+
* @category Types
|
|
267
|
+
*/
|
|
268
|
+
interface MetadataObject {
|
|
269
|
+
[key: string]: MetadataValue;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Represents any value that can appear in recipe metadata.
|
|
273
|
+
* @category Types
|
|
274
|
+
*/
|
|
275
|
+
type MetadataValue = string | number | (string | number)[] | MetadataObject | MetadataSource | MetadataTime | undefined;
|
|
240
276
|
/**
|
|
241
277
|
* Represents the metadata of a recipe.
|
|
242
278
|
* @category Types
|
|
@@ -246,15 +282,12 @@ interface Metadata {
|
|
|
246
282
|
title?: string;
|
|
247
283
|
/** The tags of the recipe. */
|
|
248
284
|
tags?: string[];
|
|
249
|
-
/**
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
/** The source author of the recipe. */
|
|
256
|
-
"source.author"?: string;
|
|
257
|
-
/** The author of the recipe. */
|
|
285
|
+
/**
|
|
286
|
+
* The source of the recipe. Can be a simple URL string or structured attribution.
|
|
287
|
+
* When parsed from YAML, `source.name`, `source.url`, `source.author` keys are merged here.
|
|
288
|
+
*/
|
|
289
|
+
source?: string | MetadataSource;
|
|
290
|
+
/** The author of the recipe (separate from source author). */
|
|
258
291
|
author?: string;
|
|
259
292
|
/** The number of servings the recipe makes.
|
|
260
293
|
* Should be either a number or a string which starts with a number
|
|
@@ -305,30 +338,11 @@ interface Metadata {
|
|
|
305
338
|
/** The locale of the recipe. */
|
|
306
339
|
locale?: string;
|
|
307
340
|
/**
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
|
|
311
|
-
"prep time"?: string;
|
|
312
|
-
/**
|
|
313
|
-
* Alias of `prep time`
|
|
314
|
-
*/
|
|
315
|
-
"time.prep"?: string;
|
|
316
|
-
/**
|
|
317
|
-
* The cooking time of the recipe.
|
|
318
|
-
* Will not be further parsed into any DateTime format nor normalize
|
|
341
|
+
* Time information for the recipe.
|
|
342
|
+
* When parsed from YAML, `prep time`, `time.prep`, `cook time`, `time.cook`,
|
|
343
|
+
* `time required`, `time`, `duration` keys are merged here.
|
|
319
344
|
*/
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Alias of `cook time`
|
|
323
|
-
*/
|
|
324
|
-
"time.cook"?: string;
|
|
325
|
-
/**
|
|
326
|
-
* The total time of the recipe.
|
|
327
|
-
* Will not be further parsed into any DateTime format nor normalize
|
|
328
|
-
*/
|
|
329
|
-
"time required"?: string;
|
|
330
|
-
time?: string;
|
|
331
|
-
duration?: string;
|
|
345
|
+
time?: MetadataTime;
|
|
332
346
|
/** The difficulty of the recipe. */
|
|
333
347
|
difficulty?: string;
|
|
334
348
|
/** The cuisine of the recipe. */
|
|
@@ -337,14 +351,10 @@ interface Metadata {
|
|
|
337
351
|
diet?: string;
|
|
338
352
|
/** The description of the recipe. */
|
|
339
353
|
description?: string;
|
|
340
|
-
/** The images of the recipe.
|
|
354
|
+
/** The images of the recipe. */
|
|
341
355
|
images?: string[];
|
|
342
|
-
/** The
|
|
343
|
-
pictures?: string[];
|
|
344
|
-
/** The picture of the recipe. Alias of `picture` */
|
|
356
|
+
/** The primary image of the recipe. */
|
|
345
357
|
image?: string;
|
|
346
|
-
/** The picture of the recipe. Alias of `image` */
|
|
347
|
-
picture?: string;
|
|
348
358
|
/** The introduction of the recipe. */
|
|
349
359
|
introduction?: string;
|
|
350
360
|
/**
|
|
@@ -352,7 +362,12 @@ interface Metadata {
|
|
|
352
362
|
* See [Unit Conversion Guide](/guide-unit-conversion) for more information.
|
|
353
363
|
* This stores the original value as written by the user.
|
|
354
364
|
*/
|
|
355
|
-
|
|
365
|
+
unitSystem?: string;
|
|
366
|
+
/**
|
|
367
|
+
* Index signature for additional metadata fields not explicitly typed.
|
|
368
|
+
* Any metadata key in the frontmatter will be captured here.
|
|
369
|
+
*/
|
|
370
|
+
[key: string]: MetadataValue;
|
|
356
371
|
}
|
|
357
372
|
/**
|
|
358
373
|
* Represents a quantity described by text, e.g. "a pinch"
|
|
@@ -1157,7 +1172,7 @@ declare class ProductCatalog {
|
|
|
1157
1172
|
* ## Usage
|
|
1158
1173
|
*
|
|
1159
1174
|
* - Create a new ShoppingList instance with an optional category configuration (see {@link ShoppingList."constructor" | constructor})
|
|
1160
|
-
* - Add recipes, scaling them as needed (see {@link ShoppingList.
|
|
1175
|
+
* - Add recipes, scaling them as needed (see {@link ShoppingList.addRecipe | addRecipe()})
|
|
1161
1176
|
* - Categorize the ingredients (see {@link ShoppingList.categorize | categorize()})
|
|
1162
1177
|
*
|
|
1163
1178
|
* @example
|
|
@@ -1169,10 +1184,10 @@ declare class ProductCatalog {
|
|
|
1169
1184
|
* const categoryConfig = fs.readFileSync("./myconfig.txt", "utf-8")
|
|
1170
1185
|
* const recipe1 = new Recipe(fs.readFileSync("./myrecipe.cook", "utf-8"));
|
|
1171
1186
|
* const shoppingList = new ShoppingList();
|
|
1172
|
-
* shoppingList.
|
|
1187
|
+
* shoppingList.setCategoryConfig(categoryConfig);
|
|
1173
1188
|
* // Quantities are automatically calculated and ingredients categorized
|
|
1174
1189
|
* // when adding a recipe
|
|
1175
|
-
* shoppingList.
|
|
1190
|
+
* shoppingList.addRecipe(recipe1);
|
|
1176
1191
|
* ```
|
|
1177
1192
|
*
|
|
1178
1193
|
* @category Classes
|
|
@@ -1189,17 +1204,17 @@ declare class ShoppingList {
|
|
|
1189
1204
|
/**
|
|
1190
1205
|
* The category configuration for the shopping list.
|
|
1191
1206
|
*/
|
|
1192
|
-
|
|
1207
|
+
categoryConfig?: CategoryConfig;
|
|
1193
1208
|
/**
|
|
1194
1209
|
* The categorized ingredients in the shopping list.
|
|
1195
1210
|
*/
|
|
1196
1211
|
categories?: CategorizedIngredients;
|
|
1197
1212
|
/**
|
|
1198
1213
|
* Creates a new ShoppingList instance
|
|
1199
|
-
* @param
|
|
1214
|
+
* @param categoryConfigStr - The category configuration to parse.
|
|
1200
1215
|
*/
|
|
1201
|
-
constructor(
|
|
1202
|
-
private
|
|
1216
|
+
constructor(categoryConfigStr?: string | CategoryConfig);
|
|
1217
|
+
private calculateIngredients;
|
|
1203
1218
|
/**
|
|
1204
1219
|
* Adds a recipe to the shopping list, then automatically
|
|
1205
1220
|
* recalculates the quantities and recategorize the ingredients.
|
|
@@ -1207,7 +1222,7 @@ declare class ShoppingList {
|
|
|
1207
1222
|
* @param options - Options for adding the recipe.
|
|
1208
1223
|
* @throws Error if the recipe has alternatives without corresponding choices.
|
|
1209
1224
|
*/
|
|
1210
|
-
|
|
1225
|
+
addRecipe(recipe: Recipe, options?: AddedRecipeOptions): void;
|
|
1211
1226
|
/**
|
|
1212
1227
|
* Checks if a recipe has unresolved alternatives (alternatives without provided choices).
|
|
1213
1228
|
* @param recipe - The recipe to check.
|
|
@@ -1217,16 +1232,16 @@ declare class ShoppingList {
|
|
|
1217
1232
|
private getUnresolvedAlternativesError;
|
|
1218
1233
|
/**
|
|
1219
1234
|
* Removes a recipe from the shopping list, then automatically
|
|
1220
|
-
* recalculates the quantities and recategorize the ingredients.
|
|
1235
|
+
* recalculates the quantities and recategorize the ingredients.
|
|
1221
1236
|
* @param index - The index of the recipe to remove.
|
|
1222
1237
|
*/
|
|
1223
|
-
|
|
1238
|
+
removeRecipe(index: number): void;
|
|
1224
1239
|
/**
|
|
1225
1240
|
* Sets the category configuration for the shopping list
|
|
1226
1241
|
* and automatically categorize current ingredients from the list.
|
|
1227
1242
|
* @param config - The category configuration to parse.
|
|
1228
1243
|
*/
|
|
1229
|
-
|
|
1244
|
+
setCategoryConfig(config: string | CategoryConfig): void;
|
|
1230
1245
|
/**
|
|
1231
1246
|
* Categorizes the ingredients in the shopping list
|
|
1232
1247
|
* Will use the category config if any, otherwise all ingredients will be placed in the "other" category
|
|
@@ -1269,7 +1284,7 @@ interface ShoppingCartSummary {
|
|
|
1269
1284
|
* ```ts
|
|
1270
1285
|
* const shoppingList = new ShoppingList();
|
|
1271
1286
|
* const recipe = new Recipe("@flour{600%g}");
|
|
1272
|
-
* shoppingList.
|
|
1287
|
+
* shoppingList.addRecipe(recipe);
|
|
1273
1288
|
*
|
|
1274
1289
|
* const catalog = new ProductCatalog();
|
|
1275
1290
|
* catalog.products = [
|
|
@@ -1639,4 +1654,4 @@ declare class NoShoppingListForCartError extends Error {
|
|
|
1639
1654
|
constructor();
|
|
1640
1655
|
}
|
|
1641
1656
|
|
|
1642
|
-
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 IngredientExtras, type IngredientFlag, type IngredientItem, type IngredientQuantityAndGroup, type IngredientQuantityGroup, type MaybeNestedAndGroup, type MaybeNestedGroup, type MaybeNestedOrGroup, type MaybeScalableQuantity, type Metadata, NoProductCatalogForCartError, type NoProductMatchErrorCode, NoShoppingListForCartError, type Note, type NoteItem, type OrGroup, 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, Recipe, type RecipeAlternatives, type RecipeChoices, type RecipeWithFactor, type RecipeWithServings, Section, ShoppingCart, type ShoppingCartOptions, type ShoppingCartSummary, ShoppingList, type SpecificUnitSystem, type Step, type StepItem, type TextItem, type TextValue, type Timer, type TimerItem, type ToBaseBySystem, type Unit, type UnitDefinition, type UnitDefinitionLike, type UnitSystem, type UnitType, convertQuantityToSystem, formatExtendedQuantity, formatItemQuantity, formatNumericValue, formatQuantity, formatQuantityWithUnit, formatSingleValue, formatUnit, hasAlternatives, isAlternativeSelected, isAndGroup, isGroupedItem, isSimpleGroup, renderFractionAsVulgar };
|
|
1657
|
+
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 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, 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, Recipe, type RecipeAlternatives, type RecipeChoices, type RecipeWithFactor, type RecipeWithServings, Section, ShoppingCart, type ShoppingCartOptions, type ShoppingCartSummary, ShoppingList, type SpecificUnitSystem, type Step, type StepItem, type TextItem, type TextValue, type Timer, type TimerItem, type ToBaseBySystem, type Unit, type UnitDefinition, type UnitDefinitionLike, type UnitSystem, type UnitType, convertQuantityToSystem, formatExtendedQuantity, formatItemQuantity, formatNumericValue, formatQuantity, formatQuantityWithUnit, formatSingleValue, formatUnit, hasAlternatives, isAlternativeSelected, isAndGroup, isGroupedItem, isSimpleGroup, renderFractionAsVulgar };
|
package/dist/index.d.ts
CHANGED
|
@@ -154,7 +154,7 @@ declare class Recipe {
|
|
|
154
154
|
* Quantities are grouped by their alternative signature and summed using addEquivalentsAndSimplify.
|
|
155
155
|
* @internal
|
|
156
156
|
*/
|
|
157
|
-
private
|
|
157
|
+
private _populateIngredientQuantities;
|
|
158
158
|
/**
|
|
159
159
|
* Gets ingredients with their quantities populated, optionally filtered by section/step
|
|
160
160
|
* and respecting user choices for alternatives.
|
|
@@ -237,6 +237,42 @@ declare class Recipe {
|
|
|
237
237
|
clone(): Recipe;
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Represents source attribution information for a recipe.
|
|
242
|
+
* @category Types
|
|
243
|
+
*/
|
|
244
|
+
interface MetadataSource {
|
|
245
|
+
/** The name of the source (e.g., "New York Times Cooking"). */
|
|
246
|
+
name?: string;
|
|
247
|
+
/** The URL of the source recipe. */
|
|
248
|
+
url?: string;
|
|
249
|
+
/** The author at the source. */
|
|
250
|
+
author?: string;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Represents time information for a recipe.
|
|
254
|
+
* @category Types
|
|
255
|
+
*/
|
|
256
|
+
interface MetadataTime {
|
|
257
|
+
/** The preparation time (not parsed into DateTime format). */
|
|
258
|
+
prep?: string;
|
|
259
|
+
/** The cooking time (not parsed into DateTime format). */
|
|
260
|
+
cook?: string;
|
|
261
|
+
/** The total time required (not parsed into DateTime format). */
|
|
262
|
+
total?: string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Represents a nested metadata object with arbitrary keys.
|
|
266
|
+
* @category Types
|
|
267
|
+
*/
|
|
268
|
+
interface MetadataObject {
|
|
269
|
+
[key: string]: MetadataValue;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Represents any value that can appear in recipe metadata.
|
|
273
|
+
* @category Types
|
|
274
|
+
*/
|
|
275
|
+
type MetadataValue = string | number | (string | number)[] | MetadataObject | MetadataSource | MetadataTime | undefined;
|
|
240
276
|
/**
|
|
241
277
|
* Represents the metadata of a recipe.
|
|
242
278
|
* @category Types
|
|
@@ -246,15 +282,12 @@ interface Metadata {
|
|
|
246
282
|
title?: string;
|
|
247
283
|
/** The tags of the recipe. */
|
|
248
284
|
tags?: string[];
|
|
249
|
-
/**
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
/** The source author of the recipe. */
|
|
256
|
-
"source.author"?: string;
|
|
257
|
-
/** The author of the recipe. */
|
|
285
|
+
/**
|
|
286
|
+
* The source of the recipe. Can be a simple URL string or structured attribution.
|
|
287
|
+
* When parsed from YAML, `source.name`, `source.url`, `source.author` keys are merged here.
|
|
288
|
+
*/
|
|
289
|
+
source?: string | MetadataSource;
|
|
290
|
+
/** The author of the recipe (separate from source author). */
|
|
258
291
|
author?: string;
|
|
259
292
|
/** The number of servings the recipe makes.
|
|
260
293
|
* Should be either a number or a string which starts with a number
|
|
@@ -305,30 +338,11 @@ interface Metadata {
|
|
|
305
338
|
/** The locale of the recipe. */
|
|
306
339
|
locale?: string;
|
|
307
340
|
/**
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
|
|
311
|
-
"prep time"?: string;
|
|
312
|
-
/**
|
|
313
|
-
* Alias of `prep time`
|
|
314
|
-
*/
|
|
315
|
-
"time.prep"?: string;
|
|
316
|
-
/**
|
|
317
|
-
* The cooking time of the recipe.
|
|
318
|
-
* Will not be further parsed into any DateTime format nor normalize
|
|
341
|
+
* Time information for the recipe.
|
|
342
|
+
* When parsed from YAML, `prep time`, `time.prep`, `cook time`, `time.cook`,
|
|
343
|
+
* `time required`, `time`, `duration` keys are merged here.
|
|
319
344
|
*/
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Alias of `cook time`
|
|
323
|
-
*/
|
|
324
|
-
"time.cook"?: string;
|
|
325
|
-
/**
|
|
326
|
-
* The total time of the recipe.
|
|
327
|
-
* Will not be further parsed into any DateTime format nor normalize
|
|
328
|
-
*/
|
|
329
|
-
"time required"?: string;
|
|
330
|
-
time?: string;
|
|
331
|
-
duration?: string;
|
|
345
|
+
time?: MetadataTime;
|
|
332
346
|
/** The difficulty of the recipe. */
|
|
333
347
|
difficulty?: string;
|
|
334
348
|
/** The cuisine of the recipe. */
|
|
@@ -337,14 +351,10 @@ interface Metadata {
|
|
|
337
351
|
diet?: string;
|
|
338
352
|
/** The description of the recipe. */
|
|
339
353
|
description?: string;
|
|
340
|
-
/** The images of the recipe.
|
|
354
|
+
/** The images of the recipe. */
|
|
341
355
|
images?: string[];
|
|
342
|
-
/** The
|
|
343
|
-
pictures?: string[];
|
|
344
|
-
/** The picture of the recipe. Alias of `picture` */
|
|
356
|
+
/** The primary image of the recipe. */
|
|
345
357
|
image?: string;
|
|
346
|
-
/** The picture of the recipe. Alias of `image` */
|
|
347
|
-
picture?: string;
|
|
348
358
|
/** The introduction of the recipe. */
|
|
349
359
|
introduction?: string;
|
|
350
360
|
/**
|
|
@@ -352,7 +362,12 @@ interface Metadata {
|
|
|
352
362
|
* See [Unit Conversion Guide](/guide-unit-conversion) for more information.
|
|
353
363
|
* This stores the original value as written by the user.
|
|
354
364
|
*/
|
|
355
|
-
|
|
365
|
+
unitSystem?: string;
|
|
366
|
+
/**
|
|
367
|
+
* Index signature for additional metadata fields not explicitly typed.
|
|
368
|
+
* Any metadata key in the frontmatter will be captured here.
|
|
369
|
+
*/
|
|
370
|
+
[key: string]: MetadataValue;
|
|
356
371
|
}
|
|
357
372
|
/**
|
|
358
373
|
* Represents a quantity described by text, e.g. "a pinch"
|
|
@@ -1157,7 +1172,7 @@ declare class ProductCatalog {
|
|
|
1157
1172
|
* ## Usage
|
|
1158
1173
|
*
|
|
1159
1174
|
* - Create a new ShoppingList instance with an optional category configuration (see {@link ShoppingList."constructor" | constructor})
|
|
1160
|
-
* - Add recipes, scaling them as needed (see {@link ShoppingList.
|
|
1175
|
+
* - Add recipes, scaling them as needed (see {@link ShoppingList.addRecipe | addRecipe()})
|
|
1161
1176
|
* - Categorize the ingredients (see {@link ShoppingList.categorize | categorize()})
|
|
1162
1177
|
*
|
|
1163
1178
|
* @example
|
|
@@ -1169,10 +1184,10 @@ declare class ProductCatalog {
|
|
|
1169
1184
|
* const categoryConfig = fs.readFileSync("./myconfig.txt", "utf-8")
|
|
1170
1185
|
* const recipe1 = new Recipe(fs.readFileSync("./myrecipe.cook", "utf-8"));
|
|
1171
1186
|
* const shoppingList = new ShoppingList();
|
|
1172
|
-
* shoppingList.
|
|
1187
|
+
* shoppingList.setCategoryConfig(categoryConfig);
|
|
1173
1188
|
* // Quantities are automatically calculated and ingredients categorized
|
|
1174
1189
|
* // when adding a recipe
|
|
1175
|
-
* shoppingList.
|
|
1190
|
+
* shoppingList.addRecipe(recipe1);
|
|
1176
1191
|
* ```
|
|
1177
1192
|
*
|
|
1178
1193
|
* @category Classes
|
|
@@ -1189,17 +1204,17 @@ declare class ShoppingList {
|
|
|
1189
1204
|
/**
|
|
1190
1205
|
* The category configuration for the shopping list.
|
|
1191
1206
|
*/
|
|
1192
|
-
|
|
1207
|
+
categoryConfig?: CategoryConfig;
|
|
1193
1208
|
/**
|
|
1194
1209
|
* The categorized ingredients in the shopping list.
|
|
1195
1210
|
*/
|
|
1196
1211
|
categories?: CategorizedIngredients;
|
|
1197
1212
|
/**
|
|
1198
1213
|
* Creates a new ShoppingList instance
|
|
1199
|
-
* @param
|
|
1214
|
+
* @param categoryConfigStr - The category configuration to parse.
|
|
1200
1215
|
*/
|
|
1201
|
-
constructor(
|
|
1202
|
-
private
|
|
1216
|
+
constructor(categoryConfigStr?: string | CategoryConfig);
|
|
1217
|
+
private calculateIngredients;
|
|
1203
1218
|
/**
|
|
1204
1219
|
* Adds a recipe to the shopping list, then automatically
|
|
1205
1220
|
* recalculates the quantities and recategorize the ingredients.
|
|
@@ -1207,7 +1222,7 @@ declare class ShoppingList {
|
|
|
1207
1222
|
* @param options - Options for adding the recipe.
|
|
1208
1223
|
* @throws Error if the recipe has alternatives without corresponding choices.
|
|
1209
1224
|
*/
|
|
1210
|
-
|
|
1225
|
+
addRecipe(recipe: Recipe, options?: AddedRecipeOptions): void;
|
|
1211
1226
|
/**
|
|
1212
1227
|
* Checks if a recipe has unresolved alternatives (alternatives without provided choices).
|
|
1213
1228
|
* @param recipe - The recipe to check.
|
|
@@ -1217,16 +1232,16 @@ declare class ShoppingList {
|
|
|
1217
1232
|
private getUnresolvedAlternativesError;
|
|
1218
1233
|
/**
|
|
1219
1234
|
* Removes a recipe from the shopping list, then automatically
|
|
1220
|
-
* recalculates the quantities and recategorize the ingredients.
|
|
1235
|
+
* recalculates the quantities and recategorize the ingredients.
|
|
1221
1236
|
* @param index - The index of the recipe to remove.
|
|
1222
1237
|
*/
|
|
1223
|
-
|
|
1238
|
+
removeRecipe(index: number): void;
|
|
1224
1239
|
/**
|
|
1225
1240
|
* Sets the category configuration for the shopping list
|
|
1226
1241
|
* and automatically categorize current ingredients from the list.
|
|
1227
1242
|
* @param config - The category configuration to parse.
|
|
1228
1243
|
*/
|
|
1229
|
-
|
|
1244
|
+
setCategoryConfig(config: string | CategoryConfig): void;
|
|
1230
1245
|
/**
|
|
1231
1246
|
* Categorizes the ingredients in the shopping list
|
|
1232
1247
|
* Will use the category config if any, otherwise all ingredients will be placed in the "other" category
|
|
@@ -1269,7 +1284,7 @@ interface ShoppingCartSummary {
|
|
|
1269
1284
|
* ```ts
|
|
1270
1285
|
* const shoppingList = new ShoppingList();
|
|
1271
1286
|
* const recipe = new Recipe("@flour{600%g}");
|
|
1272
|
-
* shoppingList.
|
|
1287
|
+
* shoppingList.addRecipe(recipe);
|
|
1273
1288
|
*
|
|
1274
1289
|
* const catalog = new ProductCatalog();
|
|
1275
1290
|
* catalog.products = [
|
|
@@ -1639,4 +1654,4 @@ declare class NoShoppingListForCartError extends Error {
|
|
|
1639
1654
|
constructor();
|
|
1640
1655
|
}
|
|
1641
1656
|
|
|
1642
|
-
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 IngredientExtras, type IngredientFlag, type IngredientItem, type IngredientQuantityAndGroup, type IngredientQuantityGroup, type MaybeNestedAndGroup, type MaybeNestedGroup, type MaybeNestedOrGroup, type MaybeScalableQuantity, type Metadata, NoProductCatalogForCartError, type NoProductMatchErrorCode, NoShoppingListForCartError, type Note, type NoteItem, type OrGroup, 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, Recipe, type RecipeAlternatives, type RecipeChoices, type RecipeWithFactor, type RecipeWithServings, Section, ShoppingCart, type ShoppingCartOptions, type ShoppingCartSummary, ShoppingList, type SpecificUnitSystem, type Step, type StepItem, type TextItem, type TextValue, type Timer, type TimerItem, type ToBaseBySystem, type Unit, type UnitDefinition, type UnitDefinitionLike, type UnitSystem, type UnitType, convertQuantityToSystem, formatExtendedQuantity, formatItemQuantity, formatNumericValue, formatQuantity, formatQuantityWithUnit, formatSingleValue, formatUnit, hasAlternatives, isAlternativeSelected, isAndGroup, isGroupedItem, isSimpleGroup, renderFractionAsVulgar };
|
|
1657
|
+
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 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, 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, Recipe, type RecipeAlternatives, type RecipeChoices, type RecipeWithFactor, type RecipeWithServings, Section, ShoppingCart, type ShoppingCartOptions, type ShoppingCartSummary, ShoppingList, type SpecificUnitSystem, type Step, type StepItem, type TextItem, type TextValue, type Timer, type TimerItem, type ToBaseBySystem, type Unit, type UnitDefinition, type UnitDefinitionLike, type UnitSystem, type UnitType, convertQuantityToSystem, formatExtendedQuantity, formatItemQuantity, formatNumericValue, formatQuantity, formatQuantityWithUnit, formatSingleValue, formatUnit, hasAlternatives, isAlternativeSelected, isAndGroup, isGroupedItem, isSimpleGroup, renderFractionAsVulgar };
|