### Uninstall and Install Cooklang Packages Source: https://github.com/cooklang/cooklang-ts/blob/main/DEPRECATION_NOTICE.md Use these npm commands to uninstall the deprecated @cooklang/cooklang-ts package and install the new @cooklang/cooklang package. ```bash # Uninstall old package npm uninstall @cooklang/cooklang-ts # Install new package npm install @cooklang/cooklang ``` -------------------------------- ### Parse Cooklang Recipe with Custom Parser Defaults Source: https://context7.com/cooklang/cooklang-ts/llms.txt Demonstrates creating a Parser instance with custom default values for ingredient amounts, cookware amounts, and step numbering. Shows how to parse a recipe string and access the resulting metadata, ingredients, and cookwares. ```typescript import { Parser } from '@cooklang/cooklang-ts'; // Create parser with custom defaults const parser = new Parser({ defaultIngredientAmount: 'some', defaultCookwareAmount: 1, includeStepNumber: false }); // Parse a Cooklang recipe string const result = parser.parse(` >> author: Chef John >> prep time: 10 minutes Preheat the #oven{} to 350°F. Mix @flour{2%cups}, @sugar{1%cup}, and @butter{1/2%cup} in a #mixing bowl{large}. Bake for ~{25%minutes} until golden brown. `); // Access all parsed components console.log(result.metadata); // { author: 'Chef John', 'prep time': '10 minutes' } console.log(result.ingredients); // [ // { type: 'ingredient', name: 'flour', quantity: 2, units: 'cups' }, // { type: 'ingredient', name: 'sugar', quantity: 1, units: 'cup' }, // { type: 'ingredient', name: 'butter', quantity: 0.5, units: 'cup' } // ] console.log(result.cookwares); // [ // { type: 'cookware', name: 'oven', quantity: 1 }, // { type: 'cookware', name: 'mixing bowl', quantity: 'large' } // ] console.log(result.steps.length); // 3 console.log(result.shoppingList); // {} ``` -------------------------------- ### Parse Ingredient with Preparation Instructions Source: https://context7.com/cooklang/cooklang-ts/llms.txt Shows how to parse an ingredient that includes preparation instructions in parentheses. The Parser class must be imported. ```typescript import { Parser } from '@cooklang/cooklang-ts'; const parser = new Parser(); // Ingredient with preparation instructions const result5 = parser.parse('Add @garlic{3%cloves}(minced) to the pan.'); console.log(result5.ingredients); // [{ type: 'ingredient', name: 'garlic', quantity: 3, units: 'cloves', preparation: 'minced' }] ``` -------------------------------- ### Recipe Class Constructor Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/classes/Recipe.html Initializes a new Recipe object. It can be created with an optional Cooklang source string and parser options. ```APIDOC ## new Recipe(source?: string, options?: ParserOptions) ### Description Creates a new recipe from the supplied Cooklang string. If `source` is omitted, an empty recipe is created. ### Method constructor ### Parameters #### Optional Parameters - **source** (string) - The Cooklang string to parse. - **options** (ParserOptions) - The options to pass to the parser. ### Returns - **Recipe** - A new instance of the Recipe class. ``` -------------------------------- ### Run Tests Source: https://github.com/cooklang/cooklang-ts/blob/main/readme.md Execute the tests for Cooklang-TS using npm. Ensure your environment is set up with Node.js and npm. ```bash npm test ``` -------------------------------- ### Recipe Class Methods Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/classes/Recipe.html Documentation for the `toCooklang` method, which converts the recipe object back into a Cooklang formatted string. ```APIDOC ## toCooklang() ### Description Generates a Cooklang string from the recipe's metadata, steps, and shopping lists. ### Method toCooklang ### Returns - **string** - The generated Cooklang string. ``` -------------------------------- ### Classes Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/modules.html Core classes for interacting with Cooklang recipes. ```APIDOC ## Classes ### Parser * **Description**: A class for parsing Cooklang recipe content. ### Recipe * **Description**: Represents a parsed Cooklang recipe object. ``` -------------------------------- ### Parse Timers with Quantity and Units Source: https://context7.com/cooklang/cooklang-ts/llms.txt Demonstrates parsing timer syntax with quantities and units. Timers are embedded within steps and not collected separately. Requires importing the Parser class. ```typescript import { Parser } from '@cooklang/cooklang-ts'; const parser = new Parser(); // Timer with quantity and units const result = parser.parse(` Boil for ~{10%minutes}. Let rest for ~resting time{5%minutes}. Simmer ~{1%hour} until reduced. `); // Timers appear within step items console.log(result.steps[0]); // [ // { type: 'text', value: 'Boil for ' }, // { type: 'timer', name: '', quantity: 10, units: 'minutes' }, // { type: 'text', value: '.' } // ] console.log(result.steps[1]); // [ // { type: 'text', value: 'Let rest for ' }, // { type: 'timer', name: 'resting time', quantity: 5, units: 'minutes' }, // { type: 'text', value: '.' } // ] ``` -------------------------------- ### Serialize Recipe to Cooklang Format Source: https://context7.com/cooklang/cooklang-ts/llms.txt Demonstrates using the `toCooklang()` method of the `Recipe` class to serialize a recipe object back into Cooklang format. Useful for round-trip parsing or programmatic file generation. ```typescript import { Recipe } from '@cooklang/cooklang-ts'; // Create and modify a recipe const recipe = new Recipe(); // Set metadata recipe.metadata = { author: 'Home Chef', servings: '4', 'prep time': '15 minutes' }; // Define steps with ingredients and cookware recipe.steps = [ [ { type: 'text', value: 'Heat ' }, { type: 'ingredient', name: 'olive oil', quantity: 2, units: 'tbsp' }, { type: 'text', value: ' in a ' }, { type: 'cookware', name: 'large skillet', quantity: 1 }, { type: 'text', value: '.' } ], [ { type: 'text', value: 'Add ' }, { type: 'ingredient', name: 'garlic', quantity: 3, units: 'cloves' }, { type: 'text', value: ' and sauté for ' }, { type: 'timer', name: '', quantity: 2, units: 'minutes' }, { type: 'text', value: '.' } ] ]; // Generate Cooklang output const cooklang = recipe.toCooklang(); console.log(cooklang); // >> author: Home Chef // >> servings: 4 // >> prep time: 15 minutes // // Heat @olive oil{2%tbsp} in a #large skillet{1}. // // Add @garlic{3%cloves} and sauté for ~{2%minutes}. ``` -------------------------------- ### Create Recipe with Custom Parser Options Source: https://context7.com/cooklang/cooklang-ts/llms.txt Creates a Cooklang recipe using the Recipe class with custom parser options. This allows setting default ingredient amounts, default cookware amounts, and including step numbers in parsed items. ```typescript import { Recipe } from '@cooklang/cooklang-ts'; // Create recipe with custom parser options const source = ` Fry @eggs{} in a #pan{} for ~{3%minutes}. Add @salt and @pepper to taste. `; const recipe = new Recipe(source, { defaultIngredientAmount: 1, // Default: 'some' defaultCookwareAmount: 1, // Default: 1 includeStepNumber: true // Default: false }); console.log(recipe.ingredients); // [ // { type: 'ingredient', name: 'eggs', quantity: 1, units: '', step: 0 }, // { type: 'ingredient', name: 'salt', quantity: 1, units: '', step: 1 }, // { type: 'ingredient', name: 'pepper', quantity: 1, units: '', step: 1 } // ] // Step items include timers console.log(recipe.steps[0]); // [ // { type: 'text', value: 'Fry ' }, // { type: 'ingredient', name: 'eggs', quantity: 1, units: '', step: 0 }, // { type: 'text', value: ' in a ' }, // { type: 'cookware', name: 'pan', quantity: 1, step: 0 }, // { type: 'text', value: ' for ' }, // { type: 'timer', name: '', quantity: 3, units: 'minutes' }, // { type: 'text', value: '.' } // ] ``` -------------------------------- ### Generate Image URL for Recipe Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/modules.html Creates a URL for a recipe's image, optionally specifying the file extension and step number. Ensure the 'name' parameter is the base filename of the .cook file. ```typescript getImageURL('Baked Potato', { extension: 'jpg', step: 2 });// returns "Baked Potato.2.jpg" ``` -------------------------------- ### Parse Cooklang Recipe Source: https://github.com/cooklang/cooklang-ts/blob/main/readme.md Instantiate a Recipe object with a Cooklang source string to parse its content. This includes ingredients, cookwares, metadata, and steps. ```typescript import { Recipe, Parser, getImageURL } from '@cooklang/cooklang-ts'; const source = ` >> source: https://www.dinneratthezoo.com/wprm_print/6796 >> total time: 6 minutes >> servings: 2 Place the @apple juice{1,5%cups}, @banana{one sliced}, @frozen mixed berries{1,5%cups} and @vanilla greek yogurt{3/4%cup} in a #blender{}; blend until smooth. If the smoothie seems too thick, add a little more liquid (1/4 cup). Taste and add @honey{} if desired. Pour into two glasses and garnish with fresh berries and mint sprigs if desired. `; console.log(new Recipe(source)); ``` -------------------------------- ### Parse Cooklang Recipe Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/index.html Instantiate a Recipe object with a Cooklang source string to parse it. The parsed recipe object contains ingredients, cookwares, metadata, steps, and a shopping list. Use the Parser class for more granular control. ```typescript import { Recipe, Parser, getImageURL } from '@cooklang/cooklang-ts'; const source = `>> source: https://www.dinneratthezoo.com/wprm_print/6796>> total time: 6 minutes>> servings: 2Place the @apple juice{1,5%cups}, @banana{one sliced}, @frozen mixed berries{1,5%cups} and @vanilla greek yogurt{3/4%cup} in a #blender{}; blend until smooth. If the smoothie seems too thick, add a little more liquid (1/4 cup). Taste and add @honey{} if desired. Pour into two glasses and garnish with fresh berries and mint sprigs if desired.`; console.log(new Recipe(source)); ``` ```typescript console.log(new Parser().parse(source).metadata); ``` -------------------------------- ### Generate Image URL for Cooklang Recipe Source: https://github.com/cooklang/cooklang-ts/blob/main/readme.md Generate a URL for an image associated with a Cooklang recipe step. Requires the recipe name, step number, and desired file extension. ```typescript console.log(getImageURL('Mixed Berry Smoothie', { step: 1, extension: 'png' })); ``` -------------------------------- ### Parse Ingredient with Fractional Quantity Source: https://context7.com/cooklang/cooklang-ts/llms.txt Demonstrates parsing an ingredient where the quantity is a fraction, which is automatically converted to a decimal. Ensure the Parser is imported. ```typescript import { Parser } from '@cooklang/cooklang-ts'; const parser = new Parser(); // Fractions are automatically converted to decimals const result3 = parser.parse('Add @butter{1/4%cup}.'); console.log(result3.ingredients); // [{ type: 'ingredient', name: 'butter', quantity: 0.25, units: 'cup' }] ``` -------------------------------- ### Recipe Class Properties Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/classes/Recipe.html Details the properties available on a Recipe object, including cookwares, ingredients, metadata, shoppingList, and steps. ```APIDOC ### cookwares * **Type**: Cookware[] * **Default**: [] * **Description**: Stores cookware information associated with the recipe. ### ingredients * **Type**: Ingredient[] * **Default**: [] * **Description**: Stores ingredient information for the recipe. ### metadata * **Type**: Metadata * **Default**: {} * **Description**: Contains metadata related to the recipe. ### shoppingList * **Type**: ShoppingList * **Default**: {} * **Description**: Represents the shopping list generated from the recipe. ### steps * **Type**: Step[] * **Default**: [] * **Description**: An array of steps detailing the recipe's preparation. ``` -------------------------------- ### Type-Safe Recipe Handling with TypeScript Interfaces Source: https://context7.com/cooklang/cooklang-ts/llms.txt Illustrates how to use exported TypeScript interfaces from `@cooklang/cooklang-ts` for type-safe handling of recipe data, including ingredients and timers. ```typescript import { Recipe, Parser, Ingredient, Cookware, Timer, Text, Step, Metadata, ShoppingList, Item, ParserOptions, ParseResult, ImageURLOptions } from '@cooklang/cooklang-ts'; // Type-safe ingredient handling function summarizeIngredients(ingredients: Ingredient[]): string { return ingredients .map(ing => { const qty = typeof ing.quantity === 'number' ? ing.quantity.toString() : ing.quantity; return `${qty} ${ing.units} ${ing.name}`.trim(); }) .join(', '); } // Type-safe step processing function extractTimers(steps: Step[]): Timer[] { const timers: Timer[] = []; for (const step of steps) { for (const item of step) { if (item.type === 'timer') { timers.push(item); } } } return timers; } // Usage const recipe = new Recipe(` Mix @flour{2%cups} and @water{1%cup}. Knead for ~{10%minutes}. Let rise for ~{1%hour}. `); console.log(summarizeIngredients(recipe.ingredients)); // '2 cups flour, 1 cup water' console.log(extractTimers(recipe.steps)); // [ // { type: 'timer', name: '', quantity: 10, units: 'minutes' }, // { type: 'timer', name: '', quantity: 1, units: 'hour' } // ] ``` -------------------------------- ### Parse Single-Word Ingredient Syntax Source: https://context7.com/cooklang/cooklang-ts/llms.txt Illustrates parsing a simple ingredient without braces, where the default quantity 'some' is used. Requires importing the Parser class. ```typescript import { Parser } from '@cooklang/cooklang-ts'; const parser = new Parser(); // Single-word ingredient (no braces needed) const result1 = parser.parse('Add @salt and @pepper.'); console.log(result1.ingredients); // [ // { type: 'ingredient', name: 'salt', quantity: 'some', units: '' }, // { type: 'ingredient', name: 'pepper', quantity: 'some', units: '' } // ] ``` -------------------------------- ### Interfaces Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/modules.html Definitions for interfaces representing various components of a Cooklang recipe. ```APIDOC ## Interfaces ### Cookware * **Description**: Represents cookware used in a recipe. ### ImageURLOptions * **Description**: Options for generating image URLs. * **Properties**: * `extension` (string) - Optional - The file extension for the image. * `step` (number) - Optional - The specific step number for the image. ### Ingredient * **Description**: Represents an ingredient in a recipe. ### Item * **Description**: Represents an item within a shopping list category. ### ParseResult * **Description**: The result of parsing a Cooklang recipe. ### ParserOptions * **Description**: Options for configuring the parser. ### Text * **Description**: Represents plain text within a recipe step. ### Timer * **Description**: Represents a timer setting within a recipe step. ``` -------------------------------- ### Item Interface Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/interfaces/Item.html Represents a single item in a Cooklang shopping list. ```APIDOC ## Interface Item A shopping list item ### Hierarchy * Item ### Properties #### name name: string * Required * Defined in [cooklang.ts:64](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/cooklang.ts#L64) #### synonym synonym?: string * Optional * Defined in [cooklang.ts:65](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/cooklang.ts#L65) ``` -------------------------------- ### Generate Image URLs with getImageURL Source: https://context7.com/cooklang/cooklang-ts/llms.txt Utility function to generate image URLs for recipe photos based on the Cooklang specification. Supports custom step numbers and file extensions. ```typescript import { getImageURL } from '@cooklang/cooklang-ts'; // Basic usage - generates PNG URL for main recipe image const mainImage = getImageURL('Chocolate Cake'); console.log(mainImage); // 'Chocolate Cake.png' // With step number for step-specific images const step2Image = getImageURL('Chocolate Cake', { step: 2 }); console.log(step2Image); // 'Chocolate Cake.2.png' // With custom extension const jpgImage = getImageURL('Chocolate Cake', { extension: 'jpg' }); console.log(jpgImage); // 'Chocolate Cake.jpg' // Combined step and extension const step3Jpg = getImageURL('Chocolate Cake', { step: 3, extension: 'jpg' }); console.log(step3Jpg); // 'Chocolate Cake.3.jpg' ``` -------------------------------- ### Parse Shopping Lists with Cooklang-TS Source: https://context7.com/cooklang/cooklang-ts/llms.txt Demonstrates parsing a Cooklang recipe containing shopping list definitions. The shopping list is extracted into a structured object. ```typescript import { Parser } from '@cooklang/cooklang-ts'; const parser = new Parser(); const result = parser.parse(` >> title: Weekly Groceries Get ingredients for the week. [Dairy] milk cheese|cheddar butter [Produce] apples bananas spinach|baby spinach `); console.log(result.shoppingList); // { // 'Dairy': [ // { name: 'milk', synonym: '' }, // { name: 'cheese', synonym: 'cheddar' }, // { name: 'butter', synonym: '' } // ], // 'Produce': [ // { name: 'apples', synonym: '' }, // { name: 'bananas', synonym: '' }, // { name: 'spinach', synonym: 'baby spinach' } // ] // } ``` -------------------------------- ### Parse Multi-Word Ingredient with Quantity and Units Source: https://context7.com/cooklang/cooklang-ts/llms.txt Shows how to parse ingredients with multi-word names, specifying both quantity and units. The Parser class must be imported. ```typescript import { Parser } from '@cooklang/cooklang-ts'; const parser = new Parser(); // Multi-word ingredient with quantity and units const result2 = parser.parse('Add @chicken breast{500%g} to the pan.'); console.log(result2.ingredients); // [{ type: 'ingredient', name: 'chicken breast', quantity: 500, units: 'g' }] ``` -------------------------------- ### Parse Complete Recipe with Recipe Class Source: https://context7.com/cooklang/cooklang-ts/llms.txt Parses a full Cooklang recipe string including metadata, ingredients, and multiple steps using the Recipe class. Access extracted data like ingredients, cookwares, metadata, and steps. Serializes the recipe back to Cooklang format. ```typescript import { Recipe } from '@cooklang/cooklang-ts'; // Parse a complete recipe with metadata, ingredients, and multiple steps const source = ` >> source: https://example.com/smoothie-recipe >> total time: 6 minutes >> servings: 2 Place the @apple juice{1.5%cups}, @banana{one sliced}, @frozen mixed berries{1.5%cups} and @vanilla greek yogurt{3/4%cup} in a #blender{}; blend until smooth. Taste and add @honey{} if desired. Pour into two glasses and garnish with fresh berries. `; const recipe = new Recipe(source); // Access extracted ingredients console.log(recipe.ingredients); // [ // { type: 'ingredient', name: 'apple juice', quantity: 1.5, units: 'cups' }, // { type: 'ingredient', name: 'banana', quantity: 'one sliced', units: '' }, // { type: 'ingredient', name: 'frozen mixed berries', quantity: 1.5, units: 'cups' }, // { type: 'ingredient', name: 'vanilla greek yogurt', quantity: 0.75, units: 'cup' }, // { type: 'ingredient', name: 'honey', quantity: 'some', units: '' } // ] // Access cookware required console.log(recipe.cookwares); // [{ type: 'cookware', name: 'blender', quantity: 1 }] // Access recipe metadata console.log(recipe.metadata); // { // source: 'https://example.com/smoothie-recipe', // 'total time': '6 minutes', // servings: '2' // } // Access parsed steps (array of step items) console.log(recipe.steps.length); // 2 // Serialize back to Cooklang format const cooklangOutput = recipe.toCooklang(); console.log(cooklangOutput); ``` -------------------------------- ### Cookware Interface Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/interfaces/Cookware.html Defines the structure for cookware items within Cooklang recipes. ```APIDOC ## Interface Cookware ### Description A piece of cookware. See: [Cooklang Cookware](https://cooklang.org/docs/spec/#cookware) ### Properties #### name - **name** (string) - Required - The name of the cookware. #### quantity - **quantity** (string | number) - Required - The quantity of the cookware. #### step - **step** (number) - Optional - The step number in which this cookware is used. #### type - **type** (string) - Required - Must be "cookware". ### Example Request Body ```json { "name": "Saucepan", "quantity": 1, "type": "cookware" } ``` ### Example Success Response ```json { "name": "Saucepan", "quantity": 1, "type": "cookware" } ``` ``` -------------------------------- ### Parser Class Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/classes/Parser.html The Parser class is the main entry point for parsing Cooklang recipes. It can be instantiated with optional configuration options. ```APIDOC ## Parser Class ### Description The Parser class is responsible for parsing Cooklang recipe strings into structured data. ### Constructors #### constructor(options?: ParserOptions) * **Description**: Creates a new parser instance with the supplied options. * **Parameters**: * `options` (ParserOptions) - Optional. The parser's configuration options. * **Returns**: Parser - A new instance of the Parser class. ### Properties #### defaultCookwareAmount * **Type**: string | number * **Description**: The default amount for cookware. #### defaultIngredientAmount * **Type**: string | number * **Description**: The default amount for ingredients. #### defaultUnits * **Type**: string * **Default**: '' * **Description**: The default units to use. #### includeStepNumber * **Type**: boolean * **Description**: Whether to include step numbers in the parsed output. ### Methods #### parse(source: string) * **Description**: Parses a Cooklang string and returns the extracted metadata, steps, and shopping lists. * **Parameters**: * `source` (string) - Required. The Cooklang recipe string to parse. * **Returns**: ParseResult - An object containing the parsed recipe data. * **See**: [Cooklang Recipe Specification](https://cooklang.org/docs/spec/#the-cook-recipe-specification) ``` -------------------------------- ### Text Interface Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/interfaces/Text.html Details the structure and properties of the Text interface in Cooklang-TS. ```APIDOC ## Interface Text A piece of text ### Hierarchy * Text ### Properties * [type](Text.html#type) * [value](Text.html#value) ### type - **type**: "text" - **Description**: The type identifier for text elements. - **Defined in**: [cooklang.ts:42](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/cooklang.ts#L42) ### value - **value**: string - **Description**: The actual string content of the text. - **Defined in**: [cooklang.ts:43](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/cooklang.ts#L43) ``` -------------------------------- ### Parse Comments in Cooklang Recipes Source: https://context7.com/cooklang/cooklang-ts/llms.txt Shows how Cooklang handles single-line comments (`--`) and multi-line block comments (`[- ... -]`). Comments are excluded from the parsed output. Requires importing the Parser class. ```typescript import { Parser } from '@cooklang/cooklang-ts'; const parser = new Parser(); const result = parser.parse(` -- This is a single-line comment Add @flour{2%cups} to the bowl. [- This is a multi-line block comment -] Mix well with a #whisk{}. `); console.log(result.steps.length); // 2 (comments excluded) console.log(result.ingredients); // [{ type: 'ingredient', name: 'flour', quantity: 2, units: 'cups' }] console.log(result.cookwares); // [{ type: 'cookware', name: 'whisk', quantity: 1 }] ``` -------------------------------- ### Ingredient Interface Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/interfaces/Ingredient.html The Ingredient interface defines the structure for ingredients within a Cooklang recipe. ```APIDOC ## Interface Ingredient An ingredient see [Cooklang Ingredient](https://cooklang.org/docs/spec/#ingredients) ### Hierarchy * Ingredient ### Properties * [name](Ingredient.html#name) * [quantity](Ingredient.html#quantity) * [step](Ingredient.html#step) * [type](Ingredient.html#type) * [units](Ingredient.html#units) ## Property name name: string * Defined in [cooklang.ts:8](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/cooklang.ts#L8) ## Property quantity quantity: string | number * Defined in [cooklang.ts:9](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/cooklang.ts#L9) ## Property units units: string * Defined in [cooklang.ts:10](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/cooklang.ts#L10) ## Optional Property step step?: number * Defined in [cooklang.ts:11](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/cooklang.ts#L11) ## Property type type: "ingredient" * Defined in [cooklang.ts:7](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/cooklang.ts#L7) ``` -------------------------------- ### ImageURLOptions Interface Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/interfaces/ImageURLOptions.html The ImageURLOptions interface provides options for generating image URLs. ```APIDOC ## Interface ImageURLOptions ### Description Provides options for generating image URLs. ### Properties #### Optional extension - **extension** (string) - Optional - Specifies the image file extension. Allowed values: "png" or "jpg". #### Optional step - **step** (number) - Optional - Specifies a particular step for the image. ### Request Example ```json { "extension": "png", "step": 1 } ``` ### Response Example ```json { "extension": "png", "step": 1 } ``` ``` -------------------------------- ### getImageURL Function Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/modules.html Generates a URL for an image associated with a Cooklang recipe. This function can optionally include a specific step number and file extension. ```APIDOC ## getImageURL Function ### Description Creates a URL for an image of the the supplied recipe. ### Method GET (conceptual, as this is a utility function) ### Endpoint N/A (Client-side function) ### Parameters #### Query Parameters - **name** (string) - Required - The name of the .cook file. - **options** (ImageURLOptions) - Optional - The URL options, which can include `extension` (string) and `step` (number). ### Request Example ```javascript getImageURL('Baked Potato', { extension: 'jpg', step: 2 }); ``` ### Response #### Success Response (string) - **URL** (string) - The image URL for the given recipe and step. #### Response Example ``` "Baked Potato.2.jpg" ``` ### See Also [Cooklang Pictures Specification](https://cooklang.org/docs/spec/#adding-pictures) ``` -------------------------------- ### ParseResult Interface Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/interfaces/ParseResult.html This interface defines the structure of the parsed Cooklang recipe data. ```APIDOC ## Interface ParseResult ### Description Represents the structured output of parsing Cooklang text. ### Properties * **cookwares** (Cookware[]) - An array of cookware items used in the recipe. * **ingredients** (Ingredient[]) - An array of ingredients required for the recipe. * **metadata** (Metadata) - An object containing metadata about the recipe. * **shoppingList** (ShoppingList) - An object representing the generated shopping list. * **steps** (Step[]) - An array of steps detailing the cooking process. ``` -------------------------------- ### Parse Ingredient with Non-Numeric Quantity Source: https://context7.com/cooklang/cooklang-ts/llms.txt Illustrates parsing an ingredient where the quantity is a descriptive string, which is preserved as a string. The Parser class needs to be imported. ```typescript import { Parser } from '@cooklang/cooklang-ts'; const parser = new Parser(); // Non-numeric quantities preserved as strings const result4 = parser.parse('Add @onion{one large, diced}.'); console.log(result4.ingredients); // [{ type: 'ingredient', name: 'onion', quantity: 'one large, diced', units: '' }] ``` -------------------------------- ### ParserOptions Interface Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/interfaces/ParserOptions.html The ParserOptions interface defines the configurable settings for the Cooklang parser. ```APIDOC ## Interface ParserOptions ### Description Defines the configuration options for the Cooklang parser. ### Properties #### Optional defaultCookwareAmount - **Type**: `string | number` - **Description**: The default value to use for cookware amounts when none is specified. Defaults to 1. - **Defined in**: [Parser.ts:11](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/Parser.ts#L11) #### Optional defaultIngredientAmount - **Type**: `string | number` - **Description**: The default value to use for ingredient amounts when none is specified. Defaults to "some". - **Defined in**: [Parser.ts:12](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/Parser.ts#L12) #### Optional includeStepNumber - **Type**: `boolean` - **Description**: Determines whether to include the step number in ingredient and cookware nodes. Defaults to `false`. - **Defined in**: [Parser.ts:13](https://github.com/cooklang/cooklang-ts/blob/eed557f/src/Parser.ts#L13) ``` -------------------------------- ### Extract Metadata from Cooklang Recipe Source: https://github.com/cooklang/cooklang-ts/blob/main/readme.md Use the Parser class to parse a Cooklang source string and access its metadata. This is useful for retrieving information like source URL, total time, and servings. ```typescript console.log(new Parser().parse(source).metadata); ``` -------------------------------- ### Timer Interface Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/interfaces/Timer.html Represents a timer object within the Cooklang specification, used for timing ingredients or steps. ```APIDOC ## Interface Timer ### Description A timer object used in Cooklang recipes. ### Properties #### name `name?: string` An optional name for the timer. #### quantity `quantity: string | number` The numerical or string value representing the quantity for the timer. #### type `type: "timer"` Specifies the type of the object as a timer. #### units `units: string` The unit of time for the timer (e.g., "minutes", "hours"). ``` -------------------------------- ### Type Aliases Source: https://github.com/cooklang/cooklang-ts/blob/main/docs/modules.html Definitions for custom types used within the cooklang-ts library. ```APIDOC ## Type Aliases ### Metadata `type Metadata = Record` * **Description**: A recipe's metadata. * **See**: [Cooklang Metadata](https://cooklang.org/docs/spec/#metadata) ### ShoppingList `type ShoppingList = Record` * **Description**: A shopping list consisting of categories and their items. * **See**: [Cooklang Shopping List](https://cooklang.org/docs/spec/#the-shopping-list-specification) ### Step `type Step = (Ingredient | Cookware | Timer | Text)[]` * **Description**: A step consisting of multiple ingredients, cookware, timers, and text. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.