@jclind/ingredient-parser 1.0.26 → 1.0.27

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.
@@ -7,12 +7,24 @@ export const parseIngredientString = (ingrStr) => {
7
7
  // Find the index of the first ',' character
8
8
  const commaIndex = ingrStr.indexOf(',');
9
9
  // Extract the text inside the parentheses and the text before the first comma using regular expressions
10
- const textInParentheses = ingrStr.match(parenRegex)?.[1] ?? '';
11
- const comment = ingrStr
12
- .replace(parenRegex, '')
13
- .substring(commaIndex + 1)
14
- .trim() + ` (${textInParentheses})`;
15
- const ingrText = convertFractions(ingrStr.match(commaRegex)?.[1] ?? '');
10
+ const parenthesesStr = ingrStr.match(parenRegex)?.[1] ?? '';
11
+ const textInParenthesesStr = parenthesesStr ? ` (${parenthesesStr})` : '';
12
+ let ingrText;
13
+ let comment;
14
+ // If there is no comma in the string don't include a comment
15
+ if (commaIndex !== -1) {
16
+ ingrText = convertFractions(ingrStr.substring(0, commaIndex).replace(parenRegex, ''));
17
+ comment =
18
+ ingrStr
19
+ .replace(parenRegex, '')
20
+ .substring(commaIndex + 1)
21
+ .trim() + textInParenthesesStr;
22
+ }
23
+ else {
24
+ ingrText = convertFractions(ingrStr.replace(parenRegex, '').trim());
25
+ comment = textInParenthesesStr;
26
+ }
27
+ console.log(comment);
16
28
  const parsedIngrRes = parse(ingrText, 'eng');
17
29
  if (!parsedIngrRes.ingredient) {
18
30
  return { ...parsedIngrRes, originalIngredientString: ingrStr, comment };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jclind/ingredient-parser",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "Parses given sentence including ingredient information and attemps to return quantity, measurement and ingredient data",
5
5
  "keywords": [
6
6
  "recipe",