@recipe-book/core 0.0.1
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/README.md +11 -0
- package/dist/chunk-22RBQQWH.mjs +1 -0
- package/dist/chunk-2WUP3JQY.mjs +25 -0
- package/dist/chunk-3CSP4UZG.mjs +1 -0
- package/dist/chunk-4AN32V3Z.mjs +1 -0
- package/dist/chunk-4EB3HG6B.mjs +50 -0
- package/dist/chunk-5ZCZ6LQB.mjs +1 -0
- package/dist/chunk-6QJZOZ6W.mjs +49 -0
- package/dist/chunk-BOG6H6FE.mjs +1 -0
- package/dist/chunk-C45UD45A.mjs +1 -0
- package/dist/chunk-CBLJXA6P.mjs +1 -0
- package/dist/chunk-CEPTOQUR.mjs +1 -0
- package/dist/chunk-EKLUF5ED.mjs +1 -0
- package/dist/chunk-IEYO4T4T.mjs +49 -0
- package/dist/chunk-JPGZ2MYF.mjs +48 -0
- package/dist/chunk-KXFUCO3R.mjs +1 -0
- package/dist/chunk-LLHRB3T7.mjs +1 -0
- package/dist/chunk-MUILH2IA.mjs +1 -0
- package/dist/chunk-NJQRYZC2.mjs +48 -0
- package/dist/chunk-OBJ5JUVG.mjs +49 -0
- package/dist/chunk-SR2KFBT3.mjs +1 -0
- package/dist/chunk-ULDLBAEG.mjs +1 -0
- package/dist/chunk-V26OCCTL.mjs +82 -0
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/chunk-XV4QN4LA.mjs +6 -0
- package/dist/chunk-YHBHNGQX.mjs +1 -0
- package/dist/chunk-YY3SUQ7P.mjs +16 -0
- package/dist/chunk-YZB3IG47.mjs +80 -0
- package/dist/chunk-ZPZT4LMQ.mjs +25 -0
- package/dist/const/conversion.d.mts +7 -0
- package/dist/const/conversion.d.ts +7 -0
- package/dist/const/conversion.js +1 -0
- package/dist/const/conversion.mjs +1 -0
- package/dist/const/unit.d.mts +119 -0
- package/dist/const/unit.d.ts +119 -0
- package/dist/const/unit.js +1 -0
- package/dist/const/unit.mjs +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/lib/assert.d.mts +18 -0
- package/dist/lib/assert.d.ts +18 -0
- package/dist/lib/assert.js +1 -0
- package/dist/lib/assert.mjs +1 -0
- package/dist/lib/ingredient.d.mts +8 -0
- package/dist/lib/ingredient.d.ts +8 -0
- package/dist/lib/ingredient.js +1 -0
- package/dist/lib/ingredient.mjs +1 -0
- package/dist/lib/recipe.d.mts +10 -0
- package/dist/lib/recipe.d.ts +10 -0
- package/dist/lib/recipe.js +1 -0
- package/dist/lib/recipe.mjs +1 -0
- package/dist/lib/runtime.d.mts +3 -0
- package/dist/lib/runtime.d.ts +3 -0
- package/dist/lib/runtime.js +1 -0
- package/dist/lib/runtime.mjs +1 -0
- package/dist/lib/unit.d.mts +18 -0
- package/dist/lib/unit.d.ts +18 -0
- package/dist/lib/unit.js +1 -0
- package/dist/lib/unit.mjs +1 -0
- package/dist/types.d.mts +31 -0
- package/dist/types.d.ts +31 -0
- package/dist/types.js +1 -0
- package/dist/types.mjs +1 -0
- package/package.json +16 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @recipe-book/core
|
|
2
|
+
|
|
3
|
+
A toolkit to build recipe interfaces in any framework. Supports unit conversions, ingredient highlighting, and more.
|
|
4
|
+
|
|
5
|
+
## Packages
|
|
6
|
+
|
|
7
|
+
| Package | Description |
|
|
8
|
+
| :------------------------------ | :-------------------------------------------- |
|
|
9
|
+
| [`core`](./packages/core) | Core logic for parsing and formatting recipes |
|
|
10
|
+
| [`react`](./packages/react) | React components for displaying recipes |
|
|
11
|
+
| [`website`](./packages/website) | Demo website for Recipe components. |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=[{key:!0,name:"gram",abbreviation:"g",value:1,type:"weight"},{name:"kilogram",abbreviation:"kg",value:1e3,type:"weight"},{name:"ounce",abbreviation:"oz",value:28.3495,type:"weight"},{name:"pound",abbreviation:"lb",value:453.592,type:"weight"}],a=[{key:!0,name:"liter",abbreviation:"L",value:1,type:"volume"},{name:"gallon",abbreviation:"gal",value:3.78541,type:"volume"},{name:"milliliter",abbreviation:"mL",value:.001,type:"volume"},{name:"cup",abbreviation:"cup",value:.0625,type:"volume"},{name:"teaspoon",abbreviation:"tsp",value:.0208333,type:"volume"},{name:"tablespoon",abbreviation:"tbsp",value:.0625,type:"volume"},{name:"fluid ounce",abbreviation:"fl oz",value:.125,type:"volume"}],t=[...e,...a];export{e as a,a as b,t as c};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UnitUtils
|
|
3
|
+
} from "./chunk-IEYO4T4T.mjs";
|
|
4
|
+
|
|
5
|
+
// src/lib/ingredient.ts
|
|
6
|
+
var IngredientUtils = 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
|
+
|
|
23
|
+
export {
|
|
24
|
+
IngredientUtils
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=!0;export{t as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as o}from"./chunk-SR2KFBT3.mjs";var r=class{convert(t,n){let m=o.convert(t.amount.value,t.amount.unit,n);return{...t,amount:{value:m,unit:n}}}};export{r as a};
|
|
@@ -0,0 +1,50 @@
|
|
|
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 RecipeUtils = 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
|
+
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
|
+
|
|
48
|
+
export {
|
|
49
|
+
RecipeUtils
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=process.env.NODE_ENV!=="production";export{o as a};
|
|
@@ -0,0 +1,49 @@
|
|
|
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 UnitUtils = class {
|
|
14
|
+
static 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
|
+
static 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
|
+
assert(
|
|
24
|
+
lookupTable,
|
|
25
|
+
(lookupTable2) => !!lookupTable2[to],
|
|
26
|
+
`No conversion table available for unit ${from} to ${to}`
|
|
27
|
+
);
|
|
28
|
+
return lookupTable[to];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts a number from one unit to another
|
|
32
|
+
*
|
|
33
|
+
* @param amount - The amount to convert
|
|
34
|
+
* @param from - The unit to convert from
|
|
35
|
+
* @param to - The unit to convert to
|
|
36
|
+
* @returns - The converted amount
|
|
37
|
+
*/
|
|
38
|
+
static convert(amount, from, to) {
|
|
39
|
+
if (from === to) {
|
|
40
|
+
return amount;
|
|
41
|
+
}
|
|
42
|
+
const ratio = this.getConversionRatio(from, to);
|
|
43
|
+
return amount * ratio;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
UnitUtils
|
|
49
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as s}from"./chunk-C45UD45A.mjs";import{a as r}from"./chunk-3CSP4UZG.mjs";var t=class{scopedMessageFactory(e){return i=>`${e.name}: ${i}`}validateConfig(e){if(!!0)return;let i=this.scopedMessageFactory(e);s(e.instructions,n=>n.length>0,i("Recipe has no instructions")),s(e.servings,n=>n!==void 0&&n<=0,i("Recipe has less than one serving")),s(e.ingredients,n=>n.length>0,i("Recipe has no ingredients"))}create(e){return this.validateConfig(e),{name:e.name,ingredients:e.ingredients,servings:e.servings??1,instructions:e.instructions??[],units:e.units}}};export{t as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(n,o,r){if(!o(n))throw new Error(r)}function t(n,o,r){o(n)||console.warn(r)}export{e as a,t as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as s}from"./chunk-C45UD45A.mjs";import{a as r}from"./chunk-3CSP4UZG.mjs";var t=class{scopedMessageFactory(e){return i=>`${e.name}: ${i}`}validateConfig(e){if(!!0)return;let i=this.scopedMessageFactory(e);s(e.instructions,n=>n.length>0,i("Recipe has no instructions")),s(e.servings,n=>n!==void 0&&n<=0,i("Recipe has less than one serving")),s(e.ingredients,n=>n.length>0,i("Recipe has no ingredients"))}create(e){return this.validateConfig(e),{name:e.name,ingredients:e.ingredients,units:e.units,thumbnail:e.thumbnail,servings:e.servings??1,instructions:e.instructions??[]}}};export{t as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c}from"./chunk-22RBQQWH.mjs";import{a as o}from"./chunk-C45UD45A.mjs";import{a,b as s}from"./chunk-KXFUCO3R.mjs";var b=class{static getUnit(t){let e=c.find(n=>n.abbreviation===t||n.name===t);return o(e,n=>!!n,`No unit found for key: ${t}`),e}static getConversionRatio(t,e){let{type:n,abbreviation:i}=this.getUnit(t),r=(n==="volume"?s:a)[i];return o(r,v=>!!v[e],`No conversion table available for unit ${t} to ${e}`),r[e]}static convert(t,e,n){if(e===n)return t;let i=this.getConversionRatio(e,n);return t*i}};export{b as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as s}from"./chunk-C45UD45A.mjs";import{a as r}from"./chunk-3CSP4UZG.mjs";var t=class{scopedMessageFactory(e){return n=>`${e.name}: ${n}`}validateConfig(e){if(!0)return;let n=this.scopedMessageFactory(e);s(e.instructions,i=>i.length>0,n("Recipe has no instructions")),s(e.servings,i=>i!==void 0&&i<=0,n("Recipe has less than one serving")),s(e.ingredients,i=>i.length>0,n("Recipe has no ingredients"))}create(e){return this.validateConfig(e),{name:e.name,ingredients:e.ingredients,servings:e.servings??1,instructions:e.instructions??[]}}};export{t as a};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UNITS
|
|
3
|
+
} from "./chunk-YZB3IG47.mjs";
|
|
4
|
+
import {
|
|
5
|
+
assert
|
|
6
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
7
|
+
import {
|
|
8
|
+
VOLUME_CONVERSION_TABLE,
|
|
9
|
+
WEIGHT_CONVERSION_TABLE
|
|
10
|
+
} from "./chunk-V26OCCTL.mjs";
|
|
11
|
+
|
|
12
|
+
// src/lib/unit.ts
|
|
13
|
+
var UnitUtils = class {
|
|
14
|
+
static 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
|
+
static 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
|
+
assert(
|
|
24
|
+
lookupTable,
|
|
25
|
+
(lookupTable2) => !!lookupTable2[to],
|
|
26
|
+
`No conversion table available for unit ${from} to ${to}`
|
|
27
|
+
);
|
|
28
|
+
return lookupTable[to];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts a number from one unit to another
|
|
32
|
+
*
|
|
33
|
+
* @param amount - The amount to convert
|
|
34
|
+
* @param from - The unit to convert from
|
|
35
|
+
* @param to - The unit to convert to
|
|
36
|
+
* @returns - The converted amount
|
|
37
|
+
*/
|
|
38
|
+
static convert(amount, from, to) {
|
|
39
|
+
if (from === to) {
|
|
40
|
+
return amount;
|
|
41
|
+
}
|
|
42
|
+
const ratio = this.getConversionRatio(from, to);
|
|
43
|
+
return amount * ratio;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
UnitUtils
|
|
49
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IS_DEV
|
|
3
|
+
} from "./chunk-XV4QN4LA.mjs";
|
|
4
|
+
import {
|
|
5
|
+
warn
|
|
6
|
+
} from "./chunk-YY3SUQ7P.mjs";
|
|
7
|
+
|
|
8
|
+
// src/lib/recipe.ts
|
|
9
|
+
var RecipeUtils = 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
|
+
create(config) {
|
|
35
|
+
this.validateConfig(config);
|
|
36
|
+
return {
|
|
37
|
+
name: config.name,
|
|
38
|
+
ingredients: config.ingredients,
|
|
39
|
+
servings: config.servings ?? 1,
|
|
40
|
+
instructions: config.instructions ?? [],
|
|
41
|
+
units: config.units
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
RecipeUtils
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t={g:{g:1,kg:1e3,oz:28.3495,lb:453.592},kg:{g:.001,kg:1,oz:.0283495,lb:.453592},oz:{g:.035274,kg:35.274,oz:1,lb:16},lb:{g:.00220462,kg:2.20462,oz:.0625,lb:1}},p={L:{L:1,gal:3.78541,mL:.001,cup:.0625,tsp:.202884,tbsp:.067628},gal:{L:.264172,gal:1,mL:264172e-9,cup:.016,tsp:.0515037,tbsp:.0171679},mL:{L:1e3,gal:3785.41,mL:1,cup:.00422675,tsp:.033814,tbsp:.00422675},cup:{L:4.22675,gal:16,mL:236.588,cup:1,tsp:3.2,tbsp:1.06667},tsp:{L:4.92892,gal:18.6184,mL:4.92892,cup:.3125,tsp:1,tbsp:.333333},tbsp:{L:14.7868,gal:56,mL:14.7868,cup:.9375,tsp:3,tbsp:1}};export{t as a,p as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as r}from"./chunk-3CSP4UZG.mjs";import{b as s}from"./chunk-C45UD45A.mjs";var t=class{scopedMessageFactory(e){return n=>`${e.name}: ${n}`}validateConfig(e){if(!0)return;let n=this.scopedMessageFactory(e);s(e.instructions,i=>i.length>0,n("Recipe has no instructions")),s(e.servings,i=>i!==void 0&&i<=0,n("Recipe has less than one serving")),s(e.ingredients,i=>i.length>0,n("Recipe has no ingredients"))}create(e){return this.validateConfig(e),{name:e.name,ingredients:e.ingredients,servings:e.servings??1,instructions:e.instructions??[]}}};export{t as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as o}from"./chunk-CEPTOQUR.mjs";var r=class{convert(t,n){let m=o.convert(t.amount.value,t.amount.unit,n);return{...t,amount:{value:m,unit:n}}}};export{r as a};
|
|
@@ -0,0 +1,48 @@
|
|
|
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 RecipeUtils = 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
|
+
create(config) {
|
|
35
|
+
this.validateConfig(config);
|
|
36
|
+
return {
|
|
37
|
+
name: config.name,
|
|
38
|
+
ingredients: config.ingredients,
|
|
39
|
+
servings: config.servings ?? 1,
|
|
40
|
+
instructions: config.instructions ?? [],
|
|
41
|
+
units: config.units
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
RecipeUtils
|
|
48
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
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 RecipeUtils = 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
|
+
create(config) {
|
|
35
|
+
this.validateConfig(config);
|
|
36
|
+
return {
|
|
37
|
+
name: config.name,
|
|
38
|
+
ingredients: config.ingredients,
|
|
39
|
+
servings: config.servings ?? 1,
|
|
40
|
+
instructions: config.instructions ?? [],
|
|
41
|
+
units: config.units,
|
|
42
|
+
thumbnail: config.thumbnail
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
RecipeUtils
|
|
49
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b as s}from"./chunk-KXFUCO3R.mjs";import{c}from"./chunk-22RBQQWH.mjs";import{a as o}from"./chunk-C45UD45A.mjs";var b=class{static getUnit(t){let e=c.find(n=>n.abbreviation===t||n.name===t);return o(e,n=>!!n,`No unit found for key: ${t}`),e}static getConversionRatio(t,e){let{type:n,abbreviation:i}=this.getUnit(t),r=(n==="volume"?s:a)[i];return o(r,v=>!!v[e],`No conversion table available for unit ${t} to ${e}`),r[e]}static convert(t,e,n){if(e===n)return t;let i=this.getConversionRatio(e,n);return t*i}};export{b as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./chunk-SR2KFBT3.mjs";var o=class{convert(n,t){let r=e.convert(n.amount.value,n.amount.unit,t);return{...n,amount:{value:r,unit:t}}}};export{o as a};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// src/const/conversion.ts
|
|
2
|
+
var WEIGHT_CONVERSION_TABLE = {
|
|
3
|
+
g: {
|
|
4
|
+
g: 1,
|
|
5
|
+
kg: 1e3,
|
|
6
|
+
oz: 28.3495,
|
|
7
|
+
lb: 453.592
|
|
8
|
+
},
|
|
9
|
+
kg: {
|
|
10
|
+
g: 1e-3,
|
|
11
|
+
kg: 1,
|
|
12
|
+
oz: 0.0283495,
|
|
13
|
+
lb: 0.453592
|
|
14
|
+
},
|
|
15
|
+
oz: {
|
|
16
|
+
g: 0.035274,
|
|
17
|
+
kg: 35.274,
|
|
18
|
+
oz: 1,
|
|
19
|
+
lb: 16
|
|
20
|
+
},
|
|
21
|
+
lb: {
|
|
22
|
+
g: 220462e-8,
|
|
23
|
+
kg: 2.20462,
|
|
24
|
+
oz: 0.0625,
|
|
25
|
+
lb: 1
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var VOLUME_CONVERSION_TABLE = {
|
|
29
|
+
L: {
|
|
30
|
+
L: 1,
|
|
31
|
+
gal: 3.78541,
|
|
32
|
+
mL: 1e-3,
|
|
33
|
+
cup: 0.0625,
|
|
34
|
+
tsp: 0.202884,
|
|
35
|
+
tbsp: 0.067628
|
|
36
|
+
},
|
|
37
|
+
gal: {
|
|
38
|
+
L: 0.264172,
|
|
39
|
+
gal: 1,
|
|
40
|
+
mL: 264172e-9,
|
|
41
|
+
cup: 0.016,
|
|
42
|
+
tsp: 0.0515037,
|
|
43
|
+
tbsp: 0.0171679
|
|
44
|
+
},
|
|
45
|
+
mL: {
|
|
46
|
+
L: 1e3,
|
|
47
|
+
gal: 3785.41,
|
|
48
|
+
mL: 1,
|
|
49
|
+
cup: 422675e-8,
|
|
50
|
+
tsp: 0.033814,
|
|
51
|
+
tbsp: 422675e-8
|
|
52
|
+
},
|
|
53
|
+
cup: {
|
|
54
|
+
L: 4.22675,
|
|
55
|
+
gal: 16,
|
|
56
|
+
mL: 236.588,
|
|
57
|
+
cup: 1,
|
|
58
|
+
tsp: 3.2,
|
|
59
|
+
tbsp: 1.06667
|
|
60
|
+
},
|
|
61
|
+
tsp: {
|
|
62
|
+
L: 4.92892,
|
|
63
|
+
gal: 18.6184,
|
|
64
|
+
mL: 4.92892,
|
|
65
|
+
cup: 0.3125,
|
|
66
|
+
tsp: 1,
|
|
67
|
+
tbsp: 0.333333
|
|
68
|
+
},
|
|
69
|
+
tbsp: {
|
|
70
|
+
L: 14.7868,
|
|
71
|
+
gal: 56,
|
|
72
|
+
mL: 14.7868,
|
|
73
|
+
cup: 0.9375,
|
|
74
|
+
tsp: 3,
|
|
75
|
+
tbsp: 1
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export {
|
|
80
|
+
WEIGHT_CONVERSION_TABLE,
|
|
81
|
+
VOLUME_CONVERSION_TABLE
|
|
82
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as t}from"./chunk-5ZCZ6LQB.mjs";import{b as s}from"./chunk-C45UD45A.mjs";var r=class{scopedMessageFactory(e){return n=>`${e.name}: ${n}`}validateConfig(e){if(t)return;let n=this.scopedMessageFactory(e);s(e.instructions,i=>i.length>0,n("Recipe has no instructions")),s(e.servings,i=>i!==void 0&&i<=0,n("Recipe has less than one serving")),s(e.ingredients,i=>i.length>0,n("Recipe has no ingredients"))}create(e){return this.validateConfig(e),{name:e.name,ingredients:e.ingredients,servings:e.servings??1,instructions:e.instructions??[]}}};export{r as a};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/lib/assert.ts
|
|
2
|
+
function assert(value, assertion, message) {
|
|
3
|
+
if (!assertion(value)) {
|
|
4
|
+
throw new Error(message);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function warn(value, assertion, message) {
|
|
8
|
+
if (!assertion(value)) {
|
|
9
|
+
console.warn(message);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
assert,
|
|
15
|
+
warn
|
|
16
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/const/unit.ts
|
|
2
|
+
var WEIGHT_UNITS = [
|
|
3
|
+
{
|
|
4
|
+
key: true,
|
|
5
|
+
name: "gram",
|
|
6
|
+
abbreviation: "g",
|
|
7
|
+
value: 1,
|
|
8
|
+
type: "weight"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: "kilogram",
|
|
12
|
+
abbreviation: "kg",
|
|
13
|
+
value: 1e3,
|
|
14
|
+
type: "weight"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "ounce",
|
|
18
|
+
abbreviation: "oz",
|
|
19
|
+
value: 28.3495,
|
|
20
|
+
type: "weight"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "pound",
|
|
24
|
+
abbreviation: "lb",
|
|
25
|
+
value: 453.592,
|
|
26
|
+
type: "weight"
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
var VOLUME_UNITS = [
|
|
30
|
+
{
|
|
31
|
+
key: true,
|
|
32
|
+
name: "liter",
|
|
33
|
+
abbreviation: "L",
|
|
34
|
+
value: 1,
|
|
35
|
+
type: "volume"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "gallon",
|
|
39
|
+
abbreviation: "gal",
|
|
40
|
+
value: 3.78541,
|
|
41
|
+
type: "volume"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "milliliter",
|
|
45
|
+
abbreviation: "mL",
|
|
46
|
+
value: 1e-3,
|
|
47
|
+
type: "volume"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "cup",
|
|
51
|
+
abbreviation: "cup",
|
|
52
|
+
value: 0.0625,
|
|
53
|
+
type: "volume"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "teaspoon",
|
|
57
|
+
abbreviation: "tsp",
|
|
58
|
+
value: 0.0208333,
|
|
59
|
+
type: "volume"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "tablespoon",
|
|
63
|
+
abbreviation: "tbsp",
|
|
64
|
+
value: 0.0625,
|
|
65
|
+
type: "volume"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "fluid ounce",
|
|
69
|
+
abbreviation: "fl oz",
|
|
70
|
+
value: 0.125,
|
|
71
|
+
type: "volume"
|
|
72
|
+
}
|
|
73
|
+
];
|
|
74
|
+
var UNITS = [...WEIGHT_UNITS, ...VOLUME_UNITS];
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
WEIGHT_UNITS,
|
|
78
|
+
VOLUME_UNITS,
|
|
79
|
+
UNITS
|
|
80
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UnitUtils
|
|
3
|
+
} from "./chunk-6QJZOZ6W.mjs";
|
|
4
|
+
|
|
5
|
+
// src/lib/ingredient.ts
|
|
6
|
+
var IngredientUtils = 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
|
+
|
|
23
|
+
export {
|
|
24
|
+
IngredientUtils
|
|
25
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type weightAbbreviation = "g" | "kg" | "oz" | "lb";
|
|
2
|
+
type volumeAbbreviation = "L" | "gal" | "mL" | "cup" | "tsp" | "tbsp";
|
|
3
|
+
type conversionTable<T extends string> = Record<T, Partial<Record<T, number>>>;
|
|
4
|
+
declare const WEIGHT_CONVERSION_TABLE: conversionTable<weightAbbreviation>;
|
|
5
|
+
declare const VOLUME_CONVERSION_TABLE: conversionTable<volumeAbbreviation>;
|
|
6
|
+
|
|
7
|
+
export { VOLUME_CONVERSION_TABLE, WEIGHT_CONVERSION_TABLE };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type weightAbbreviation = "g" | "kg" | "oz" | "lb";
|
|
2
|
+
type volumeAbbreviation = "L" | "gal" | "mL" | "cup" | "tsp" | "tbsp";
|
|
3
|
+
type conversionTable<T extends string> = Record<T, Partial<Record<T, number>>>;
|
|
4
|
+
declare const WEIGHT_CONVERSION_TABLE: conversionTable<weightAbbreviation>;
|
|
5
|
+
declare const VOLUME_CONVERSION_TABLE: conversionTable<volumeAbbreviation>;
|
|
6
|
+
|
|
7
|
+
export { VOLUME_CONVERSION_TABLE, WEIGHT_CONVERSION_TABLE };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var L=(p,t)=>{for(var b in t)o(p,b,{get:t[b],enumerable:!0})},c=(p,t,b,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of l(t))!a.call(p,s)&&s!==b&&o(p,s,{get:()=>t[s],enumerable:!(e=g(t,s))||e.enumerable});return p};var n=p=>c(o({},"__esModule",{value:!0}),p);var m={};L(m,{VOLUME_CONVERSION_TABLE:()=>r,WEIGHT_CONVERSION_TABLE:()=>i});module.exports=n(m);var i={g:{g:1,kg:1e3,oz:28.3495,lb:453.592},kg:{g:.001,kg:1,oz:.0283495,lb:.453592},oz:{g:.035274,kg:35.274,oz:1,lb:16},lb:{g:.00220462,kg:2.20462,oz:.0625,lb:1}},r={L:{L:1,gal:3.78541,mL:.001,cup:.0625,tsp:.202884,tbsp:.067628},gal:{L:.264172,gal:1,mL:264172e-9,cup:.016,tsp:.0515037,tbsp:.0171679},mL:{L:1e3,gal:3785.41,mL:1,cup:.00422675,tsp:.033814,tbsp:.00422675},cup:{L:4.22675,gal:16,mL:236.588,cup:1,tsp:3.2,tbsp:1.06667},tsp:{L:4.92892,gal:18.6184,mL:4.92892,cup:.3125,tsp:1,tbsp:.333333},tbsp:{L:14.7868,gal:56,mL:14.7868,cup:.9375,tsp:3,tbsp:1}};0&&(module.exports={VOLUME_CONVERSION_TABLE,WEIGHT_CONVERSION_TABLE});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b}from"../chunk-KXFUCO3R.mjs";export{b as VOLUME_CONVERSION_TABLE,a as WEIGHT_CONVERSION_TABLE};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
declare const WEIGHT_UNITS: readonly [{
|
|
2
|
+
readonly key: true;
|
|
3
|
+
readonly name: "gram";
|
|
4
|
+
readonly abbreviation: "g";
|
|
5
|
+
readonly value: 1;
|
|
6
|
+
readonly type: "weight";
|
|
7
|
+
}, {
|
|
8
|
+
readonly name: "kilogram";
|
|
9
|
+
readonly abbreviation: "kg";
|
|
10
|
+
readonly value: 1000;
|
|
11
|
+
readonly type: "weight";
|
|
12
|
+
}, {
|
|
13
|
+
readonly name: "ounce";
|
|
14
|
+
readonly abbreviation: "oz";
|
|
15
|
+
readonly value: 28.3495;
|
|
16
|
+
readonly type: "weight";
|
|
17
|
+
}, {
|
|
18
|
+
readonly name: "pound";
|
|
19
|
+
readonly abbreviation: "lb";
|
|
20
|
+
readonly value: 453.592;
|
|
21
|
+
readonly type: "weight";
|
|
22
|
+
}];
|
|
23
|
+
declare const VOLUME_UNITS: readonly [{
|
|
24
|
+
readonly key: true;
|
|
25
|
+
readonly name: "liter";
|
|
26
|
+
readonly abbreviation: "L";
|
|
27
|
+
readonly value: 1;
|
|
28
|
+
readonly type: "volume";
|
|
29
|
+
}, {
|
|
30
|
+
readonly name: "gallon";
|
|
31
|
+
readonly abbreviation: "gal";
|
|
32
|
+
readonly value: 3.78541;
|
|
33
|
+
readonly type: "volume";
|
|
34
|
+
}, {
|
|
35
|
+
readonly name: "milliliter";
|
|
36
|
+
readonly abbreviation: "mL";
|
|
37
|
+
readonly value: 0.001;
|
|
38
|
+
readonly type: "volume";
|
|
39
|
+
}, {
|
|
40
|
+
readonly name: "cup";
|
|
41
|
+
readonly abbreviation: "cup";
|
|
42
|
+
readonly value: 0.0625;
|
|
43
|
+
readonly type: "volume";
|
|
44
|
+
}, {
|
|
45
|
+
readonly name: "teaspoon";
|
|
46
|
+
readonly abbreviation: "tsp";
|
|
47
|
+
readonly value: 0.0208333;
|
|
48
|
+
readonly type: "volume";
|
|
49
|
+
}, {
|
|
50
|
+
readonly name: "tablespoon";
|
|
51
|
+
readonly abbreviation: "tbsp";
|
|
52
|
+
readonly value: 0.0625;
|
|
53
|
+
readonly type: "volume";
|
|
54
|
+
}, {
|
|
55
|
+
readonly name: "fluid ounce";
|
|
56
|
+
readonly abbreviation: "fl oz";
|
|
57
|
+
readonly value: 0.125;
|
|
58
|
+
readonly type: "volume";
|
|
59
|
+
}];
|
|
60
|
+
declare const UNITS: ({
|
|
61
|
+
readonly key: true;
|
|
62
|
+
readonly name: "gram";
|
|
63
|
+
readonly abbreviation: "g";
|
|
64
|
+
readonly value: 1;
|
|
65
|
+
readonly type: "weight";
|
|
66
|
+
} | {
|
|
67
|
+
readonly name: "kilogram";
|
|
68
|
+
readonly abbreviation: "kg";
|
|
69
|
+
readonly value: 1000;
|
|
70
|
+
readonly type: "weight";
|
|
71
|
+
} | {
|
|
72
|
+
readonly name: "ounce";
|
|
73
|
+
readonly abbreviation: "oz";
|
|
74
|
+
readonly value: 28.3495;
|
|
75
|
+
readonly type: "weight";
|
|
76
|
+
} | {
|
|
77
|
+
readonly name: "pound";
|
|
78
|
+
readonly abbreviation: "lb";
|
|
79
|
+
readonly value: 453.592;
|
|
80
|
+
readonly type: "weight";
|
|
81
|
+
} | {
|
|
82
|
+
readonly key: true;
|
|
83
|
+
readonly name: "liter";
|
|
84
|
+
readonly abbreviation: "L";
|
|
85
|
+
readonly value: 1;
|
|
86
|
+
readonly type: "volume";
|
|
87
|
+
} | {
|
|
88
|
+
readonly name: "gallon";
|
|
89
|
+
readonly abbreviation: "gal";
|
|
90
|
+
readonly value: 3.78541;
|
|
91
|
+
readonly type: "volume";
|
|
92
|
+
} | {
|
|
93
|
+
readonly name: "milliliter";
|
|
94
|
+
readonly abbreviation: "mL";
|
|
95
|
+
readonly value: 0.001;
|
|
96
|
+
readonly type: "volume";
|
|
97
|
+
} | {
|
|
98
|
+
readonly name: "cup";
|
|
99
|
+
readonly abbreviation: "cup";
|
|
100
|
+
readonly value: 0.0625;
|
|
101
|
+
readonly type: "volume";
|
|
102
|
+
} | {
|
|
103
|
+
readonly name: "teaspoon";
|
|
104
|
+
readonly abbreviation: "tsp";
|
|
105
|
+
readonly value: 0.0208333;
|
|
106
|
+
readonly type: "volume";
|
|
107
|
+
} | {
|
|
108
|
+
readonly name: "tablespoon";
|
|
109
|
+
readonly abbreviation: "tbsp";
|
|
110
|
+
readonly value: 0.0625;
|
|
111
|
+
readonly type: "volume";
|
|
112
|
+
} | {
|
|
113
|
+
readonly name: "fluid ounce";
|
|
114
|
+
readonly abbreviation: "fl oz";
|
|
115
|
+
readonly value: 0.125;
|
|
116
|
+
readonly type: "volume";
|
|
117
|
+
})[];
|
|
118
|
+
|
|
119
|
+
export { UNITS, VOLUME_UNITS, WEIGHT_UNITS };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
declare const WEIGHT_UNITS: readonly [{
|
|
2
|
+
readonly key: true;
|
|
3
|
+
readonly name: "gram";
|
|
4
|
+
readonly abbreviation: "g";
|
|
5
|
+
readonly value: 1;
|
|
6
|
+
readonly type: "weight";
|
|
7
|
+
}, {
|
|
8
|
+
readonly name: "kilogram";
|
|
9
|
+
readonly abbreviation: "kg";
|
|
10
|
+
readonly value: 1000;
|
|
11
|
+
readonly type: "weight";
|
|
12
|
+
}, {
|
|
13
|
+
readonly name: "ounce";
|
|
14
|
+
readonly abbreviation: "oz";
|
|
15
|
+
readonly value: 28.3495;
|
|
16
|
+
readonly type: "weight";
|
|
17
|
+
}, {
|
|
18
|
+
readonly name: "pound";
|
|
19
|
+
readonly abbreviation: "lb";
|
|
20
|
+
readonly value: 453.592;
|
|
21
|
+
readonly type: "weight";
|
|
22
|
+
}];
|
|
23
|
+
declare const VOLUME_UNITS: readonly [{
|
|
24
|
+
readonly key: true;
|
|
25
|
+
readonly name: "liter";
|
|
26
|
+
readonly abbreviation: "L";
|
|
27
|
+
readonly value: 1;
|
|
28
|
+
readonly type: "volume";
|
|
29
|
+
}, {
|
|
30
|
+
readonly name: "gallon";
|
|
31
|
+
readonly abbreviation: "gal";
|
|
32
|
+
readonly value: 3.78541;
|
|
33
|
+
readonly type: "volume";
|
|
34
|
+
}, {
|
|
35
|
+
readonly name: "milliliter";
|
|
36
|
+
readonly abbreviation: "mL";
|
|
37
|
+
readonly value: 0.001;
|
|
38
|
+
readonly type: "volume";
|
|
39
|
+
}, {
|
|
40
|
+
readonly name: "cup";
|
|
41
|
+
readonly abbreviation: "cup";
|
|
42
|
+
readonly value: 0.0625;
|
|
43
|
+
readonly type: "volume";
|
|
44
|
+
}, {
|
|
45
|
+
readonly name: "teaspoon";
|
|
46
|
+
readonly abbreviation: "tsp";
|
|
47
|
+
readonly value: 0.0208333;
|
|
48
|
+
readonly type: "volume";
|
|
49
|
+
}, {
|
|
50
|
+
readonly name: "tablespoon";
|
|
51
|
+
readonly abbreviation: "tbsp";
|
|
52
|
+
readonly value: 0.0625;
|
|
53
|
+
readonly type: "volume";
|
|
54
|
+
}, {
|
|
55
|
+
readonly name: "fluid ounce";
|
|
56
|
+
readonly abbreviation: "fl oz";
|
|
57
|
+
readonly value: 0.125;
|
|
58
|
+
readonly type: "volume";
|
|
59
|
+
}];
|
|
60
|
+
declare const UNITS: ({
|
|
61
|
+
readonly key: true;
|
|
62
|
+
readonly name: "gram";
|
|
63
|
+
readonly abbreviation: "g";
|
|
64
|
+
readonly value: 1;
|
|
65
|
+
readonly type: "weight";
|
|
66
|
+
} | {
|
|
67
|
+
readonly name: "kilogram";
|
|
68
|
+
readonly abbreviation: "kg";
|
|
69
|
+
readonly value: 1000;
|
|
70
|
+
readonly type: "weight";
|
|
71
|
+
} | {
|
|
72
|
+
readonly name: "ounce";
|
|
73
|
+
readonly abbreviation: "oz";
|
|
74
|
+
readonly value: 28.3495;
|
|
75
|
+
readonly type: "weight";
|
|
76
|
+
} | {
|
|
77
|
+
readonly name: "pound";
|
|
78
|
+
readonly abbreviation: "lb";
|
|
79
|
+
readonly value: 453.592;
|
|
80
|
+
readonly type: "weight";
|
|
81
|
+
} | {
|
|
82
|
+
readonly key: true;
|
|
83
|
+
readonly name: "liter";
|
|
84
|
+
readonly abbreviation: "L";
|
|
85
|
+
readonly value: 1;
|
|
86
|
+
readonly type: "volume";
|
|
87
|
+
} | {
|
|
88
|
+
readonly name: "gallon";
|
|
89
|
+
readonly abbreviation: "gal";
|
|
90
|
+
readonly value: 3.78541;
|
|
91
|
+
readonly type: "volume";
|
|
92
|
+
} | {
|
|
93
|
+
readonly name: "milliliter";
|
|
94
|
+
readonly abbreviation: "mL";
|
|
95
|
+
readonly value: 0.001;
|
|
96
|
+
readonly type: "volume";
|
|
97
|
+
} | {
|
|
98
|
+
readonly name: "cup";
|
|
99
|
+
readonly abbreviation: "cup";
|
|
100
|
+
readonly value: 0.0625;
|
|
101
|
+
readonly type: "volume";
|
|
102
|
+
} | {
|
|
103
|
+
readonly name: "teaspoon";
|
|
104
|
+
readonly abbreviation: "tsp";
|
|
105
|
+
readonly value: 0.0208333;
|
|
106
|
+
readonly type: "volume";
|
|
107
|
+
} | {
|
|
108
|
+
readonly name: "tablespoon";
|
|
109
|
+
readonly abbreviation: "tbsp";
|
|
110
|
+
readonly value: 0.0625;
|
|
111
|
+
readonly type: "volume";
|
|
112
|
+
} | {
|
|
113
|
+
readonly name: "fluid ounce";
|
|
114
|
+
readonly abbreviation: "fl oz";
|
|
115
|
+
readonly value: 0.125;
|
|
116
|
+
readonly type: "volume";
|
|
117
|
+
})[];
|
|
118
|
+
|
|
119
|
+
export { UNITS, VOLUME_UNITS, WEIGHT_UNITS };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var n=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var p=(a,e)=>{for(var o in e)n(a,o,{get:e[o],enumerable:!0})},r=(a,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of b(e))!m.call(a,t)&&t!==o&&n(a,t,{get:()=>e[t],enumerable:!(i=u(e,t))||i.enumerable});return a};var y=a=>r(n({},"__esModule",{value:!0}),a);var g={};p(g,{UNITS:()=>s,VOLUME_UNITS:()=>v,WEIGHT_UNITS:()=>l});module.exports=y(g);var l=[{key:!0,name:"gram",abbreviation:"g",value:1,type:"weight"},{name:"kilogram",abbreviation:"kg",value:1e3,type:"weight"},{name:"ounce",abbreviation:"oz",value:28.3495,type:"weight"},{name:"pound",abbreviation:"lb",value:453.592,type:"weight"}],v=[{key:!0,name:"liter",abbreviation:"L",value:1,type:"volume"},{name:"gallon",abbreviation:"gal",value:3.78541,type:"volume"},{name:"milliliter",abbreviation:"mL",value:.001,type:"volume"},{name:"cup",abbreviation:"cup",value:.0625,type:"volume"},{name:"teaspoon",abbreviation:"tsp",value:.0208333,type:"volume"},{name:"tablespoon",abbreviation:"tbsp",value:.0625,type:"volume"},{name:"fluid ounce",abbreviation:"fl oz",value:.125,type:"volume"}],s=[...l,...v];0&&(module.exports={UNITS,VOLUME_UNITS,WEIGHT_UNITS});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c}from"../chunk-22RBQQWH.mjs";export{c as UNITS,b as VOLUME_UNITS,a as WEIGHT_UNITS};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { RecipeUtils } from './lib/recipe.mjs';
|
|
2
|
+
export { UnitUtils } from './lib/unit.mjs';
|
|
3
|
+
export { IngredientUtils } from './lib/ingredient.mjs';
|
|
4
|
+
export { GlobalRecipeConfig, Ingredient, IngredientAmount, Recipe, RecipeConfig, Unit, UnitAbbreviation, UnitKey, UnitName } from './types.mjs';
|
|
5
|
+
import './const/unit.mjs';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { RecipeUtils } from './lib/recipe.js';
|
|
2
|
+
export { UnitUtils } from './lib/unit.js';
|
|
3
|
+
export { IngredientUtils } from './lib/ingredient.js';
|
|
4
|
+
export { GlobalRecipeConfig, Ingredient, IngredientAmount, Recipe, RecipeConfig, Unit, UnitAbbreviation, UnitKey, UnitName } from './types.js';
|
|
5
|
+
import './const/unit.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var f=(o,e)=>{for(var t in e)l(o,t,{get:e[t],enumerable:!0})},U=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of y(e))!L.call(o,i)&&i!==t&&l(o,i,{get:()=>e[i],enumerable:!(n=T(e,i))||n.enumerable});return o};var d=o=>U(l({},"__esModule",{value:!0}),o);var R={};f(R,{IngredientUtils:()=>p,RecipeUtils:()=>s,UnitUtils:()=>a});module.exports=d(R);function b(o,e,t){if(!e(o))throw new Error(t)}function r(o,e,t){e(o)||console.warn(t)}var s=class{scopedMessageFactory(e){return t=>`${e.name}: ${t}`}validateConfig(e){if(!!0)return;let t=this.scopedMessageFactory(e);r(e.instructions,n=>n.length>0,t("Recipe has no instructions")),r(e.servings,n=>n!==void 0&&n<=0,t("Recipe has less than one serving")),r(e.ingredients,n=>n.length>0,t("Recipe has no ingredients"))}create(e){return this.validateConfig(e),{name:e.name,ingredients:e.ingredients,units:e.units,thumbnail:e.thumbnail,servings:e.servings??1,instructions:e.instructions??[]}}};var u={g:{g:1,kg:1e3,oz:28.3495,lb:453.592},kg:{g:.001,kg:1,oz:.0283495,lb:.453592},oz:{g:.035274,kg:35.274,oz:1,lb:16},lb:{g:.00220462,kg:2.20462,oz:.0625,lb:1}},v={L:{L:1,gal:3.78541,mL:.001,cup:.0625,tsp:.202884,tbsp:.067628},gal:{L:.264172,gal:1,mL:264172e-9,cup:.016,tsp:.0515037,tbsp:.0171679},mL:{L:1e3,gal:3785.41,mL:1,cup:.00422675,tsp:.033814,tbsp:.00422675},cup:{L:4.22675,gal:16,mL:236.588,cup:1,tsp:3.2,tbsp:1.06667},tsp:{L:4.92892,gal:18.6184,mL:4.92892,cup:.3125,tsp:1,tbsp:.333333},tbsp:{L:14.7868,gal:56,mL:14.7868,cup:.9375,tsp:3,tbsp:1}};var h=[{key:!0,name:"gram",abbreviation:"g",value:1,type:"weight"},{name:"kilogram",abbreviation:"kg",value:1e3,type:"weight"},{name:"ounce",abbreviation:"oz",value:28.3495,type:"weight"},{name:"pound",abbreviation:"lb",value:453.592,type:"weight"}],C=[{key:!0,name:"liter",abbreviation:"L",value:1,type:"volume"},{name:"gallon",abbreviation:"gal",value:3.78541,type:"volume"},{name:"milliliter",abbreviation:"mL",value:.001,type:"volume"},{name:"cup",abbreviation:"cup",value:.0625,type:"volume"},{name:"teaspoon",abbreviation:"tsp",value:.0208333,type:"volume"},{name:"tablespoon",abbreviation:"tbsp",value:.0625,type:"volume"},{name:"fluid ounce",abbreviation:"fl oz",value:.125,type:"volume"}],c=[...h,...C];var a=class{static getUnit(e){let t=c.find(n=>n.abbreviation===e||n.name===e);return b(t,n=>!!n,`No unit found for key: ${e}`),t}static getConversionRatio(e,t){let{type:n,abbreviation:i}=this.getUnit(e),m=(n==="volume"?v:u)[i];return b(m,g=>!!g[t],`No conversion table available for unit ${e} to ${t}`),m[t]}static convert(e,t,n){if(t===n)return e;let i=this.getConversionRatio(t,n);return e*i}};var p=class{convert(e,t){let n=a.convert(e.amount.value,e.amount.unit,t);return{...e,amount:{value:n,unit:t}}}};0&&(module.exports={IngredientUtils,RecipeUtils,UnitUtils});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunk-WBQAMGXK.mjs";import{a as i}from"./chunk-ULDLBAEG.mjs";import{a as t}from"./chunk-SR2KFBT3.mjs";import"./chunk-KXFUCO3R.mjs";import"./chunk-22RBQQWH.mjs";import{a as r}from"./chunk-CBLJXA6P.mjs";import"./chunk-C45UD45A.mjs";import"./chunk-3CSP4UZG.mjs";export{i as IngredientUtils,r as RecipeUtils,t as UnitUtils};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws an error if the assertion fails
|
|
3
|
+
*
|
|
4
|
+
* @param value - The value to assert
|
|
5
|
+
* @param assertion - The assertion to make
|
|
6
|
+
* @param message - The message to throw if the assertion fails
|
|
7
|
+
*/
|
|
8
|
+
declare function assert<T>(value: T, assertion: (value: T) => boolean, message: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Logs a warning in development if the assertion fails
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to assert
|
|
13
|
+
* @param assertion - The assertion to make
|
|
14
|
+
* @param message - The message to log if the assertion fails
|
|
15
|
+
*/
|
|
16
|
+
declare function warn<T>(value: T, assertion: (value: T) => boolean, message: string): void;
|
|
17
|
+
|
|
18
|
+
export { assert, warn };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws an error if the assertion fails
|
|
3
|
+
*
|
|
4
|
+
* @param value - The value to assert
|
|
5
|
+
* @param assertion - The assertion to make
|
|
6
|
+
* @param message - The message to throw if the assertion fails
|
|
7
|
+
*/
|
|
8
|
+
declare function assert<T>(value: T, assertion: (value: T) => boolean, message: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Logs a warning in development if the assertion fails
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to assert
|
|
13
|
+
* @param assertion - The assertion to make
|
|
14
|
+
* @param message - The message to log if the assertion fails
|
|
15
|
+
*/
|
|
16
|
+
declare function warn<T>(value: T, assertion: (value: T) => boolean, message: string): void;
|
|
17
|
+
|
|
18
|
+
export { assert, warn };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var s=(o,n)=>{for(var r in n)t(o,r,{get:n[r],enumerable:!0})},f=(o,n,r,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of T(n))!l.call(o,e)&&e!==r&&t(o,e,{get:()=>n[e],enumerable:!(a=i(n,e))||a.enumerable});return o};var u=o=>f(t({},"__esModule",{value:!0}),o);var b={};s(b,{assert:()=>w,warn:()=>c});module.exports=u(b);function w(o,n,r){if(!n(o))throw new Error(r)}function c(o,n,r){n(o)||console.warn(r)}0&&(module.exports={assert,warn});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b}from"../chunk-C45UD45A.mjs";export{a as assert,b as warn};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Ingredient, UnitKey } from '../types.mjs';
|
|
2
|
+
import '../const/unit.mjs';
|
|
3
|
+
|
|
4
|
+
declare abstract class IngredientUtils {
|
|
5
|
+
convert<TConversionTableKey extends string>(ingredient: Ingredient<TConversionTableKey>, to: UnitKey): Ingredient<TConversionTableKey>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { IngredientUtils };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Ingredient, UnitKey } from '../types.js';
|
|
2
|
+
import '../const/unit.js';
|
|
3
|
+
|
|
4
|
+
declare abstract class IngredientUtils {
|
|
5
|
+
convert<TConversionTableKey extends string>(ingredient: Ingredient<TConversionTableKey>, to: UnitKey): Ingredient<TConversionTableKey>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { IngredientUtils };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var r=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var y=(n,e)=>{for(var t in e)r(n,t,{get:e[t],enumerable:!0})},L=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of g(e))!T.call(n,a)&&a!==t&&r(n,a,{get:()=>e[a],enumerable:!(o=c(e,a))||o.enumerable});return n};var U=n=>L(r({},"__esModule",{value:!0}),n);var N={};y(N,{IngredientUtils:()=>b});module.exports=U(N);var p={g:{g:1,kg:1e3,oz:28.3495,lb:453.592},kg:{g:.001,kg:1,oz:.0283495,lb:.453592},oz:{g:.035274,kg:35.274,oz:1,lb:16},lb:{g:.00220462,kg:2.20462,oz:.0625,lb:1}},v={L:{L:1,gal:3.78541,mL:.001,cup:.0625,tsp:.202884,tbsp:.067628},gal:{L:.264172,gal:1,mL:264172e-9,cup:.016,tsp:.0515037,tbsp:.0171679},mL:{L:1e3,gal:3785.41,mL:1,cup:.00422675,tsp:.033814,tbsp:.00422675},cup:{L:4.22675,gal:16,mL:236.588,cup:1,tsp:3.2,tbsp:1.06667},tsp:{L:4.92892,gal:18.6184,mL:4.92892,cup:.3125,tsp:1,tbsp:.333333},tbsp:{L:14.7868,gal:56,mL:14.7868,cup:.9375,tsp:3,tbsp:1}};var f=[{key:!0,name:"gram",abbreviation:"g",value:1,type:"weight"},{name:"kilogram",abbreviation:"kg",value:1e3,type:"weight"},{name:"ounce",abbreviation:"oz",value:28.3495,type:"weight"},{name:"pound",abbreviation:"lb",value:453.592,type:"weight"}],E=[{key:!0,name:"liter",abbreviation:"L",value:1,type:"volume"},{name:"gallon",abbreviation:"gal",value:3.78541,type:"volume"},{name:"milliliter",abbreviation:"mL",value:.001,type:"volume"},{name:"cup",abbreviation:"cup",value:.0625,type:"volume"},{name:"teaspoon",abbreviation:"tsp",value:.0208333,type:"volume"},{name:"tablespoon",abbreviation:"tbsp",value:.0625,type:"volume"},{name:"fluid ounce",abbreviation:"fl oz",value:.125,type:"volume"}],u=[...f,...E];function s(n,e,t){if(!e(n))throw new Error(t)}var i=class{static getUnit(e){let t=u.find(o=>o.abbreviation===e||o.name===e);return s(t,o=>!!o,`No unit found for key: ${e}`),t}static getConversionRatio(e,t){let{type:o,abbreviation:a}=this.getUnit(e),l=(o==="volume"?v:p)[a];return s(l,m=>!!m[t],`No conversion table available for unit ${e} to ${t}`),l[t]}static convert(e,t,o){if(t===o)return e;let a=this.getConversionRatio(t,o);return e*a}};var b=class{convert(e,t){let o=i.convert(e.amount.value,e.amount.unit,t);return{...e,amount:{value:o,unit:t}}}};0&&(module.exports={IngredientUtils});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"../chunk-ULDLBAEG.mjs";import"../chunk-SR2KFBT3.mjs";import"../chunk-KXFUCO3R.mjs";import"../chunk-22RBQQWH.mjs";import"../chunk-C45UD45A.mjs";export{a as IngredientUtils};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RecipeConfig, Recipe } from '../types.mjs';
|
|
2
|
+
import '../const/unit.mjs';
|
|
3
|
+
|
|
4
|
+
declare abstract class RecipeUtils {
|
|
5
|
+
private scopedMessageFactory;
|
|
6
|
+
private validateConfig;
|
|
7
|
+
create<TConversionTableKey extends string>(config: RecipeConfig<TConversionTableKey>): Recipe<TConversionTableKey>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { RecipeUtils };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RecipeConfig, Recipe } from '../types.js';
|
|
2
|
+
import '../const/unit.js';
|
|
3
|
+
|
|
4
|
+
declare abstract class RecipeUtils {
|
|
5
|
+
private scopedMessageFactory;
|
|
6
|
+
private validateConfig;
|
|
7
|
+
create<TConversionTableKey extends string>(config: RecipeConfig<TConversionTableKey>): Recipe<TConversionTableKey>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { RecipeUtils };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var l=(i,e)=>{for(var n in e)a(i,n,{get:e[n],enumerable:!0})},c=(i,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of u(e))!g.call(i,r)&&r!==n&&a(i,r,{get:()=>e[r],enumerable:!(t=p(e,r))||t.enumerable});return i};var m=i=>c(a({},"__esModule",{value:!0}),i);var v={};l(v,{RecipeUtils:()=>o});module.exports=m(v);function s(i,e,n){e(i)||console.warn(n)}var o=class{scopedMessageFactory(e){return n=>`${e.name}: ${n}`}validateConfig(e){if(!!0)return;let n=this.scopedMessageFactory(e);s(e.instructions,t=>t.length>0,n("Recipe has no instructions")),s(e.servings,t=>t!==void 0&&t<=0,n("Recipe has less than one serving")),s(e.ingredients,t=>t.length>0,n("Recipe has no ingredients"))}create(e){return this.validateConfig(e),{name:e.name,ingredients:e.ingredients,units:e.units,thumbnail:e.thumbnail,servings:e.servings??1,instructions:e.instructions??[]}}};0&&(module.exports={RecipeUtils});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"../chunk-CBLJXA6P.mjs";import"../chunk-C45UD45A.mjs";import"../chunk-3CSP4UZG.mjs";export{a as RecipeUtils};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var x=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},D=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of s(t))!u.call(e,o)&&o!==r&&c(e,o,{get:()=>t[o],enumerable:!(n=p(t,o))||n.enumerable});return e};var E=e=>D(c({},"__esModule",{value:!0}),e);var S={};x(S,{IS_DEV:()=>I});module.exports=E(S);var I=!0;0&&(module.exports={IS_DEV});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"../chunk-3CSP4UZG.mjs";export{a as IS_DEV};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { UnitKey } from '../types.mjs';
|
|
2
|
+
import '../const/unit.mjs';
|
|
3
|
+
|
|
4
|
+
declare abstract class UnitUtils {
|
|
5
|
+
private static getUnit;
|
|
6
|
+
private static getConversionRatio;
|
|
7
|
+
/**
|
|
8
|
+
* Converts a number from one unit to another
|
|
9
|
+
*
|
|
10
|
+
* @param amount - The amount to convert
|
|
11
|
+
* @param from - The unit to convert from
|
|
12
|
+
* @param to - The unit to convert to
|
|
13
|
+
* @returns - The converted amount
|
|
14
|
+
*/
|
|
15
|
+
static convert(amount: number, from: UnitKey, to: UnitKey): number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { UnitUtils };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { UnitKey } from '../types.js';
|
|
2
|
+
import '../const/unit.js';
|
|
3
|
+
|
|
4
|
+
declare abstract class UnitUtils {
|
|
5
|
+
private static getUnit;
|
|
6
|
+
private static getConversionRatio;
|
|
7
|
+
/**
|
|
8
|
+
* Converts a number from one unit to another
|
|
9
|
+
*
|
|
10
|
+
* @param amount - The amount to convert
|
|
11
|
+
* @param from - The unit to convert from
|
|
12
|
+
* @param to - The unit to convert to
|
|
13
|
+
* @returns - The converted amount
|
|
14
|
+
*/
|
|
15
|
+
static convert(amount: number, from: UnitKey, to: UnitKey): number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { UnitUtils };
|
package/dist/lib/unit.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var T=(a,e)=>{for(var t in e)i(a,t,{get:e[t],enumerable:!0})},L=(a,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of m(e))!g.call(a,n)&&n!==t&&i(a,n,{get:()=>e[n],enumerable:!(o=c(e,n))||o.enumerable});return a};var y=a=>L(i({},"__esModule",{value:!0}),a);var N={};T(N,{UnitUtils:()=>b});module.exports=y(N);var l={g:{g:1,kg:1e3,oz:28.3495,lb:453.592},kg:{g:.001,kg:1,oz:.0283495,lb:.453592},oz:{g:.035274,kg:35.274,oz:1,lb:16},lb:{g:.00220462,kg:2.20462,oz:.0625,lb:1}},p={L:{L:1,gal:3.78541,mL:.001,cup:.0625,tsp:.202884,tbsp:.067628},gal:{L:.264172,gal:1,mL:264172e-9,cup:.016,tsp:.0515037,tbsp:.0171679},mL:{L:1e3,gal:3785.41,mL:1,cup:.00422675,tsp:.033814,tbsp:.00422675},cup:{L:4.22675,gal:16,mL:236.588,cup:1,tsp:3.2,tbsp:1.06667},tsp:{L:4.92892,gal:18.6184,mL:4.92892,cup:.3125,tsp:1,tbsp:.333333},tbsp:{L:14.7868,gal:56,mL:14.7868,cup:.9375,tsp:3,tbsp:1}};var E=[{key:!0,name:"gram",abbreviation:"g",value:1,type:"weight"},{name:"kilogram",abbreviation:"kg",value:1e3,type:"weight"},{name:"ounce",abbreviation:"oz",value:28.3495,type:"weight"},{name:"pound",abbreviation:"lb",value:453.592,type:"weight"}],U=[{key:!0,name:"liter",abbreviation:"L",value:1,type:"volume"},{name:"gallon",abbreviation:"gal",value:3.78541,type:"volume"},{name:"milliliter",abbreviation:"mL",value:.001,type:"volume"},{name:"cup",abbreviation:"cup",value:.0625,type:"volume"},{name:"teaspoon",abbreviation:"tsp",value:.0208333,type:"volume"},{name:"tablespoon",abbreviation:"tbsp",value:.0625,type:"volume"},{name:"fluid ounce",abbreviation:"fl oz",value:.125,type:"volume"}],v=[...E,...U];function r(a,e,t){if(!e(a))throw new Error(t)}var b=class{static getUnit(e){let t=v.find(o=>o.abbreviation===e||o.name===e);return r(t,o=>!!o,`No unit found for key: ${e}`),t}static getConversionRatio(e,t){let{type:o,abbreviation:n}=this.getUnit(e),s=(o==="volume"?p:l)[n];return r(s,u=>!!u[t],`No conversion table available for unit ${e} to ${t}`),s[t]}static convert(e,t,o){if(t===o)return e;let n=this.getConversionRatio(t,o);return e*n}};0&&(module.exports={UnitUtils});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"../chunk-SR2KFBT3.mjs";import"../chunk-KXFUCO3R.mjs";import"../chunk-22RBQQWH.mjs";import"../chunk-C45UD45A.mjs";export{a as UnitUtils};
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UNITS } from './const/unit.mjs';
|
|
2
|
+
|
|
3
|
+
type Unit = (typeof UNITS)[number];
|
|
4
|
+
type UnitName = Unit["name"];
|
|
5
|
+
type UnitAbbreviation = Unit["abbreviation"];
|
|
6
|
+
type UnitKey = UnitName | UnitAbbreviation;
|
|
7
|
+
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
8
|
+
type IngredientAmount = {
|
|
9
|
+
value: number;
|
|
10
|
+
unit: UnitKey;
|
|
11
|
+
};
|
|
12
|
+
type Ingredient<TConversionTableKey extends string> = {
|
|
13
|
+
name: string;
|
|
14
|
+
amount: IngredientAmount;
|
|
15
|
+
conversion?: Record<TConversionTableKey, IngredientAmount | UnitKey>;
|
|
16
|
+
notes?: string;
|
|
17
|
+
};
|
|
18
|
+
type GlobalRecipeConfig<TConversionTableKey extends string> = {
|
|
19
|
+
units: TConversionTableKey[];
|
|
20
|
+
};
|
|
21
|
+
type Recipe<TConversionTableKey extends string> = GlobalRecipeConfig<TConversionTableKey> & {
|
|
22
|
+
name: string;
|
|
23
|
+
thumbnail?: string;
|
|
24
|
+
ingredients: Ingredient<TConversionTableKey>[];
|
|
25
|
+
servings: number;
|
|
26
|
+
instructions: string[];
|
|
27
|
+
};
|
|
28
|
+
type recipeOmittableKeys = "servings";
|
|
29
|
+
type RecipeConfig<TConversionTableKey extends string> = PartialBy<Recipe<TConversionTableKey>, recipeOmittableKeys>;
|
|
30
|
+
|
|
31
|
+
export type { GlobalRecipeConfig, Ingredient, IngredientAmount, Recipe, RecipeConfig, Unit, UnitAbbreviation, UnitKey, UnitName };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UNITS } from './const/unit.js';
|
|
2
|
+
|
|
3
|
+
type Unit = (typeof UNITS)[number];
|
|
4
|
+
type UnitName = Unit["name"];
|
|
5
|
+
type UnitAbbreviation = Unit["abbreviation"];
|
|
6
|
+
type UnitKey = UnitName | UnitAbbreviation;
|
|
7
|
+
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
8
|
+
type IngredientAmount = {
|
|
9
|
+
value: number;
|
|
10
|
+
unit: UnitKey;
|
|
11
|
+
};
|
|
12
|
+
type Ingredient<TConversionTableKey extends string> = {
|
|
13
|
+
name: string;
|
|
14
|
+
amount: IngredientAmount;
|
|
15
|
+
conversion?: Record<TConversionTableKey, IngredientAmount | UnitKey>;
|
|
16
|
+
notes?: string;
|
|
17
|
+
};
|
|
18
|
+
type GlobalRecipeConfig<TConversionTableKey extends string> = {
|
|
19
|
+
units: TConversionTableKey[];
|
|
20
|
+
};
|
|
21
|
+
type Recipe<TConversionTableKey extends string> = GlobalRecipeConfig<TConversionTableKey> & {
|
|
22
|
+
name: string;
|
|
23
|
+
thumbnail?: string;
|
|
24
|
+
ingredients: Ingredient<TConversionTableKey>[];
|
|
25
|
+
servings: number;
|
|
26
|
+
instructions: string[];
|
|
27
|
+
};
|
|
28
|
+
type recipeOmittableKeys = "servings";
|
|
29
|
+
type RecipeConfig<TConversionTableKey extends string> = PartialBy<Recipe<TConversionTableKey>, recipeOmittableKeys>;
|
|
30
|
+
|
|
31
|
+
export type { GlobalRecipeConfig, Ingredient, IngredientAmount, Recipe, RecipeConfig, Unit, UnitAbbreviation, UnitKey, UnitName };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var r=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var y=(n,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of a(e))!p.call(n,t)&&t!==o&&r(n,t,{get:()=>e[t],enumerable:!(i=s(e,t))||i.enumerable});return n};var T=n=>y(r({},"__esModule",{value:!0}),n);var b={};module.exports=T(b);
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunk-WBQAMGXK.mjs";
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@recipe-book/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsup src",
|
|
14
|
+
"dev": "tsup src --watch"
|
|
15
|
+
}
|
|
16
|
+
}
|