@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.cjs
CHANGED
|
@@ -2487,7 +2487,7 @@ var Section = class {
|
|
|
2487
2487
|
};
|
|
2488
2488
|
|
|
2489
2489
|
// src/quantities/alternatives.ts
|
|
2490
|
-
var
|
|
2490
|
+
var import_big4 = __toESM(require("big.js"), 1);
|
|
2491
2491
|
|
|
2492
2492
|
// src/units/lookup.ts
|
|
2493
2493
|
function findListWithCompatibleQuantity(list, quantity) {
|
|
@@ -2510,7 +2510,40 @@ function findCompatibleQuantityWithinList(list, quantity) {
|
|
|
2510
2510
|
}
|
|
2511
2511
|
|
|
2512
2512
|
// src/utils/general.ts
|
|
2513
|
-
var
|
|
2513
|
+
var import_big3 = __toESM(require("big.js"), 1);
|
|
2514
|
+
var legacyDeepClone = (v) => {
|
|
2515
|
+
if (v === null || typeof v !== "object") {
|
|
2516
|
+
return v;
|
|
2517
|
+
}
|
|
2518
|
+
if (v instanceof import_big3.default) {
|
|
2519
|
+
return new import_big3.default(v);
|
|
2520
|
+
}
|
|
2521
|
+
if (v instanceof Map) {
|
|
2522
|
+
return new Map(
|
|
2523
|
+
Array.from(v.entries()).map(([k, val]) => [
|
|
2524
|
+
legacyDeepClone(k),
|
|
2525
|
+
legacyDeepClone(val)
|
|
2526
|
+
])
|
|
2527
|
+
);
|
|
2528
|
+
}
|
|
2529
|
+
if (v instanceof Set) {
|
|
2530
|
+
return new Set(
|
|
2531
|
+
Array.from(v).map((val) => legacyDeepClone(val))
|
|
2532
|
+
);
|
|
2533
|
+
}
|
|
2534
|
+
if (v instanceof Date) {
|
|
2535
|
+
return new Date(v.getTime());
|
|
2536
|
+
}
|
|
2537
|
+
if (Array.isArray(v)) {
|
|
2538
|
+
return v.map((item) => legacyDeepClone(item));
|
|
2539
|
+
}
|
|
2540
|
+
const cloned = {};
|
|
2541
|
+
for (const key of Object.keys(v)) {
|
|
2542
|
+
cloned[key] = legacyDeepClone(v[key]);
|
|
2543
|
+
}
|
|
2544
|
+
return cloned;
|
|
2545
|
+
};
|
|
2546
|
+
var deepClone = (v) => legacyDeepClone(v);
|
|
2514
2547
|
|
|
2515
2548
|
// src/quantities/alternatives.ts
|
|
2516
2549
|
function getEquivalentUnitsLists(...quantities) {
|
|
@@ -2736,7 +2769,7 @@ function regroupQuantitiesAndExpandEquivalents(sum, unitsLists, system) {
|
|
|
2736
2769
|
return main.reduce((acc, v) => {
|
|
2737
2770
|
const mainInList = findCompatibleQuantityWithinList(list, v);
|
|
2738
2771
|
const conversionRatio = getBaseUnitRatio(v, mainInList);
|
|
2739
|
-
const valueInOriginalUnit = (0,
|
|
2772
|
+
const valueInOriginalUnit = (0, import_big4.default)(getAverageValue(v.quantity)).times(
|
|
2740
2773
|
conversionRatio
|
|
2741
2774
|
);
|
|
2742
2775
|
const newValue = {
|
|
@@ -2748,7 +2781,7 @@ function regroupQuantitiesAndExpandEquivalents(sum, unitsLists, system) {
|
|
|
2748
2781
|
decimal: valueInOriginalUnit.toNumber()
|
|
2749
2782
|
}
|
|
2750
2783
|
},
|
|
2751
|
-
(0,
|
|
2784
|
+
(0, import_big4.default)(getAverageValue(equiv.quantity)).div(
|
|
2752
2785
|
getAverageValue(mainInList.quantity)
|
|
2753
2786
|
)
|
|
2754
2787
|
)
|
|
@@ -2832,7 +2865,7 @@ function recomputeEquivalents(primaries, ratioMap, equivUnits) {
|
|
|
2832
2865
|
}
|
|
2833
2866
|
|
|
2834
2867
|
// src/classes/recipe.ts
|
|
2835
|
-
var
|
|
2868
|
+
var import_big5 = __toESM(require("big.js"), 1);
|
|
2836
2869
|
var _Recipe = class _Recipe {
|
|
2837
2870
|
/**
|
|
2838
2871
|
* Creates a new Recipe instance.
|
|
@@ -3864,7 +3897,7 @@ var _Recipe = class _Recipe {
|
|
|
3864
3897
|
if (originalServings === void 0 || originalServings === 0) {
|
|
3865
3898
|
originalServings = 1;
|
|
3866
3899
|
}
|
|
3867
|
-
const factor = (0,
|
|
3900
|
+
const factor = (0, import_big5.default)(newServings).div(originalServings);
|
|
3868
3901
|
return this.scaleBy(factor);
|
|
3869
3902
|
}
|
|
3870
3903
|
/**
|
|
@@ -3883,7 +3916,7 @@ var _Recipe = class _Recipe {
|
|
|
3883
3916
|
function scaleAlternativesBy(alternatives, factor2) {
|
|
3884
3917
|
for (const alternative of alternatives) {
|
|
3885
3918
|
if (alternative.quantity) {
|
|
3886
|
-
const scaleFactor = alternative.scalable ? (0,
|
|
3919
|
+
const scaleFactor = alternative.scalable ? (0, import_big5.default)(factor2) : 1;
|
|
3887
3920
|
if (alternative.quantity.type !== "fixed" || alternative.quantity.value.type !== "text") {
|
|
3888
3921
|
alternative.quantity = multiplyQuantityValue(
|
|
3889
3922
|
alternative.quantity,
|
|
@@ -3956,10 +3989,10 @@ var _Recipe = class _Recipe {
|
|
|
3956
3989
|
arbitrary.unit = optimized.unit;
|
|
3957
3990
|
}
|
|
3958
3991
|
newRecipe._populateIngredientQuantities();
|
|
3959
|
-
newRecipe.servings = (0,
|
|
3992
|
+
newRecipe.servings = (0, import_big5.default)(originalServings).times(factor).toNumber();
|
|
3960
3993
|
for (const metaVar of ["servings", "serves"]) {
|
|
3961
3994
|
if (typeof newRecipe.metadata[metaVar] === "number") {
|
|
3962
|
-
newRecipe.metadata[metaVar] = (0,
|
|
3995
|
+
newRecipe.metadata[metaVar] = (0, import_big5.default)(newRecipe.metadata[metaVar]).times(factor).toNumber();
|
|
3963
3996
|
}
|
|
3964
3997
|
}
|
|
3965
3998
|
if (newRecipe.metadata.yield && this.metadata.yield) {
|