From fbb1b62dcb196b2e7230206825654f1064a943b9 Mon Sep 17 00:00:00 2001 From: Johannes Roth Date: Fri, 30 Jun 2023 22:29:18 +0200 Subject: [PATCH 01/10] Fix yieldCalculator parseFloat problem Signed-off-by: Johannes Roth --- src/js/yieldCalculator.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/yieldCalculator.js b/src/js/yieldCalculator.js index f0d2ed71f..1fa9fe0e2 100644 --- a/src/js/yieldCalculator.js +++ b/src/js/yieldCalculator.js @@ -39,7 +39,9 @@ function recalculateIngredients(ingredients, currentYield, originalYield) { const possibleUnit = ingredient .split(" ")[0] .replace(/[^a-zA-Z]/g, "") - const amount = parseFloat(ingredients[index].split(" ")[0]) + const amount = parseFloat( + ingredients[index].split(" ")[0].replace(",", ".") + ) const unitAndIngredient = ingredient.split(" ").slice(1).join(" ") let newAmount = (amount / originalYield) * currentYield newAmount = newAmount.toFixed(2).replace(/[.]00$/, "") From 8ab5c448b70791429c821ba5949018004e1788ab Mon Sep 17 00:00:00 2001 From: Johannes Roth Date: Fri, 30 Jun 2023 22:34:47 +0200 Subject: [PATCH 02/10] Fix yieldCalculator comments of regex expressions Signed-off-by: Johannes Roth --- src/js/yieldCalculator.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/js/yieldCalculator.js b/src/js/yieldCalculator.js index 1fa9fe0e2..49595e0d5 100644 --- a/src/js/yieldCalculator.js +++ b/src/js/yieldCalculator.js @@ -1,23 +1,21 @@ function isValidIngredientSyntax(ingredient) { /* - *** Outdated!!! *** - Explanation of ingredientSyntaxRegExp: - ^: Start of string - (?:\d+(?:\.\d+)?|\.\d+): Non-capturing group that matches either a positive float value or a positive integer value. The first alternative matches one or more digits, followed by an optional decimal part consisting of a dot and one or more digits. The second alternative matches a decimal point followed by one or more digits. - (?:\s.+$|\s\S+$): Non-capturing group that matches a whitespace character followed by any character with unlimited length or any special character with unlimited length. The first alternative matches a whitespace character followed by any character(s) until the end of the string. The second alternative matches a whitespace character followed by any non-whitespace character(s) until the end of the string. - $: End of string + The ingredientSyntaxRegExp checks whether the ingredient string starts with a number, + possibly followed by a fractional part or a fraction. Then there should be a space + and then any sequence of characters. */ const ingredientSyntaxRegExp = /^(?:\d+(?:\.\d+)?(?:\/\d+)?)\s?.*$/ - // Regular expression to match all possible fractions within a string + + /* + The ingredientFractionRegExp is used to identify fractions in the string. + This is used to exclude strings that contain fractions from being valid. + */ const ingredientFractionRegExp = /\b\d+\/\d+\b/g + /* - Explanation of ingredientMultipleSeperatorsRegExp: - /^ - Start of the string - -? - Matches an optional minus sign - \d+ - Matches one or more digits - (?:[.,]\d+){2,} - Non-capturing group that matches a separator (.,) followed by one or more digits. - The {2,} quantifier ensures that there are at least two occurrences of this pattern. - .* - Matches any characters (except newline) zero or more times. + The ingredientMultipleSeperatorsRegExp is used to check whether the string contains + more than one separators (.,) after a number. This is used to exclude strings that + contain more than one separator from being valid. */ const ingredientMultipleSeperatorsRegExp = /^-?\d+(?:[.,]\d+){2,}.*/ From ffc3277a3d539a95a99a233071c3cf59217dc301 Mon Sep 17 00:00:00 2001 From: Johannes Roth Date: Fri, 30 Jun 2023 22:38:32 +0200 Subject: [PATCH 03/10] Add width to yieldInput Signed-off-by: Johannes Roth --- src/components/RecipeView.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/RecipeView.vue b/src/components/RecipeView.vue index a6f08a943..ca84157b0 100644 --- a/src/components/RecipeView.vue +++ b/src/components/RecipeView.vue @@ -77,6 +77,7 @@ v-model="recipeYield" type="number" min="0" + style="width: 65px;" />