You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library supports parsing ingredients in multiple languages through configurable keyword options. While unit names can be localized using `additionalUOMs`, the following options allow localization of parsing keywords and quantities.
262
+
226
263
### `decimalSeparator`
227
264
228
265
The character used as a decimal separator in numeric quantities. Use `','` for European-style decimal commas (e.g., `'1,5'` for 1.5). Defaults to `'.'`.
Patterns to identify group headers (e.g., "For the icing:"). Strings are treated as prefix patterns matched at the start of the line followed by whitespace. RegExp patterns are used as-is for more complex matching. Defaults to `['For']`.
284
+
285
+
```js
286
+
// German group headers
287
+
parseIngredient('Für den Teig:\n2 cups flour', {
288
+
groupHeaderPatterns: ['For', 'Für'],
289
+
});
290
+
// [
291
+
// { description: 'Für den Teig:', isGroupHeader: true, ... },
// French with regex pattern (matches "Pour la", "Pour le", "Pour un", etc.)
296
+
parseIngredient('Pour la pâte:', {
297
+
groupHeaderPatterns: ['For',/^Pour\s/iu],
298
+
});
299
+
```
300
+
301
+
### `rangeSeparators`
302
+
303
+
Words or patterns to identify ranges between quantities (e.g., "1 to 2", "1 or 2"). Dash characters (-, –, —) are always recognized. Defaults to `['to', 'or']`.
304
+
305
+
```js
306
+
// German range separators
307
+
parseIngredient('1 bis 2 cups flour', {
308
+
rangeSeparators: ['to', 'or', 'bis', 'oder'],
309
+
});
310
+
// [{ quantity: 1, quantity2: 2, ... }]
311
+
312
+
// French range separator
313
+
parseIngredient('2 à 3 cups sugar', {
314
+
rangeSeparators: ['to', 'or', 'à', 'ou'],
315
+
});
316
+
```
317
+
318
+
### `descriptionStripPrefixes`
319
+
320
+
Words or patterns to strip from the beginning of ingredient descriptions. Commonly used to remove "of" from phrases like "1 cup of sugar". Strings are matched as whole words followed by whitespace. RegExp patterns are used as-is, which is useful for languages with contractions or elisions. Defaults to `['of']`.
321
+
322
+
> **Note:** This option is only applied when `allowLeadingOf` is `false` (the default). If `allowLeadingOf` is `true`, prefix stripping is disabled entirely and this option is ignored.
323
+
324
+
```js
325
+
// Spanish "de" stripping
326
+
parseIngredient('2 tazas de azúcar', {
327
+
descriptionStripPrefixes: ['of', 'de'],
328
+
});
329
+
// [{ description: 'azúcar', ... }]
330
+
331
+
// French with regex patterns for elisions/contractions
0 commit comments