mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 15:49:42 +02:00
* pin editor buttons on scroll * scaler scratch * fix langauge assignment 1st pass * set lang on navigate * refactor/breakup router * unify style for language selectro * refactor/code-cleanup * refactor/page specific components to page folder * Fix time card layout issue * fix timecard display * update mobile cards / fix overflow errors Co-authored-by: hay-kot <hay-kot@pm.me>
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import { recipeIngredient } from "./recipeIngredient";
|
|
import { recipeNumber } from "./recipeNumber";
|
|
|
|
export const ingredientScaler = {
|
|
process(ingredientArray, scale) {
|
|
console.log(scale);
|
|
let workingArray = ingredientArray.map(x =>
|
|
ingredientScaler.markIngredient(x)
|
|
);
|
|
return workingArray.map(x => ingredientScaler.adjustIngredients(x, scale));
|
|
},
|
|
|
|
adjustIngredients(ingredient, scale) {
|
|
var scaledQuantity = new recipeNumber(ingredient.quantity).multiply(scale);
|
|
const newText = ingredient.text.replace(
|
|
ingredient.quantity,
|
|
scaledQuantity
|
|
);
|
|
return { ...ingredient, quantity: scaledQuantity, text: newText };
|
|
},
|
|
|
|
markIngredient(ingredient) {
|
|
console.log(ingredient);
|
|
const returnVar = ingredient.replace(
|
|
/^([\d/?[^\s&]*)(?: |\s)(\w*)/g,
|
|
(match, quantity, unit) => {
|
|
return `${unit}${quantity},${match}`;
|
|
}
|
|
);
|
|
const split = returnVar.split(",");
|
|
const [unit, quantity, match] = split;
|
|
console.log("Split", unit, quantity, match);
|
|
const n = new recipeNumber(quantity);
|
|
const i = new recipeIngredient(n, unit);
|
|
const serializedQuantity = n.isFraction() ? n.toImproperFraction() : n;
|
|
return {
|
|
unit: i,
|
|
quantity: serializedQuantity.toString(),
|
|
text: match,
|
|
};
|
|
},
|
|
};
|