@tmlmt/cooklang-parser 3.0.0-alpha.20 → 3.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +42 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +42 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2428,7 +2428,7 @@ var Section = class {
|
|
|
2428
2428
|
};
|
|
2429
2429
|
|
|
2430
2430
|
// src/quantities/alternatives.ts
|
|
2431
|
-
import
|
|
2431
|
+
import Big4 from "big.js";
|
|
2432
2432
|
|
|
2433
2433
|
// src/units/lookup.ts
|
|
2434
2434
|
function findListWithCompatibleQuantity(list, quantity) {
|
|
@@ -2451,7 +2451,40 @@ function findCompatibleQuantityWithinList(list, quantity) {
|
|
|
2451
2451
|
}
|
|
2452
2452
|
|
|
2453
2453
|
// src/utils/general.ts
|
|
2454
|
-
|
|
2454
|
+
import Big3 from "big.js";
|
|
2455
|
+
var legacyDeepClone = (v) => {
|
|
2456
|
+
if (v === null || typeof v !== "object") {
|
|
2457
|
+
return v;
|
|
2458
|
+
}
|
|
2459
|
+
if (v instanceof Big3) {
|
|
2460
|
+
return new Big3(v);
|
|
2461
|
+
}
|
|
2462
|
+
if (v instanceof Map) {
|
|
2463
|
+
return new Map(
|
|
2464
|
+
Array.from(v.entries()).map(([k, val]) => [
|
|
2465
|
+
legacyDeepClone(k),
|
|
2466
|
+
legacyDeepClone(val)
|
|
2467
|
+
])
|
|
2468
|
+
);
|
|
2469
|
+
}
|
|
2470
|
+
if (v instanceof Set) {
|
|
2471
|
+
return new Set(
|
|
2472
|
+
Array.from(v).map((val) => legacyDeepClone(val))
|
|
2473
|
+
);
|
|
2474
|
+
}
|
|
2475
|
+
if (v instanceof Date) {
|
|
2476
|
+
return new Date(v.getTime());
|
|
2477
|
+
}
|
|
2478
|
+
if (Array.isArray(v)) {
|
|
2479
|
+
return v.map((item) => legacyDeepClone(item));
|
|
2480
|
+
}
|
|
2481
|
+
const cloned = {};
|
|
2482
|
+
for (const key of Object.keys(v)) {
|
|
2483
|
+
cloned[key] = legacyDeepClone(v[key]);
|
|
2484
|
+
}
|
|
2485
|
+
return cloned;
|
|
2486
|
+
};
|
|
2487
|
+
var deepClone = (v) => legacyDeepClone(v);
|
|
2455
2488
|
|
|
2456
2489
|
// src/quantities/alternatives.ts
|
|
2457
2490
|
function getEquivalentUnitsLists(...quantities) {
|
|
@@ -2677,7 +2710,7 @@ function regroupQuantitiesAndExpandEquivalents(sum, unitsLists, system) {
|
|
|
2677
2710
|
return main.reduce((acc, v) => {
|
|
2678
2711
|
const mainInList = findCompatibleQuantityWithinList(list, v);
|
|
2679
2712
|
const conversionRatio = getBaseUnitRatio(v, mainInList);
|
|
2680
|
-
const valueInOriginalUnit =
|
|
2713
|
+
const valueInOriginalUnit = Big4(getAverageValue(v.quantity)).times(
|
|
2681
2714
|
conversionRatio
|
|
2682
2715
|
);
|
|
2683
2716
|
const newValue = {
|
|
@@ -2689,7 +2722,7 @@ function regroupQuantitiesAndExpandEquivalents(sum, unitsLists, system) {
|
|
|
2689
2722
|
decimal: valueInOriginalUnit.toNumber()
|
|
2690
2723
|
}
|
|
2691
2724
|
},
|
|
2692
|
-
|
|
2725
|
+
Big4(getAverageValue(equiv.quantity)).div(
|
|
2693
2726
|
getAverageValue(mainInList.quantity)
|
|
2694
2727
|
)
|
|
2695
2728
|
)
|
|
@@ -2773,7 +2806,7 @@ function recomputeEquivalents(primaries, ratioMap, equivUnits) {
|
|
|
2773
2806
|
}
|
|
2774
2807
|
|
|
2775
2808
|
// src/classes/recipe.ts
|
|
2776
|
-
import
|
|
2809
|
+
import Big5 from "big.js";
|
|
2777
2810
|
var _Recipe = class _Recipe {
|
|
2778
2811
|
/**
|
|
2779
2812
|
* Creates a new Recipe instance.
|
|
@@ -3805,7 +3838,7 @@ var _Recipe = class _Recipe {
|
|
|
3805
3838
|
if (originalServings === void 0 || originalServings === 0) {
|
|
3806
3839
|
originalServings = 1;
|
|
3807
3840
|
}
|
|
3808
|
-
const factor =
|
|
3841
|
+
const factor = Big5(newServings).div(originalServings);
|
|
3809
3842
|
return this.scaleBy(factor);
|
|
3810
3843
|
}
|
|
3811
3844
|
/**
|
|
@@ -3824,7 +3857,7 @@ var _Recipe = class _Recipe {
|
|
|
3824
3857
|
function scaleAlternativesBy(alternatives, factor2) {
|
|
3825
3858
|
for (const alternative of alternatives) {
|
|
3826
3859
|
if (alternative.quantity) {
|
|
3827
|
-
const scaleFactor = alternative.scalable ?
|
|
3860
|
+
const scaleFactor = alternative.scalable ? Big5(factor2) : 1;
|
|
3828
3861
|
if (alternative.quantity.type !== "fixed" || alternative.quantity.value.type !== "text") {
|
|
3829
3862
|
alternative.quantity = multiplyQuantityValue(
|
|
3830
3863
|
alternative.quantity,
|
|
@@ -3897,10 +3930,10 @@ var _Recipe = class _Recipe {
|
|
|
3897
3930
|
arbitrary.unit = optimized.unit;
|
|
3898
3931
|
}
|
|
3899
3932
|
newRecipe._populateIngredientQuantities();
|
|
3900
|
-
newRecipe.servings =
|
|
3933
|
+
newRecipe.servings = Big5(originalServings).times(factor).toNumber();
|
|
3901
3934
|
for (const metaVar of ["servings", "serves"]) {
|
|
3902
3935
|
if (typeof newRecipe.metadata[metaVar] === "number") {
|
|
3903
|
-
newRecipe.metadata[metaVar] =
|
|
3936
|
+
newRecipe.metadata[metaVar] = Big5(newRecipe.metadata[metaVar]).times(factor).toNumber();
|
|
3904
3937
|
}
|
|
3905
3938
|
}
|
|
3906
3939
|
if (newRecipe.metadata.yield && this.metadata.yield) {
|