1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-24 15:49:42 +02:00

feat: Improved recipeYield Parsing For Fractions and Decimals (#2507)

* improved recipeYield parsing for fracs/decimals

* added fix for edgecase with weird fractions

* made typescript happy

* lint

* extracted yield calculation into composable

* fixed some gross edgecases

* added tests

* made bare return clearer

---------

Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
This commit is contained in:
Michael Genson 2023-08-21 09:54:02 -05:00 committed by GitHub
parent c60c63852b
commit e24e28ae03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 247 additions and 20 deletions

View file

@ -33,6 +33,8 @@ import RecipeRating from "~/components/Domain/Recipe/RecipeRating.vue";
import { NoUndefinedField } from "~/lib/api/types/non-generated";
import { Recipe } from "~/lib/api/types/recipe";
import { usePageState } from "~/composables/recipe-page/shared-state";
import { useExtractRecipeYield } from "~/composables/recipe-page/use-extract-recipe-yield";
export default defineComponent({
components: {
RecipeScaleEditButton,
@ -65,29 +67,11 @@ export default defineComponent({
});
const scaledYield = computed(() => {
const regMatchNum = /\d+/;
const yieldString = props.recipe.recipeYield;
const num = yieldString?.match(regMatchNum);
if (num && num?.length > 0) {
const yieldAsInt = parseInt(num[0]);
return yieldString?.replace(num[0], String(yieldAsInt * scaleValue.value));
}
return props.recipe.recipeYield;
return useExtractRecipeYield(props.recipe.recipeYield, scaleValue.value);
});
const basicYield = computed(() => {
const regMatchNum = /\d+/;
const yieldString = props.recipe.recipeYield;
const num = yieldString?.match(regMatchNum);
if (num && num?.length > 0) {
const yieldAsInt = parseInt(num[0]);
return yieldString?.replace(num[0], String(yieldAsInt));
}
return props.recipe.recipeYield;
return useExtractRecipeYield(props.recipe.recipeYield, 1);
});
return {