Skip to content

@tmlmt/cooklang-parser / CategoryConfig

Class: CategoryConfig ​

Parser for category configurations specified à-la-cooklang.

Usage ​

You can either directly provide the category configuration string when creating the instance e.g. const categoryConfig = new CategoryConfig(<...>), or create it first and then pass the category configuration string to the parse() method.

The initialized CategoryConfig can then be fed to a ShoppingList

Example ​

typescript
import { CategoryConfig } from @tmlmt/cooklang-parser;

const categoryConfigString = `
[Dairy]
milk
butter

[Bakery]
flour
sugar`;

const categoryConfig = new CategoryConfig(categoryConfigString);

See ​

Category Configuration section of the cooklang specs

Constructors ​

Constructor ​

new CategoryConfig(config?): CategoryConfig

Creates a new CategoryConfig instance.

Parameters ​

config? ​

string

The category configuration to parse.

Returns ​

CategoryConfig

Properties ​

categories ​

categories: Category[] = []

The parsed categories of ingredients.

Methods ​

parse() ​

parse(config): void

Parses a category configuration from a string into property categories

Parameters ​

config ​

string

The category configuration to parse.

Returns ​

void