Final comment and removed duplicte code

Signed-off-by: Christian Wolf <github@christianwolf.email>
This commit is contained in:
Christian Wolf 2023-06-30 19:46:03 +02:00
Родитель 45166e09b0
Коммит d3feaec60b
2 изменённых файлов: 2 добавлений и 31 удалений

Просмотреть файл

@ -149,35 +149,6 @@ function notify(title, options) {
}
}
function validateIngredientSyntax(ingredient) {
/*
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
*/
const ingredientSyntaxRegExp = /^(?:\d+(?:\.\d+)?(?:\/\d+)?)\s?.*$/
// Regular expression to match all possible fractions within a string
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.
*/
const ingredientMultipleSeperatorsRegExp = /^-?\d+(?:[.,]\d+){2,}.*/
return (
ingredientSyntaxRegExp.test(ingredient) &&
!ingredientFractionRegExp.test(ingredient) &&
!ingredientMultipleSeperatorsRegExp.test(ingredient)
)
}
export default {
shouldReloadContent,
isSameItemInstance,
@ -188,5 +159,4 @@ export default {
useRouter,
goTo,
notify,
validateIngredientSyntax,
}

Просмотреть файл

@ -1,6 +1,7 @@
function isValidIngredientSyntax(ingredient) {
/*
Explanation of ingredientSyntaxRegExp:
*** 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.