@jclind/ingredient-parser 1.0.41 → 1.1.0
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.d.ts +2 -2
- package/dist/index.js +10 -2
- package/dist/{api → src/api}/requests.d.ts +1 -1
- package/dist/{funcs → src/funcs}/calculatePrice.js +1 -2
- package/dist/{funcs → src/funcs}/ingredientParser.d.ts +1 -1
- package/dist/{funcs → src/funcs}/parseIngredientString.d.ts +1 -1
- package/dist/{funcs → src/funcs}/parseIngredientString.js +3 -2
- package/dist/src/funcs/parseStringConsecutiveTs.d.ts +4 -0
- package/dist/src/funcs/parseStringConsecutiveTs.js +43 -0
- package/dist/types.d.ts +73 -0
- package/dist/types.js +2 -0
- package/package.json +4 -2
- /package/dist/{api → src/api}/http.d.ts +0 -0
- /package/dist/{api → src/api}/http.js +0 -0
- /package/dist/{api → src/api}/requests.js +0 -0
- /package/dist/{funcs → src/funcs}/calculatePrice.d.ts +0 -0
- /package/dist/{funcs → src/funcs}/convertFractions.d.ts +0 -0
- /package/dist/{funcs → src/funcs}/convertFractions.js +0 -0
- /package/dist/{funcs → src/funcs}/getIngredientInfo.d.ts +0 -0
- /package/dist/{funcs → src/funcs}/getIngredientInfo.js +0 -0
- /package/dist/{funcs → src/funcs}/getSpoonacularIngrData.d.ts +0 -0
- /package/dist/{funcs → src/funcs}/getSpoonacularIngrData.js +0 -0
- /package/dist/{funcs → src/funcs}/ingredientParser.js +0 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,6 +15,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.ingredientParser = void 0;
|
|
18
|
-
const ingredientParser_1 = require("./funcs/ingredientParser");
|
|
18
|
+
const ingredientParser_1 = require("./src/funcs/ingredientParser");
|
|
19
19
|
exports.ingredientParser = ingredientParser_1.default;
|
|
20
|
-
|
|
20
|
+
// const test = async () => {
|
|
21
|
+
// const ingrData = await ingredientParser(
|
|
22
|
+
// '1 lb boneless skinless chicken breast',
|
|
23
|
+
// 'e8064d74f9804ebd82a947fb7b86189b'
|
|
24
|
+
// )
|
|
25
|
+
// return console.log(ingrData)
|
|
26
|
+
// }
|
|
27
|
+
// test()
|
|
28
|
+
__exportStar(require("./types"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IngredientData } from '
|
|
1
|
+
import { IngredientData } from '../../types.js';
|
|
2
2
|
export declare const checkIngredient: (name: string) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
3
3
|
export declare const searchIngredient: (name: string, spoonacularAPIKey: string) => Promise<any>;
|
|
4
4
|
export declare const getIngredientInformation: (ingrId: number, unit: boolean, spoonacularAPIKey: string) => Promise<any>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculatePrice = void 0;
|
|
4
|
-
//@ts-ignore
|
|
5
4
|
const ingredient_unit_converter_1 = require("@jclind/ingredient-unit-converter");
|
|
6
5
|
const calculatePrice = (quantity, unit, price) => {
|
|
7
6
|
if (!quantity)
|
|
@@ -15,7 +14,7 @@ const calculatePrice = (quantity, unit, price) => {
|
|
|
15
14
|
catch (error) {
|
|
16
15
|
return null;
|
|
17
16
|
}
|
|
18
|
-
if (!convertedUnit || convertedUnit
|
|
17
|
+
if (!convertedUnit || 'error' in convertedUnit)
|
|
19
18
|
return price.estimatedSingleUnitPrice * quantity;
|
|
20
19
|
const convertedGrams = Number(convertedUnit.quantity);
|
|
21
20
|
const total = convertedGrams * price.estimatedGramPrice;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ParsedIngredient } from '
|
|
1
|
+
import { ParsedIngredient } from '../../types.js';
|
|
2
2
|
export declare const parseIngredientString: (ingrStr: string) => ParsedIngredient;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseIngredientString = void 0;
|
|
4
|
-
const recipe_ingredient_parser_v3_1 = require("recipe-ingredient-parser-v3");
|
|
5
4
|
// import { ParsedIngredient } from '../../index.js'
|
|
6
5
|
const convertFractions_js_1 = require("./convertFractions.js");
|
|
6
|
+
const parseStringConsecutiveTs_js_1 = require("./parseStringConsecutiveTs.js");
|
|
7
7
|
const parseIngredientString = (ingrStr) => {
|
|
8
8
|
var _a, _b;
|
|
9
9
|
// Define regular expressions for text inside parentheses and text before the first comma
|
|
@@ -41,7 +41,8 @@ const parseIngredientString = (ingrStr) => {
|
|
|
41
41
|
return 'pounds';
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
|
-
const parsedIngrRes = (0,
|
|
44
|
+
const parsedIngrRes = (0, parseStringConsecutiveTs_js_1.parseStringConsecutiveTs)(prepIngrText);
|
|
45
|
+
console.log(parsedIngrRes);
|
|
45
46
|
if (!parsedIngrRes.ingredient) {
|
|
46
47
|
return Object.assign(Object.assign({}, parsedIngrRes), { originalIngredientString: ingrStr, comment });
|
|
47
48
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseStringConsecutiveTs = void 0;
|
|
4
|
+
const recipe_ingredient_parser_v3_1 = require("recipe-ingredient-parser-v3");
|
|
5
|
+
// returns words that have consecutive t's with those t's removed in a string array
|
|
6
|
+
const removeConsecutiveTs = (str) => {
|
|
7
|
+
const regex = /t{2,}/gi;
|
|
8
|
+
const words = str.split(' ');
|
|
9
|
+
const modifiedWords = words
|
|
10
|
+
.map(word => {
|
|
11
|
+
const modified = word.replace(regex, '');
|
|
12
|
+
return {
|
|
13
|
+
original: word,
|
|
14
|
+
modified: modified,
|
|
15
|
+
};
|
|
16
|
+
})
|
|
17
|
+
.filter(({ original, modified }) => original !== modified && modified !== '');
|
|
18
|
+
return modifiedWords;
|
|
19
|
+
};
|
|
20
|
+
const replaceModifiedWords = (words, str) => {
|
|
21
|
+
let updatedStr = str;
|
|
22
|
+
words.forEach(({ original, modified }) => {
|
|
23
|
+
updatedStr = updatedStr.replace(modified, original);
|
|
24
|
+
});
|
|
25
|
+
return updatedStr;
|
|
26
|
+
};
|
|
27
|
+
const parseStringConsecutiveTs = (ingrStr) => {
|
|
28
|
+
var _a;
|
|
29
|
+
// Fixes bug where words with 'tt' in them will replace
|
|
30
|
+
const removeTTsIngrName = ingrStr.replace(/t{2,}/g, '');
|
|
31
|
+
const modifiedWords = removeConsecutiveTs(ingrStr);
|
|
32
|
+
if (modifiedWords.length > 0) {
|
|
33
|
+
const parsedIngrNoTs = (0, recipe_ingredient_parser_v3_1.parse)(removeTTsIngrName, 'eng');
|
|
34
|
+
console.log('parsedIngrNoTs', parsedIngrNoTs);
|
|
35
|
+
const correctIngrStr = replaceModifiedWords(modifiedWords, (_a = parsedIngrNoTs.ingredient) !== null && _a !== void 0 ? _a : '');
|
|
36
|
+
const parsedIngr = Object.assign(Object.assign({}, parsedIngrNoTs), { ingredient: correctIngrStr });
|
|
37
|
+
return parsedIngr;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return (0, recipe_ingredient_parser_v3_1.parse)(ingrStr, 'eng');
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.parseStringConsecutiveTs = parseStringConsecutiveTs;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
type StringOrNull = string | null;
|
|
2
|
+
type NumberOrNull = number | null;
|
|
3
|
+
export type IngredientResponse = {
|
|
4
|
+
parsedIngredient: ParsedIngredient;
|
|
5
|
+
ingredientData: IngredientData;
|
|
6
|
+
id?: string;
|
|
7
|
+
} | {
|
|
8
|
+
error: {
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
11
|
+
parsedIngredient: ParsedIngredient;
|
|
12
|
+
ingredientData: IngredientData | null;
|
|
13
|
+
id?: string;
|
|
14
|
+
};
|
|
15
|
+
export type ParsedIngredient = {
|
|
16
|
+
quantity: NumberOrNull;
|
|
17
|
+
unit: StringOrNull;
|
|
18
|
+
unitPlural: StringOrNull;
|
|
19
|
+
symbol: StringOrNull;
|
|
20
|
+
ingredient: StringOrNull;
|
|
21
|
+
originalIngredientString: string;
|
|
22
|
+
minQty: NumberOrNull;
|
|
23
|
+
maxQty: NumberOrNull;
|
|
24
|
+
comment: StringOrNull;
|
|
25
|
+
};
|
|
26
|
+
export interface IngredientData {
|
|
27
|
+
_id: string;
|
|
28
|
+
ingredientId: number;
|
|
29
|
+
originalName: string;
|
|
30
|
+
name: string;
|
|
31
|
+
amount: number;
|
|
32
|
+
possibleUnits: string[];
|
|
33
|
+
consistency: string;
|
|
34
|
+
shoppingListUnits: string[];
|
|
35
|
+
aisle: string;
|
|
36
|
+
image: string;
|
|
37
|
+
imagePath: string;
|
|
38
|
+
nutrition: Nutrition;
|
|
39
|
+
totalPriceUSACents: number;
|
|
40
|
+
}
|
|
41
|
+
export interface Nutrition {
|
|
42
|
+
nutrients: Nutrient[];
|
|
43
|
+
properties: Property[];
|
|
44
|
+
flavonoids: Flavonoid[];
|
|
45
|
+
caloricBreakdown: CaloricBreakdown;
|
|
46
|
+
weightPerServing: WeightPerServing;
|
|
47
|
+
}
|
|
48
|
+
export interface Nutrient {
|
|
49
|
+
name: string;
|
|
50
|
+
amount: number;
|
|
51
|
+
unit: string;
|
|
52
|
+
percentOfDailyNeeds: number;
|
|
53
|
+
}
|
|
54
|
+
export interface Property {
|
|
55
|
+
name: string;
|
|
56
|
+
amount: number;
|
|
57
|
+
unit: string;
|
|
58
|
+
}
|
|
59
|
+
export interface Flavonoid {
|
|
60
|
+
name: string;
|
|
61
|
+
amount: number;
|
|
62
|
+
unit: string;
|
|
63
|
+
}
|
|
64
|
+
export interface CaloricBreakdown {
|
|
65
|
+
percentProtein: number;
|
|
66
|
+
percentFat: number;
|
|
67
|
+
percentCarbs: number;
|
|
68
|
+
}
|
|
69
|
+
export interface WeightPerServing {
|
|
70
|
+
amount: number;
|
|
71
|
+
unit: string;
|
|
72
|
+
}
|
|
73
|
+
export {};
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jclind/ingredient-parser",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Parses given sentence including ingredient information and attempts to return quantity, measurement and ingredient data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"recipe",
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
"units"
|
|
10
10
|
],
|
|
11
11
|
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"type": "commonjs",
|
|
12
14
|
"files": [
|
|
13
15
|
"dist"
|
|
14
16
|
],
|
|
@@ -26,7 +28,7 @@
|
|
|
26
28
|
},
|
|
27
29
|
"homepage": "https://github.com/jclind/ingredient-parser#readme",
|
|
28
30
|
"dependencies": {
|
|
29
|
-
"@jclind/ingredient-unit-converter": "^1.0.
|
|
31
|
+
"@jclind/ingredient-unit-converter": "^1.0.5",
|
|
30
32
|
"@types/axios": "^0.14.0",
|
|
31
33
|
"convert-units": "^2.3.4",
|
|
32
34
|
"dotenv": "^16.0.3",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|