@recipe-book/core 0.0.1 → 0.0.2
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/{chunk-2WUP3JQY.mjs → chunk-3FFMHRB7.mjs} +3 -2
- package/dist/{chunk-IEYO4T4T.mjs → chunk-4EHNJLGI.mjs} +9 -8
- package/dist/chunk-4IA5EEKI.mjs +81 -0
- package/dist/chunk-4TATADPT.mjs +51 -0
- package/dist/chunk-6GI5KLI4.mjs +22 -0
- package/dist/chunk-6YYQ4RYZ.mjs +26 -0
- package/dist/chunk-7BBUDI2L.mjs +0 -0
- package/dist/chunk-7KEMNCV7.mjs +26 -0
- package/dist/chunk-7MMJZZ7Z.mjs +75 -0
- package/dist/chunk-BES4V7DM.mjs +26 -0
- package/dist/{chunk-OBJ5JUVG.mjs → chunk-BRDXRIAH.mjs} +5 -4
- package/dist/chunk-CFR2ZBPB.mjs +77 -0
- package/dist/chunk-DYMNVFL2.mjs +78 -0
- package/dist/{chunk-NJQRYZC2.mjs → chunk-F6AQKXJU.mjs} +7 -4
- package/dist/chunk-FW4M2R43.mjs +51 -0
- package/dist/chunk-GCCEDUST.mjs +75 -0
- package/dist/chunk-GE7KBYZR.mjs +26 -0
- package/dist/chunk-GN7ZDGYC.mjs +51 -0
- package/dist/chunk-GOO2SCQX.mjs +75 -0
- package/dist/chunk-HAVKBQLH.mjs +51 -0
- package/dist/chunk-HCBIPANU.mjs +50 -0
- package/dist/chunk-IEBAGBS7.mjs +51 -0
- package/dist/chunk-IQ6WN2V4.mjs +75 -0
- package/dist/chunk-JB4Z2FR7.mjs +77 -0
- package/dist/chunk-JMTQOTBM.mjs +75 -0
- package/dist/{chunk-JPGZ2MYF.mjs → chunk-JRO6JUES.mjs} +9 -6
- package/dist/chunk-KH3SRXET.mjs +52 -0
- package/dist/chunk-KNZMCAQZ.mjs +51 -0
- package/dist/chunk-LEBGCVCJ.mjs +75 -0
- package/dist/chunk-MAHWFCIL.mjs +51 -0
- package/dist/chunk-MPH76SLC.mjs +51 -0
- package/dist/chunk-MQGMFBJQ.mjs +26 -0
- package/dist/chunk-NMIVG7T4.mjs +6 -0
- package/dist/chunk-Q3TT3AZ4.mjs +26 -0
- package/dist/chunk-QY5HJQIL.mjs +51 -0
- package/dist/chunk-RCPLSNKM.mjs +1 -0
- package/dist/chunk-UQ3EUYFR.mjs +1 -0
- package/dist/chunk-WSW6FMUL.mjs +51 -0
- package/dist/chunk-WU55SBIV.mjs +75 -0
- package/dist/chunk-XINK45P3.mjs +51 -0
- package/dist/chunk-XNOHIWI3.mjs +1 -0
- package/dist/chunk-YHBXEVUX.mjs +51 -0
- package/dist/chunk-YSZSCEI7.mjs +75 -0
- package/dist/const/conversion.d.mts +2 -2
- package/dist/const/conversion.d.ts +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/ingredient.d.mts +3 -2
- package/dist/lib/ingredient.d.ts +3 -2
- package/dist/lib/ingredient.js +1 -1
- package/dist/lib/ingredient.mjs +1 -1
- package/dist/lib/recipe.d.mts +4 -2
- package/dist/lib/recipe.d.ts +4 -2
- package/dist/lib/recipe.js +1 -1
- package/dist/lib/recipe.mjs +1 -1
- package/dist/lib/unit.d.mts +5 -4
- package/dist/lib/unit.d.ts +5 -4
- package/dist/lib/unit.js +1 -1
- package/dist/lib/unit.mjs +1 -1
- package/dist/types.d.mts +17 -12
- package/dist/types.d.ts +17 -12
- package/dist/types.js +1 -1
- package/package.json +6 -4
- package/dist/chunk-4AN32V3Z.mjs +0 -1
- package/dist/chunk-5ZCZ6LQB.mjs +0 -1
- package/dist/chunk-BOG6H6FE.mjs +0 -1
- package/dist/chunk-CEPTOQUR.mjs +0 -1
- package/dist/chunk-EKLUF5ED.mjs +0 -1
- package/dist/chunk-LLHRB3T7.mjs +0 -1
- package/dist/chunk-MUILH2IA.mjs +0 -1
- package/dist/chunk-YHBHNGQX.mjs +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VOLUME_CONVERSION_TABLE,
|
|
3
|
+
WEIGHT_CONVERSION_TABLE
|
|
4
|
+
} from "./chunk-V26OCCTL.mjs";
|
|
5
|
+
import {
|
|
6
|
+
UNITS
|
|
7
|
+
} from "./chunk-YZB3IG47.mjs";
|
|
8
|
+
import {
|
|
9
|
+
assert
|
|
10
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
11
|
+
|
|
12
|
+
// src/lib/unit.ts
|
|
13
|
+
var UnitUtilsImpl = class {
|
|
14
|
+
getUnit(unit) {
|
|
15
|
+
const match = UNITS.find((u) => u.abbreviation === unit || u.name === unit);
|
|
16
|
+
assert(match, (match2) => !!match2, `No unit found for key: ${unit}`);
|
|
17
|
+
return match;
|
|
18
|
+
}
|
|
19
|
+
getConversionRatio(from, to) {
|
|
20
|
+
const { type, abbreviation } = this.getUnit(from);
|
|
21
|
+
const conversionTable = type === "volume" ? VOLUME_CONVERSION_TABLE : WEIGHT_CONVERSION_TABLE;
|
|
22
|
+
const lookupTable = conversionTable[abbreviation];
|
|
23
|
+
const toUnit = to === "metric" ? type === "volume" ? "L" : "g" : to;
|
|
24
|
+
assert(
|
|
25
|
+
lookupTable,
|
|
26
|
+
(lookupTable2) => !!lookupTable2[to],
|
|
27
|
+
`No conversion table available for unit ${from} to ${to}`
|
|
28
|
+
);
|
|
29
|
+
return lookupTable[to];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Converts a number from one unit to another
|
|
33
|
+
*
|
|
34
|
+
* @param amount - The amount to convert
|
|
35
|
+
* @param from - The unit to convert from
|
|
36
|
+
* @param to - The unit to convert to
|
|
37
|
+
* @returns - The converted amount
|
|
38
|
+
*/
|
|
39
|
+
convert(amount, from, to) {
|
|
40
|
+
if (from === to) {
|
|
41
|
+
return amount;
|
|
42
|
+
}
|
|
43
|
+
const ratio = this.getConversionRatio(from, to);
|
|
44
|
+
return amount * ratio;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var UnitUtils = new UnitUtilsImpl();
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
UnitUtils
|
|
51
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
warn
|
|
3
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
4
|
+
import {
|
|
5
|
+
IS_DEV
|
|
6
|
+
} from "./chunk-XV4QN4LA.mjs";
|
|
7
|
+
|
|
8
|
+
// src/lib/recipe.ts
|
|
9
|
+
var RecipeUtilsImpl = class {
|
|
10
|
+
scopedMessageFactory(recipe) {
|
|
11
|
+
return (message) => `${recipe.name}: ${message}`;
|
|
12
|
+
}
|
|
13
|
+
validateConfig(config) {
|
|
14
|
+
if (!IS_DEV) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const msg = this.scopedMessageFactory(config);
|
|
18
|
+
warn(
|
|
19
|
+
config.instructions,
|
|
20
|
+
(instructions) => instructions.length > 0,
|
|
21
|
+
msg("Recipe has no instructions")
|
|
22
|
+
);
|
|
23
|
+
warn(
|
|
24
|
+
config.serves,
|
|
25
|
+
(serves) => serves === void 0 || serves > 0,
|
|
26
|
+
msg("Recipe serves less than 1 person")
|
|
27
|
+
);
|
|
28
|
+
warn(
|
|
29
|
+
config.ingredients,
|
|
30
|
+
(ingredients) => ingredients.length > 0,
|
|
31
|
+
msg("Recipe has no ingredients")
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
determineMeasurementSystem(config) {
|
|
35
|
+
const { ingredients } = config;
|
|
36
|
+
const hasMetric = ingredients.some(
|
|
37
|
+
(ingredient) => {
|
|
38
|
+
var _a;
|
|
39
|
+
return (_a = ingredient.conversion) == null ? void 0 : _a.metric;
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
const hasImperial = ingredients.some(
|
|
43
|
+
(ingredient) => {
|
|
44
|
+
var _a;
|
|
45
|
+
return (_a = ingredient.conversion) == null ? void 0 : _a["us-customary"];
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
if (hasMetric && hasImperial) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
if (hasMetric) {
|
|
52
|
+
return "metric";
|
|
53
|
+
}
|
|
54
|
+
if (hasImperial) {
|
|
55
|
+
return "us-customary";
|
|
56
|
+
}
|
|
57
|
+
return "none";
|
|
58
|
+
}
|
|
59
|
+
create(config) {
|
|
60
|
+
this.validateConfig(config);
|
|
61
|
+
return {
|
|
62
|
+
name: config.name,
|
|
63
|
+
ingredients: config.ingredients,
|
|
64
|
+
// optional
|
|
65
|
+
thumbnail: config.thumbnail,
|
|
66
|
+
serves: config.serves ?? 1,
|
|
67
|
+
instructions: config.instructions ?? []
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var RecipeUtils = new RecipeUtilsImpl();
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
RecipeUtils
|
|
75
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VOLUME_CONVERSION_TABLE,
|
|
3
|
+
WEIGHT_CONVERSION_TABLE
|
|
4
|
+
} from "./chunk-V26OCCTL.mjs";
|
|
5
|
+
import {
|
|
6
|
+
UNITS
|
|
7
|
+
} from "./chunk-YZB3IG47.mjs";
|
|
8
|
+
import {
|
|
9
|
+
assert
|
|
10
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
11
|
+
|
|
12
|
+
// src/lib/unit.ts
|
|
13
|
+
var UnitUtilsImpl = class {
|
|
14
|
+
getUnit(unit) {
|
|
15
|
+
const match = UNITS.find((u) => u.abbreviation === unit || u.name === unit);
|
|
16
|
+
assert(match, (match2) => !!match2, `No unit found for key: ${unit}`);
|
|
17
|
+
return match;
|
|
18
|
+
}
|
|
19
|
+
getConversionRatio(from, to) {
|
|
20
|
+
const { type, abbreviation } = this.getUnit(from);
|
|
21
|
+
const conversionTable = type === "volume" ? VOLUME_CONVERSION_TABLE : WEIGHT_CONVERSION_TABLE;
|
|
22
|
+
const lookupTable = conversionTable[abbreviation];
|
|
23
|
+
const toUnit = to === "metric" ? type === "volume" ? "L" : "g" : to;
|
|
24
|
+
assert(
|
|
25
|
+
lookupTable,
|
|
26
|
+
(lookupTable2) => !!lookupTable2[toUnit],
|
|
27
|
+
`No conversion table available for unit ${from} to ${to}`
|
|
28
|
+
);
|
|
29
|
+
return lookupTable[toUnit];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Converts a number from one unit to another
|
|
33
|
+
*
|
|
34
|
+
* @param amount - The amount to convert
|
|
35
|
+
* @param from - The unit to convert from
|
|
36
|
+
* @param to - The unit to convert to
|
|
37
|
+
* @returns - The converted amount
|
|
38
|
+
*/
|
|
39
|
+
convert(amount, from, to) {
|
|
40
|
+
if (from === to) {
|
|
41
|
+
return amount;
|
|
42
|
+
}
|
|
43
|
+
const ratio = this.getConversionRatio(from, to);
|
|
44
|
+
return amount * ratio;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var UnitUtils = new UnitUtilsImpl();
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
UnitUtils
|
|
51
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
warn
|
|
3
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
4
|
+
import {
|
|
5
|
+
IS_DEV
|
|
6
|
+
} from "./chunk-XV4QN4LA.mjs";
|
|
7
|
+
|
|
8
|
+
// src/lib/recipe.ts
|
|
9
|
+
var RecipeUtilsImpl = class {
|
|
10
|
+
scopedMessageFactory(recipe) {
|
|
11
|
+
return (message) => `${recipe.name}: ${message}`;
|
|
12
|
+
}
|
|
13
|
+
validateConfig(config) {
|
|
14
|
+
if (!IS_DEV) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const msg = this.scopedMessageFactory(config);
|
|
18
|
+
warn(
|
|
19
|
+
config.instructions,
|
|
20
|
+
(instructions) => instructions.length > 0,
|
|
21
|
+
msg("Recipe has no instructions")
|
|
22
|
+
);
|
|
23
|
+
warn(
|
|
24
|
+
config.servings,
|
|
25
|
+
(servings) => servings !== void 0 && servings <= 0,
|
|
26
|
+
msg("Recipe has less than one serving")
|
|
27
|
+
);
|
|
28
|
+
warn(
|
|
29
|
+
config.ingredients,
|
|
30
|
+
(ingredients) => ingredients.length > 0,
|
|
31
|
+
msg("Recipe has no ingredients")
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
static create(config) {
|
|
35
|
+
this.validateConfig(config);
|
|
36
|
+
return {
|
|
37
|
+
name: config.name,
|
|
38
|
+
ingredients: config.ingredients,
|
|
39
|
+
units: config.units,
|
|
40
|
+
// optional
|
|
41
|
+
thumbnail: config.thumbnail,
|
|
42
|
+
servings: config.servings ?? 1,
|
|
43
|
+
instructions: config.instructions ?? []
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var RecipeUtils = new RecipeUtilsImpl();
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
RecipeUtils
|
|
51
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UnitUtils
|
|
3
|
+
} from "./chunk-KNZMCAQZ.mjs";
|
|
4
|
+
|
|
5
|
+
// src/lib/ingredient.ts
|
|
6
|
+
var IngredientUtilsImpl = class {
|
|
7
|
+
convert(ingredient, to) {
|
|
8
|
+
const amount = UnitUtils.convert(
|
|
9
|
+
ingredient.amount.value,
|
|
10
|
+
ingredient.amount.unit,
|
|
11
|
+
to
|
|
12
|
+
);
|
|
13
|
+
return {
|
|
14
|
+
...ingredient,
|
|
15
|
+
amount: {
|
|
16
|
+
value: amount,
|
|
17
|
+
unit: to
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var IngredientUtils = new IngredientUtilsImpl();
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
IngredientUtils
|
|
26
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UnitUtils
|
|
3
|
+
} from "./chunk-KH3SRXET.mjs";
|
|
4
|
+
|
|
5
|
+
// src/lib/ingredient.ts
|
|
6
|
+
var IngredientUtilsImpl = class {
|
|
7
|
+
convert(ingredient, to) {
|
|
8
|
+
const amount = UnitUtils.convert(
|
|
9
|
+
ingredient.amount.value,
|
|
10
|
+
ingredient.amount.unit,
|
|
11
|
+
to
|
|
12
|
+
);
|
|
13
|
+
return {
|
|
14
|
+
...ingredient,
|
|
15
|
+
amount: {
|
|
16
|
+
value: amount,
|
|
17
|
+
unit: to
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var IngredientUtils = new IngredientUtilsImpl();
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
IngredientUtils
|
|
26
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
warn
|
|
3
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
4
|
+
import {
|
|
5
|
+
IS_DEV
|
|
6
|
+
} from "./chunk-XV4QN4LA.mjs";
|
|
7
|
+
|
|
8
|
+
// src/lib/recipe.ts
|
|
9
|
+
var RecipeUtilsImpl = class {
|
|
10
|
+
scopedMessageFactory(recipe) {
|
|
11
|
+
return (message) => `${recipe.name}: ${message}`;
|
|
12
|
+
}
|
|
13
|
+
validateConfig(config) {
|
|
14
|
+
if (!IS_DEV) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const msg = this.scopedMessageFactory(config);
|
|
18
|
+
warn(
|
|
19
|
+
config.instructions,
|
|
20
|
+
(instructions) => instructions.length > 0,
|
|
21
|
+
msg("Recipe has no instructions")
|
|
22
|
+
);
|
|
23
|
+
warn(
|
|
24
|
+
config.servings,
|
|
25
|
+
(servings) => servings !== void 0 && servings <= 0,
|
|
26
|
+
msg("Recipe has less than one serving")
|
|
27
|
+
);
|
|
28
|
+
warn(
|
|
29
|
+
config.ingredients,
|
|
30
|
+
(ingredients) => ingredients.length > 0,
|
|
31
|
+
msg("Recipe has no ingredients")
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
staticcreate(config) {
|
|
35
|
+
this.validateConfig(config);
|
|
36
|
+
return {
|
|
37
|
+
name: config.name,
|
|
38
|
+
ingredients: config.ingredients,
|
|
39
|
+
units: config.units,
|
|
40
|
+
// optional
|
|
41
|
+
thumbnail: config.thumbnail,
|
|
42
|
+
servings: config.servings ?? 1,
|
|
43
|
+
instructions: config.instructions ?? []
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var RecipeUtils = new RecipeUtilsImpl();
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
RecipeUtils
|
|
51
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as r}from"./chunk-XNOHIWI3.mjs";var n=class{convert(t,o){let e=r.convert(t.amount.value,t.amount.unit,o);return{...t,amount:{value:e,unit:o}}}},i=new n;export{i as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as i}from"./chunk-C45UD45A.mjs";import{a as u}from"./chunk-3CSP4UZG.mjs";var r=class{scopedMessageFactory(e){return n=>`${e.name}: ${n}`}validateConfig(e){if(!!0)return;let n=this.scopedMessageFactory(e);i(e.instructions,t=>t.length>0,n("Recipe has no instructions")),i(e.serves,t=>t===void 0||t>0,n("Recipe serves less than 1 person")),i(e.ingredients,t=>t.length>0,n("Recipe has no ingredients"))}determineMeasurementSystem(e){let{ingredients:n}=e,t=n.some(s=>s.amount.unit==="g"),a=n.some(s=>s.amount.unit==="oz"||s.amount.unit==="fl oz"||s.amount.unit==="lb"||s.amount.unit==="cup");if(!(t&&a)){if(t)return"metric";if(a)return"us-customary"}}create(e){return this.validateConfig(e),{name:e.name,ingredients:e.ingredients,thumbnail:e.thumbnail,serves:e.serves??1,instructions:e.instructions??[],measurements:e.measurements??this.determineMeasurementSystem(e)}}},p=new r;export{p as a};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
warn
|
|
3
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
4
|
+
import {
|
|
5
|
+
IS_DEV
|
|
6
|
+
} from "./chunk-XV4QN4LA.mjs";
|
|
7
|
+
|
|
8
|
+
// src/lib/recipe.ts
|
|
9
|
+
var RecipeUtilsImpl = class {
|
|
10
|
+
scopedMessageFactory(recipe) {
|
|
11
|
+
return (message) => `${recipe.name}: ${message}`;
|
|
12
|
+
}
|
|
13
|
+
validateConfig(config) {
|
|
14
|
+
if (!IS_DEV) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const msg = this.scopedMessageFactory(config);
|
|
18
|
+
warn(
|
|
19
|
+
config.instructions,
|
|
20
|
+
(instructions) => instructions.length > 0,
|
|
21
|
+
msg("Recipe has no instructions")
|
|
22
|
+
);
|
|
23
|
+
warn(
|
|
24
|
+
config.serves,
|
|
25
|
+
(servings) => servings !== void 0 && servings <= 0,
|
|
26
|
+
msg("Recipe serves less than 1 person")
|
|
27
|
+
);
|
|
28
|
+
warn(
|
|
29
|
+
config.ingredients,
|
|
30
|
+
(ingredients) => ingredients.length > 0,
|
|
31
|
+
msg("Recipe has no ingredients")
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
create(config) {
|
|
35
|
+
this.validateConfig(config);
|
|
36
|
+
return {
|
|
37
|
+
name: config.name,
|
|
38
|
+
ingredients: config.ingredients,
|
|
39
|
+
units: config.units,
|
|
40
|
+
// optional
|
|
41
|
+
thumbnail: config.thumbnail,
|
|
42
|
+
servings: config.servings ?? 1,
|
|
43
|
+
instructions: config.instructions ?? []
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var RecipeUtils = new RecipeUtilsImpl();
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
RecipeUtils
|
|
51
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
warn
|
|
3
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
4
|
+
import {
|
|
5
|
+
IS_DEV
|
|
6
|
+
} from "./chunk-XV4QN4LA.mjs";
|
|
7
|
+
|
|
8
|
+
// src/lib/recipe.ts
|
|
9
|
+
var RecipeUtilsImpl = class {
|
|
10
|
+
scopedMessageFactory(recipe) {
|
|
11
|
+
return (message) => `${recipe.name}: ${message}`;
|
|
12
|
+
}
|
|
13
|
+
validateConfig(config) {
|
|
14
|
+
if (!IS_DEV) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const msg = this.scopedMessageFactory(config);
|
|
18
|
+
warn(
|
|
19
|
+
config.instructions,
|
|
20
|
+
(instructions) => instructions.length > 0,
|
|
21
|
+
msg("Recipe has no instructions")
|
|
22
|
+
);
|
|
23
|
+
warn(
|
|
24
|
+
config.serves,
|
|
25
|
+
(serves) => serves === void 0 || serves > 0,
|
|
26
|
+
msg("Recipe serves less than 1 person")
|
|
27
|
+
);
|
|
28
|
+
warn(
|
|
29
|
+
config.ingredients,
|
|
30
|
+
(ingredients) => ingredients.length > 0,
|
|
31
|
+
msg("Recipe has no ingredients")
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
determineMeasurementSystem(config) {
|
|
35
|
+
const { ingredients } = config;
|
|
36
|
+
const hasMetric = ingredients.some(
|
|
37
|
+
(ingredient) => {
|
|
38
|
+
var _a;
|
|
39
|
+
return (_a = ingredient.conversion) == null ? void 0 : _a.metric;
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
const hasImperial = ingredients.some(
|
|
43
|
+
(ingredient) => {
|
|
44
|
+
var _a;
|
|
45
|
+
return (_a = ingredient.conversion) == null ? void 0 : _a["us-customary"];
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
if (hasMetric && hasImperial) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
if (hasMetric) {
|
|
52
|
+
return "metric";
|
|
53
|
+
}
|
|
54
|
+
if (hasImperial) {
|
|
55
|
+
return "us-customary";
|
|
56
|
+
}
|
|
57
|
+
return undeifned;
|
|
58
|
+
}
|
|
59
|
+
create(config) {
|
|
60
|
+
this.validateConfig(config);
|
|
61
|
+
return {
|
|
62
|
+
name: config.name,
|
|
63
|
+
ingredients: config.ingredients,
|
|
64
|
+
// optional
|
|
65
|
+
thumbnail: config.thumbnail,
|
|
66
|
+
serves: config.serves ?? 1,
|
|
67
|
+
instructions: config.instructions ?? []
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var RecipeUtils = new RecipeUtilsImpl();
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
RecipeUtils
|
|
75
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
warn
|
|
3
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
4
|
+
import {
|
|
5
|
+
IS_DEV
|
|
6
|
+
} from "./chunk-XV4QN4LA.mjs";
|
|
7
|
+
|
|
8
|
+
// src/lib/recipe.ts
|
|
9
|
+
var RecipeUtilsImpl = class {
|
|
10
|
+
static scopedMessageFactory(recipe) {
|
|
11
|
+
return (message) => `${recipe.name}: ${message}`;
|
|
12
|
+
}
|
|
13
|
+
static validateConfig(config) {
|
|
14
|
+
if (!IS_DEV) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const msg = this.scopedMessageFactory(config);
|
|
18
|
+
warn(
|
|
19
|
+
config.instructions,
|
|
20
|
+
(instructions) => instructions.length > 0,
|
|
21
|
+
msg("Recipe has no instructions")
|
|
22
|
+
);
|
|
23
|
+
warn(
|
|
24
|
+
config.servings,
|
|
25
|
+
(servings) => servings !== void 0 && servings <= 0,
|
|
26
|
+
msg("Recipe has less than one serving")
|
|
27
|
+
);
|
|
28
|
+
warn(
|
|
29
|
+
config.ingredients,
|
|
30
|
+
(ingredients) => ingredients.length > 0,
|
|
31
|
+
msg("Recipe has no ingredients")
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
create(config) {
|
|
35
|
+
this.validateConfig(config);
|
|
36
|
+
return {
|
|
37
|
+
name: config.name,
|
|
38
|
+
ingredients: config.ingredients,
|
|
39
|
+
units: config.units,
|
|
40
|
+
// optional
|
|
41
|
+
thumbnail: config.thumbnail,
|
|
42
|
+
servings: config.servings ?? 1,
|
|
43
|
+
instructions: config.instructions ?? []
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var RecipeUtils = new RecipeUtilsImpl();
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
RecipeUtils
|
|
51
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as v,b as m}from"./chunk-KXFUCO3R.mjs";import{c as U}from"./chunk-22RBQQWH.mjs";import{a as i}from"./chunk-C45UD45A.mjs";var r=class{getUnit(n){let e=U.find(t=>t.abbreviation===n||t.name===n);return i(e,t=>!!t,`No unit found for key: ${n}`),e}getConversionRatio(n,e){let{type:t,abbreviation:o}=this.getUnit(n),s=(t==="volume"?m:v)[o],c=e==="metric"?t==="volume"?"L":"g":e;return i(s,b=>!!b[c],`No conversion table available for unit ${n} to ${e}`),s[c]}convert(n,e,t){if(e===t)return n;let o=this.getConversionRatio(e,t),a=n*o;return Math.round(a*100)/100}},f=new r;export{f as a};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
warn
|
|
3
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
4
|
+
import {
|
|
5
|
+
IS_DEV
|
|
6
|
+
} from "./chunk-XV4QN4LA.mjs";
|
|
7
|
+
|
|
8
|
+
// src/lib/recipe.ts
|
|
9
|
+
var RecipeUtilsImpl = class {
|
|
10
|
+
scopedMessageFactory(recipe) {
|
|
11
|
+
return (message) => `${recipe.name}: ${message}`;
|
|
12
|
+
}
|
|
13
|
+
validateConfig(config) {
|
|
14
|
+
if (!IS_DEV) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const msg = this.scopedMessageFactory(config);
|
|
18
|
+
warn(
|
|
19
|
+
config.instructions,
|
|
20
|
+
(instructions) => instructions.length > 0,
|
|
21
|
+
msg("Recipe has no instructions")
|
|
22
|
+
);
|
|
23
|
+
warn(
|
|
24
|
+
config.serves,
|
|
25
|
+
(serves) => serves === void 0 || serves > 0,
|
|
26
|
+
msg("Recipe serves less than 1 person")
|
|
27
|
+
);
|
|
28
|
+
warn(
|
|
29
|
+
config.ingredients,
|
|
30
|
+
(ingredients) => ingredients.length > 0,
|
|
31
|
+
msg("Recipe has no ingredients")
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
create(config) {
|
|
35
|
+
this.validateConfig(config);
|
|
36
|
+
return {
|
|
37
|
+
name: config.name,
|
|
38
|
+
ingredients: config.ingredients,
|
|
39
|
+
units: config.units,
|
|
40
|
+
// optional
|
|
41
|
+
thumbnail: config.thumbnail,
|
|
42
|
+
serves: config.serves ?? 1,
|
|
43
|
+
instructions: config.instructions ?? []
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var RecipeUtils = new RecipeUtilsImpl();
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
RecipeUtils
|
|
51
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
warn
|
|
3
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
4
|
+
import {
|
|
5
|
+
IS_DEV
|
|
6
|
+
} from "./chunk-XV4QN4LA.mjs";
|
|
7
|
+
|
|
8
|
+
// src/lib/recipe.ts
|
|
9
|
+
var RecipeUtilsImpl = class {
|
|
10
|
+
scopedMessageFactory(recipe) {
|
|
11
|
+
return (message) => `${recipe.name}: ${message}`;
|
|
12
|
+
}
|
|
13
|
+
validateConfig(config) {
|
|
14
|
+
if (!IS_DEV) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const msg = this.scopedMessageFactory(config);
|
|
18
|
+
warn(
|
|
19
|
+
config.instructions,
|
|
20
|
+
(instructions) => instructions.length > 0,
|
|
21
|
+
msg("Recipe has no instructions")
|
|
22
|
+
);
|
|
23
|
+
warn(
|
|
24
|
+
config.serves,
|
|
25
|
+
(serves) => serves === void 0 || serves > 0,
|
|
26
|
+
msg("Recipe serves less than 1 person")
|
|
27
|
+
);
|
|
28
|
+
warn(
|
|
29
|
+
config.ingredients,
|
|
30
|
+
(ingredients) => ingredients.length > 0,
|
|
31
|
+
msg("Recipe has no ingredients")
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
determineMeasurementSystem(config) {
|
|
35
|
+
const { ingredients } = config;
|
|
36
|
+
const hasMetric = ingredients.some(
|
|
37
|
+
(ingredient) => ingredient.amount.unit === "g"
|
|
38
|
+
);
|
|
39
|
+
const hasImperial = ingredients.some(
|
|
40
|
+
(ingredient) => ingredient.amount.unit === "oz"
|
|
41
|
+
);
|
|
42
|
+
if (hasMetric && hasImperial) {
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
if (hasMetric) {
|
|
46
|
+
return "metric";
|
|
47
|
+
}
|
|
48
|
+
if (hasImperial) {
|
|
49
|
+
return "us-customary";
|
|
50
|
+
}
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
create(config) {
|
|
54
|
+
this.validateConfig(config);
|
|
55
|
+
return {
|
|
56
|
+
name: config.name,
|
|
57
|
+
ingredients: config.ingredients,
|
|
58
|
+
// optional
|
|
59
|
+
thumbnail: config.thumbnail,
|
|
60
|
+
serves: config.serves ?? 1,
|
|
61
|
+
instructions: config.instructions ?? [],
|
|
62
|
+
// computed
|
|
63
|
+
measurements: (
|
|
64
|
+
// if the user has specified a measurement system, use that
|
|
65
|
+
// otherwise, determine the measurement system based on the ingredients
|
|
66
|
+
config.measurements ?? this.determineMeasurementSystem(config)
|
|
67
|
+
)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var RecipeUtils = new RecipeUtilsImpl();
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
RecipeUtils
|
|
75
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
type weightAbbreviation =
|
|
2
|
-
type volumeAbbreviation =
|
|
1
|
+
type weightAbbreviation = 'g' | 'kg' | 'oz' | 'lb';
|
|
2
|
+
type volumeAbbreviation = 'L' | 'gal' | 'mL' | 'cup' | 'tsp' | 'tbsp';
|
|
3
3
|
type conversionTable<T extends string> = Record<T, Partial<Record<T, number>>>;
|
|
4
4
|
declare const WEIGHT_CONVERSION_TABLE: conversionTable<weightAbbreviation>;
|
|
5
5
|
declare const VOLUME_CONVERSION_TABLE: conversionTable<volumeAbbreviation>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
type weightAbbreviation =
|
|
2
|
-
type volumeAbbreviation =
|
|
1
|
+
type weightAbbreviation = 'g' | 'kg' | 'oz' | 'lb';
|
|
2
|
+
type volumeAbbreviation = 'L' | 'gal' | 'mL' | 'cup' | 'tsp' | 'tbsp';
|
|
3
3
|
type conversionTable<T extends string> = Record<T, Partial<Record<T, number>>>;
|
|
4
4
|
declare const WEIGHT_CONVERSION_TABLE: conversionTable<weightAbbreviation>;
|
|
5
5
|
declare const VOLUME_CONVERSION_TABLE: conversionTable<volumeAbbreviation>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { RecipeUtils } from './lib/recipe.mjs';
|
|
2
2
|
export { UnitUtils } from './lib/unit.mjs';
|
|
3
3
|
export { IngredientUtils } from './lib/ingredient.mjs';
|
|
4
|
-
export { GlobalRecipeConfig, Ingredient, IngredientAmount, Recipe, RecipeConfig, Unit, UnitAbbreviation, UnitKey, UnitName } from './types.mjs';
|
|
4
|
+
export { ConversionTables, GlobalRecipeConfig, Ingredient, IngredientAmount, Instruction, Recipe, RecipeConfig, Unit, UnitAbbreviation, UnitKey, UnitName } from './types.mjs';
|
|
5
5
|
import './const/unit.mjs';
|