mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-11-02 18:23:40 -05:00
feature/editor-improvements (#289)
* 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>
This commit is contained in:
42
dev/ingredientScaler/index.js
Normal file
42
dev/ingredientScaler/index.js
Normal file
@@ -0,0 +1,42 @@
|
||||
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,
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user