mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-02 20:15:24 +02:00
feat: Structured Yields (#4489)
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
parent
c8cd68b4f0
commit
327da02fc8
39 changed files with 1018 additions and 551 deletions
32
frontend/composables/recipes/use-scaled-amount.ts
Normal file
32
frontend/composables/recipes/use-scaled-amount.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { useFraction } from "~/composables/recipes";
|
||||
|
||||
function formatQuantity(val: number): string {
|
||||
if (Number.isInteger(val)) {
|
||||
return val.toString();
|
||||
}
|
||||
|
||||
const { frac } = useFraction();
|
||||
|
||||
let valString = "";
|
||||
const fraction = frac(val, 10, true);
|
||||
|
||||
if (fraction[0] !== undefined && fraction[0] > 0) {
|
||||
valString += fraction[0];
|
||||
}
|
||||
|
||||
if (fraction[1] > 0) {
|
||||
valString += `<sup>${fraction[1]}</sup><span>⁄</span><sub>${fraction[2]}</sub>`;
|
||||
}
|
||||
|
||||
return valString.trim();
|
||||
}
|
||||
|
||||
export function useScaledAmount(amount: number, scale = 1) {
|
||||
const scaledAmount = Number(((amount || 0) * scale).toFixed(3));
|
||||
const scaledAmountDisplay = scaledAmount ? formatQuantity(scaledAmount) : "";
|
||||
|
||||
return {
|
||||
scaledAmount,
|
||||
scaledAmountDisplay,
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue