@jclind/ingredient-parser 1.0.26 → 1.0.28
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,21 @@ 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
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 = (ingrStr.replace(parenRegex, '').substring(commaIndex + 1) +
|
|
18
|
+
textInParenthesesStr).trim();
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
ingrText = convertFractions(ingrStr.replace(parenRegex, '').trim());
|
|
22
|
+
comment = textInParenthesesStr.trim();
|
|
23
|
+
}
|
|
24
|
+
console.log(ingrText, comment, parenthesesStr);
|
|
16
25
|
const parsedIngrRes = parse(ingrText, 'eng');
|
|
17
26
|
if (!parsedIngrRes.ingredient) {
|
|
18
27
|
return { ...parsedIngrRes, originalIngredientString: ingrStr, comment };
|
package/package.json
CHANGED