@jclind/ingredient-parser 1.2.9 → 1.2.11
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 +4 -3
- package/dist/index.js +30 -28
- package/dist/src/api/http.d.ts +2 -2
- package/dist/src/api/http.js +18 -16
- package/dist/src/api/requests.d.ts +4 -5
- package/dist/src/api/requests.js +57 -55
- package/dist/src/funcs/calculatePrice.d.ts +4 -4
- package/dist/src/funcs/calculatePrice.js +26 -23
- package/dist/src/funcs/convertFractions.d.ts +1 -1
- package/dist/src/funcs/convertFractions.js +31 -31
- package/dist/src/funcs/getIngredientInfo.d.ts +2 -1
- package/dist/src/funcs/getIngredientInfo.js +23 -30
- package/dist/src/funcs/getSpoonacularIngrData.d.ts +1 -1
- package/dist/src/funcs/getSpoonacularIngrData.js +32 -36
- package/dist/src/funcs/ingredientParser.d.ts +3 -3
- package/dist/src/funcs/ingredientParser.js +64 -60
- package/dist/src/funcs/parseIngredientString.d.ts +2 -2
- package/dist/src/funcs/parseIngredientString.js +74 -64
- package/dist/src/funcs/parseStringConsecutiveTs.d.ts +4 -4
- package/dist/src/funcs/parseStringConsecutiveTs.js +41 -41
- package/dist/types.d.ts +90 -76
- package/dist/types.js +2 -2
- package/package.json +19 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import ingredientParser from './src/funcs/ingredientParser';
|
|
2
|
-
export { ingredientParser };
|
|
3
|
-
export
|
|
1
|
+
import ingredientParser from './src/funcs/ingredientParser';
|
|
2
|
+
export { ingredientParser };
|
|
3
|
+
export { parseIngredientString } from './src/funcs/parseIngredientString';
|
|
4
|
+
export * from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ingredientParser = void 0;
|
|
18
|
-
const ingredientParser_1 = require("./src/funcs/ingredientParser");
|
|
19
|
-
exports.ingredientParser = ingredientParser_1.default;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.parseIngredientString = exports.ingredientParser = void 0;
|
|
18
|
+
const ingredientParser_1 = require("./src/funcs/ingredientParser");
|
|
19
|
+
exports.ingredientParser = ingredientParser_1.default;
|
|
20
|
+
var parseIngredientString_1 = require("./src/funcs/parseIngredientString");
|
|
21
|
+
Object.defineProperty(exports, "parseIngredientString", { enumerable: true, get: function () { return parseIngredientString_1.parseIngredientString; } });
|
|
22
|
+
// const test = async () => {
|
|
23
|
+
// const ingrData = await ingredientParser(
|
|
24
|
+
// '1 lb boneless skinless chicken breast',
|
|
25
|
+
// 'e8064d74f9804ebd82a947fb7b86189b'
|
|
26
|
+
// )
|
|
27
|
+
// return console.log(ingrData)
|
|
28
|
+
// }
|
|
29
|
+
// test()
|
|
30
|
+
__exportStar(require("./types"), exports);
|
package/dist/src/api/http.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
1
|
+
export declare const spoonacularHttp: import("axios").AxiosInstance;
|
|
2
|
+
export declare const createIngredientServerHttp: (serverUrl?: string) => import("axios").AxiosInstance;
|
package/dist/src/api/http.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const axios_1 = require("axios");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createIngredientServerHttp = exports.spoonacularHttp = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const DEFAULT_SERVER_URL = 'https://prepify-ingredients.up.railway.app';
|
|
6
|
+
exports.spoonacularHttp = axios_1.default.create({
|
|
7
|
+
baseURL: 'https://api.spoonacular.com/food/ingredients/',
|
|
8
|
+
headers: {
|
|
9
|
+
'Content-type': 'application/json',
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
const createIngredientServerHttp = (serverUrl) => axios_1.default.create({
|
|
13
|
+
baseURL: serverUrl || DEFAULT_SERVER_URL,
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-type': 'application/json',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
exports.createIngredientServerHttp = createIngredientServerHttp;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IngredientData } from '../../types.js';
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const searchIngredient: (name: string, spoonacularAPIKey: string) => Promise<any>;
|
|
4
|
-
export declare const getIngredientInformation: (ingrId: number, unit: boolean, spoonacularAPIKey: string) => Promise<any>;
|
|
5
|
-
export declare const setMongoDBIngrData: (data: IngredientData) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
1
|
+
import { IngredientData } from '../../types.js';
|
|
2
|
+
export declare const parseAndEnrich: (ingredientString: string, spoonacularApiKey: string, serverUrl?: string) => Promise<IngredientData | null>;
|
|
3
|
+
export declare const searchIngredient: (name: string, spoonacularAPIKey: string) => Promise<any>;
|
|
4
|
+
export declare const getIngredientInformation: (ingrId: number, unit: boolean, spoonacularAPIKey: string) => Promise<any>;
|
package/dist/src/api/requests.js
CHANGED
|
@@ -1,55 +1,57 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
const http_js_1 = require("./http.js");
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getIngredientInformation = exports.searchIngredient = exports.parseAndEnrich = void 0;
|
|
13
|
+
const http_js_1 = require("./http.js");
|
|
14
|
+
const parseAndEnrich = (ingredientString, spoonacularApiKey, serverUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
var _a;
|
|
16
|
+
const serverHttp = (0, http_js_1.createIngredientServerHttp)(serverUrl);
|
|
17
|
+
const response = yield serverHttp.post('/parse', {
|
|
18
|
+
ingredientString,
|
|
19
|
+
spoonacularApiKey,
|
|
20
|
+
});
|
|
21
|
+
return (_a = response.data.data) !== null && _a !== void 0 ? _a : null;
|
|
22
|
+
});
|
|
23
|
+
exports.parseAndEnrich = parseAndEnrich;
|
|
24
|
+
const searchIngredient = (name, spoonacularAPIKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
let searchedIngr;
|
|
26
|
+
try {
|
|
27
|
+
searchedIngr = yield http_js_1.spoonacularHttp.get(`search?query=${name}&number=1&apiKey=${spoonacularAPIKey}`);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
const res = error.response.data;
|
|
31
|
+
if (res.code === 401) {
|
|
32
|
+
throw new Error('API Key Not Valid');
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error('Error Occurred, Please Try Again');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return searchedIngr;
|
|
39
|
+
});
|
|
40
|
+
exports.searchIngredient = searchIngredient;
|
|
41
|
+
const getIngredientInformation = (ingrId, unit, spoonacularAPIKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
let ingrData;
|
|
43
|
+
try {
|
|
44
|
+
ingrData = yield http_js_1.spoonacularHttp.get(`${ingrId}/information?amount=1&${unit ? 'unit=grams&' : ''}apiKey=${spoonacularAPIKey}`);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
const res = error.response.data;
|
|
48
|
+
if (res.code === 401) {
|
|
49
|
+
throw new Error('API Key Not Valid');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error('Error Occurred, Please Try Again');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return ingrData;
|
|
56
|
+
});
|
|
57
|
+
exports.getIngredientInformation = getIngredientInformation;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const calculatePrice: (quantity: number | null, unit: string | null, price: {
|
|
2
|
-
estimatedSingleUnitPrice
|
|
3
|
-
estimatedGramPrice
|
|
4
|
-
}) => number | null;
|
|
1
|
+
export declare const calculatePrice: (quantity: number | null, unit: string | null, price: {
|
|
2
|
+
estimatedSingleUnitPrice?: number;
|
|
3
|
+
estimatedGramPrice?: number;
|
|
4
|
+
}) => number | null;
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculatePrice = void 0;
|
|
4
|
-
const ingredient_unit_converter_1 = require("@jclind/ingredient-unit-converter");
|
|
5
|
-
const calculatePrice = (quantity, unit, price) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculatePrice = void 0;
|
|
4
|
+
const ingredient_unit_converter_1 = require("@jclind/ingredient-unit-converter");
|
|
5
|
+
const calculatePrice = (quantity, unit, price) => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const gramPrice = (_a = price.estimatedGramPrice) !== null && _a !== void 0 ? _a : 0;
|
|
8
|
+
const unitPrice = (_b = price.estimatedSingleUnitPrice) !== null && _b !== void 0 ? _b : 0;
|
|
9
|
+
if (quantity === null)
|
|
10
|
+
return unitPrice || null;
|
|
11
|
+
if (!unit)
|
|
12
|
+
return (unitPrice * quantity) || null;
|
|
13
|
+
let convertedUnit;
|
|
14
|
+
try {
|
|
15
|
+
convertedUnit = (0, ingredient_unit_converter_1.converter)(quantity, unit);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
if (!convertedUnit || 'error' in convertedUnit)
|
|
21
|
+
return (unitPrice * quantity) || null;
|
|
22
|
+
const convertedGrams = Number(convertedUnit.quantity);
|
|
23
|
+
const total = convertedGrams * gramPrice;
|
|
24
|
+
return Math.ceil(total * 100) / 100;
|
|
25
|
+
};
|
|
26
|
+
exports.calculatePrice = calculatePrice;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const convertFractions: (str: string) => string;
|
|
1
|
+
export declare const convertFractions: (str: string) => string;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertFractions = void 0;
|
|
4
|
-
const convertFractions = (str) => {
|
|
5
|
-
const fractions = {
|
|
6
|
-
'¼': '1/4',
|
|
7
|
-
'½': '1/2',
|
|
8
|
-
'¾': '3/4',
|
|
9
|
-
'⅓': '1/3',
|
|
10
|
-
'⅔': '2/3',
|
|
11
|
-
'⅛': '1/8',
|
|
12
|
-
'⅜': '3/8',
|
|
13
|
-
'⅝': '5/8',
|
|
14
|
-
'⅞': '7/8',
|
|
15
|
-
'⅕': '1/5',
|
|
16
|
-
'⅖': '2/5',
|
|
17
|
-
'⅗': '3/5',
|
|
18
|
-
'⅘': '4/5',
|
|
19
|
-
'⅙': '1/6',
|
|
20
|
-
'⅚': '5/6',
|
|
21
|
-
'⅐': '1/7',
|
|
22
|
-
'⅑': '1/9',
|
|
23
|
-
'⅒': '1/10',
|
|
24
|
-
};
|
|
25
|
-
for (const [fraction, value] of Object.entries(fractions)) {
|
|
26
|
-
|
|
27
|
-
str = str.replace(
|
|
28
|
-
}
|
|
29
|
-
return str;
|
|
30
|
-
};
|
|
31
|
-
exports.convertFractions = convertFractions;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertFractions = void 0;
|
|
4
|
+
const convertFractions = (str) => {
|
|
5
|
+
const fractions = {
|
|
6
|
+
'¼': '1/4',
|
|
7
|
+
'½': '1/2',
|
|
8
|
+
'¾': '3/4',
|
|
9
|
+
'⅓': '1/3',
|
|
10
|
+
'⅔': '2/3',
|
|
11
|
+
'⅛': '1/8',
|
|
12
|
+
'⅜': '3/8',
|
|
13
|
+
'⅝': '5/8',
|
|
14
|
+
'⅞': '7/8',
|
|
15
|
+
'⅕': '1/5',
|
|
16
|
+
'⅖': '2/5',
|
|
17
|
+
'⅗': '3/5',
|
|
18
|
+
'⅘': '4/5',
|
|
19
|
+
'⅙': '1/6',
|
|
20
|
+
'⅚': '5/6',
|
|
21
|
+
'⅐': '1/7',
|
|
22
|
+
'⅑': '1/9',
|
|
23
|
+
'⅒': '1/10',
|
|
24
|
+
};
|
|
25
|
+
for (const [fraction, value] of Object.entries(fractions)) {
|
|
26
|
+
str = str.replace(new RegExp(`(\\d)${fraction}`, 'g'), `$1 ${value}`);
|
|
27
|
+
str = str.replace(new RegExp(fraction, 'g'), value);
|
|
28
|
+
}
|
|
29
|
+
return str;
|
|
30
|
+
};
|
|
31
|
+
exports.convertFractions = convertFractions;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { IngredientData } from '../../types.js';
|
|
2
|
+
export declare function getIngredientInfo(ingredientString: string, spoonacularAPIKey: string, serverUrl?: string): Promise<IngredientData | null>;
|
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getIngredientInfo =
|
|
13
|
-
const requests_js_1 = require("../api/requests.js");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
return mongoIngrData.data;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
exports.getIngredientInfo = getIngredientInfo;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getIngredientInfo = getIngredientInfo;
|
|
13
|
+
const requests_js_1 = require("../api/requests.js");
|
|
14
|
+
function getIngredientInfo(ingredientString, spoonacularAPIKey, serverUrl) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
return yield (0, requests_js_1.parseAndEnrich)(ingredientString, spoonacularAPIKey, serverUrl);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new Error(error.message || 'Failed to fetch ingredient data');
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getSpoonacularIngrData(name: string, spoonacularAPIKey: string): Promise<any>;
|
|
1
|
+
export declare function getSpoonacularIngrData(name: string, spoonacularAPIKey: string): Promise<any>;
|
|
@@ -1,36 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getSpoonacularIngrData =
|
|
13
|
-
const requests_js_1 = require("../api/requests.js");
|
|
14
|
-
function getSpoonacularIngrData(name, spoonacularAPIKey) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const searchedIngr = yield (0, requests_js_1.searchIngredient)(name, spoonacularAPIKey);
|
|
18
|
-
if (searchedIngr.error)
|
|
19
|
-
return searchedIngr;
|
|
20
|
-
const ingrId = (_c = (_b = (_a = searchedIngr === null || searchedIngr === void 0 ? void 0 : searchedIngr.data) === null || _a === void 0 ? void 0 : _a.results[0]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : null;
|
|
21
|
-
if (!ingrId)
|
|
22
|
-
throw new Error(`No Data Found, unknown ingredient: ${name}`);
|
|
23
|
-
const ingrDataGram = yield (0, requests_js_1.getIngredientInformation)(ingrId, true, spoonacularAPIKey);
|
|
24
|
-
const ingrDataSingleUnit = yield (0, requests_js_1.getIngredientInformation)(ingrId, false, spoonacularAPIKey);
|
|
25
|
-
if (ingrDataGram.error || ingrDataSingleUnit.error)
|
|
26
|
-
return ingrDataGram;
|
|
27
|
-
const estimatedGramPrice = ingrDataGram.data.estimatedCost.value;
|
|
28
|
-
const estimatedSingleUnitPrice = ingrDataSingleUnit.data.estimatedCost.value;
|
|
29
|
-
const ingrData = Object.assign(Object.assign({}, ingrDataGram.data), { name, ingredientId: ingrId, estimatedPrices: { estimatedGramPrice, estimatedSingleUnitPrice } });
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return Object.assign(Object.assign({}, mongoDBIngrData), { _id });
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
exports.getSpoonacularIngrData = getSpoonacularIngrData;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getSpoonacularIngrData = getSpoonacularIngrData;
|
|
13
|
+
const requests_js_1 = require("../api/requests.js");
|
|
14
|
+
function getSpoonacularIngrData(name, spoonacularAPIKey) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
17
|
+
const searchedIngr = yield (0, requests_js_1.searchIngredient)(name, spoonacularAPIKey);
|
|
18
|
+
if (searchedIngr.error)
|
|
19
|
+
return searchedIngr;
|
|
20
|
+
const ingrId = (_c = (_b = (_a = searchedIngr === null || searchedIngr === void 0 ? void 0 : searchedIngr.data) === null || _a === void 0 ? void 0 : _a.results[0]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : null;
|
|
21
|
+
if (!ingrId)
|
|
22
|
+
throw new Error(`No Data Found, unknown ingredient: ${name}`);
|
|
23
|
+
const ingrDataGram = yield (0, requests_js_1.getIngredientInformation)(ingrId, true, spoonacularAPIKey);
|
|
24
|
+
const ingrDataSingleUnit = yield (0, requests_js_1.getIngredientInformation)(ingrId, false, spoonacularAPIKey);
|
|
25
|
+
if (ingrDataGram.error || ingrDataSingleUnit.error)
|
|
26
|
+
return ingrDataGram;
|
|
27
|
+
const estimatedGramPrice = (_e = (_d = ingrDataGram.data.estimatedCost) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : 0;
|
|
28
|
+
const estimatedSingleUnitPrice = (_g = (_f = ingrDataSingleUnit.data.estimatedCost) === null || _f === void 0 ? void 0 : _f.value) !== null && _g !== void 0 ? _g : 0;
|
|
29
|
+
const ingrData = Object.assign(Object.assign({}, ingrDataGram.data), { name, ingredientId: ingrId, estimatedPrices: { estimatedGramPrice, estimatedSingleUnitPrice } });
|
|
30
|
+
return ingrData;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IngredientResponse, OptionsType } from '../../types.js';
|
|
2
|
-
declare const ingredientParser: (ingrString: string, spoonacularAPIKey: string, options?: OptionsType) => Promise<IngredientResponse>;
|
|
3
|
-
export default ingredientParser;
|
|
1
|
+
import { IngredientResponse, OptionsType } from '../../types.js';
|
|
2
|
+
declare const ingredientParser: (ingrString: string, spoonacularAPIKey: string, options?: OptionsType) => Promise<IngredientResponse>;
|
|
3
|
+
export default ingredientParser;
|
|
@@ -1,60 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
const calculatePrice_js_1 = require("./calculatePrice.js");
|
|
24
|
-
const parseIngredientString_js_1 = require("./parseIngredientString.js");
|
|
25
|
-
const getIngredientInfo_js_1 = require("./getIngredientInfo.js");
|
|
26
|
-
const ingredientParser = (ingrString, spoonacularAPIKey, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
|
|
28
|
-
const parsedIngr = (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
const calculatePrice_js_1 = require("./calculatePrice.js");
|
|
24
|
+
const parseIngredientString_js_1 = require("./parseIngredientString.js");
|
|
25
|
+
const getIngredientInfo_js_1 = require("./getIngredientInfo.js");
|
|
26
|
+
const ingredientParser = (ingrString, spoonacularAPIKey, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
var _a;
|
|
28
|
+
// const parsedIngr: ParsedIngredient = parse(ingrString, 'eng')
|
|
29
|
+
const parsedIngr = (0, parseIngredientString_js_1.parseIngredientString)(ingrString);
|
|
30
|
+
let ingrData = null;
|
|
31
|
+
try {
|
|
32
|
+
ingrData = yield (0, getIngredientInfo_js_1.getIngredientInfo)(parsedIngr.ingredient || '', spoonacularAPIKey, options === null || options === void 0 ? void 0 : options.serverUrl);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return {
|
|
36
|
+
error: { message: error.message },
|
|
37
|
+
ingredientData: null,
|
|
38
|
+
parsedIngredient: parsedIngr !== null && parsedIngr !== void 0 ? parsedIngr : null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (parsedIngr.ingredient && ingrData) {
|
|
42
|
+
const { estimatedPrices, meta, categoryPath, unit, unitShort, unitLong, original, id, nutrition } = ingrData, reducedIngrData = __rest(ingrData, ["estimatedPrices", "meta", "categoryPath", "unit", "unitShort", "unitLong", "original", "id", "nutrition"]);
|
|
43
|
+
const totalPrice = estimatedPrices
|
|
44
|
+
? (0, calculatePrice_js_1.calculatePrice)(parsedIngr.quantity, parsedIngr.unit, estimatedPrices)
|
|
45
|
+
: null;
|
|
46
|
+
const imageSize = (_a = options === null || options === void 0 ? void 0 : options.imageSize) !== null && _a !== void 0 ? _a : '100x100';
|
|
47
|
+
const imagePath = `https://spoonacular.com/cdn/ingredients_${imageSize}/${reducedIngrData.image}`;
|
|
48
|
+
const updatedIngrData = Object.assign(Object.assign(Object.assign(Object.assign({}, reducedIngrData), { imagePath }), (totalPrice !== null && { totalPriceUSACents: totalPrice })), ((options === null || options === void 0 ? void 0 : options.returnNutritionData) && { nutrition }));
|
|
49
|
+
return {
|
|
50
|
+
ingredientData: updatedIngrData,
|
|
51
|
+
parsedIngredient: parsedIngr,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return {
|
|
56
|
+
error: {
|
|
57
|
+
message: 'Ingredient not formatted correctly or Ingredient Unknown. Please pass ingredient comments/instructions after a comma',
|
|
58
|
+
},
|
|
59
|
+
ingredientData: null,
|
|
60
|
+
parsedIngredient: parsedIngr,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
exports.default = ingredientParser;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ParsedIngredient } from '../../types.js';
|
|
2
|
-
export declare const parseIngredientString: (ingrStr: string) => ParsedIngredient;
|
|
1
|
+
import { ParsedIngredient } from '../../types.js';
|
|
2
|
+
export declare const parseIngredientString: (ingrStr: string) => ParsedIngredient;
|
|
@@ -1,64 +1,74 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseIngredientString = void 0;
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseIngredientString = void 0;
|
|
4
|
+
const convertFractions_js_1 = require("./convertFractions.js");
|
|
5
|
+
const parseStringConsecutiveTs_js_1 = require("./parseStringConsecutiveTs.js");
|
|
6
|
+
const parseIngredientString = (ingrStr) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
// Define regular expressions for text inside parentheses and text before the first comma
|
|
9
|
+
const parenRegex = /(\(.*?\))/;
|
|
10
|
+
const commaRegex = /^(.*?)(?=,)/;
|
|
11
|
+
// Extract the text inside the parentheses and the text before the first comma using regular expressions
|
|
12
|
+
const parenthesesStr = (_b = (_a = ingrStr.match(parenRegex)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : '';
|
|
13
|
+
const textWithoutParenthesesStr = ingrStr.replace(parenthesesStr, '');
|
|
14
|
+
// Find the index of the first ',' character
|
|
15
|
+
const commaIndex = textWithoutParenthesesStr.indexOf(',');
|
|
16
|
+
let ingrText;
|
|
17
|
+
let comment;
|
|
18
|
+
// If there is no comma in the string don't include a comment
|
|
19
|
+
if (commaIndex !== -1) {
|
|
20
|
+
ingrText = (0, convertFractions_js_1.convertFractions)(textWithoutParenthesesStr
|
|
21
|
+
.substring(0, commaIndex)
|
|
22
|
+
.replace(parenRegex, '')
|
|
23
|
+
.trim());
|
|
24
|
+
comment = (textWithoutParenthesesStr
|
|
25
|
+
.replace(parenRegex, '')
|
|
26
|
+
.substring(commaIndex + 1) +
|
|
27
|
+
' ' +
|
|
28
|
+
parenthesesStr).trim();
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
ingrText = (0, convertFractions_js_1.convertFractions)(ingrStr.replace(parenRegex, '').trim());
|
|
32
|
+
comment = parenthesesStr.trim();
|
|
33
|
+
}
|
|
34
|
+
const unitNormalizations = {
|
|
35
|
+
tablespoons: 'tbsp',
|
|
36
|
+
tablespoon: 'tbsp',
|
|
37
|
+
teaspoons: 'teaspoon',
|
|
38
|
+
milliliters: 'milliliter',
|
|
39
|
+
millilitres: 'milliliter',
|
|
40
|
+
kilograms: 'kilogram',
|
|
41
|
+
ounces: 'ounce',
|
|
42
|
+
pounds: 'pound',
|
|
43
|
+
grams: 'gram',
|
|
44
|
+
tsps: 'teaspoon',
|
|
45
|
+
tsp: 'teaspoon',
|
|
46
|
+
lbs: 'pounds',
|
|
47
|
+
oz: 'ounce',
|
|
48
|
+
kg: 'kilogram',
|
|
49
|
+
ml: 'milliliter',
|
|
50
|
+
lb: 'pound',
|
|
51
|
+
g: 'gram',
|
|
52
|
+
};
|
|
53
|
+
const unitPattern = new RegExp('\\b(' + Object.keys(unitNormalizations).join('|') + ')\\b', 'gi');
|
|
54
|
+
const prepIngrText = ingrText.replace(unitPattern, match => { var _a; return (_a = unitNormalizations[match.toLowerCase()]) !== null && _a !== void 0 ? _a : match; });
|
|
55
|
+
const parsedIngrRes = (0, parseStringConsecutiveTs_js_1.parseStringConsecutiveTs)(prepIngrText);
|
|
56
|
+
if (!parsedIngrRes.ingredient) {
|
|
57
|
+
return Object.assign(Object.assign({}, parsedIngrRes), { originalIngredientString: ingrStr, comment });
|
|
58
|
+
}
|
|
59
|
+
const wordsToRemove = ['small', 'medium', 'large', 'fresh', 'canned'];
|
|
60
|
+
const regex = new RegExp('\\b(' + wordsToRemove.join('|') + ')\\b', 'gi');
|
|
61
|
+
const descriptorSet = new Set(wordsToRemove.map(w => w.toLowerCase()));
|
|
62
|
+
const unit = parsedIngrRes.unit && descriptorSet.has(parsedIngrRes.unit.toLowerCase())
|
|
63
|
+
? null
|
|
64
|
+
: parsedIngrRes.unit;
|
|
65
|
+
const formattedIngrName = parsedIngrRes.ingredient
|
|
66
|
+
.trim()
|
|
67
|
+
.replace(/\s{2,}/g, ' ') // Replace multiple whitespace characters with a single space
|
|
68
|
+
.replace(/,/g, '') // Remove commas
|
|
69
|
+
.replace(/^(fluid|fl|oz) /, '') // Remove "fluid ", "fl ", or "oz " at the beginning of the string
|
|
70
|
+
.replace(regex, '')
|
|
71
|
+
.trim();
|
|
72
|
+
return Object.assign(Object.assign({}, parsedIngrRes), { unit, ingredient: formattedIngrName, originalIngredientString: ingrStr, comment });
|
|
73
|
+
};
|
|
74
|
+
exports.parseIngredientString = parseIngredientString;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParsedIngredient } from '../../types';
|
|
2
|
-
type ParsedIngredientOmitType = Omit<ParsedIngredient, 'originalIngredientString' | 'comment'>;
|
|
3
|
-
export declare const parseStringConsecutiveTs: (ingrStr: string) => ParsedIngredientOmitType;
|
|
4
|
-
export {};
|
|
1
|
+
import { ParsedIngredient } from '../../types.js';
|
|
2
|
+
type ParsedIngredientOmitType = Omit<ParsedIngredient, 'originalIngredientString' | 'comment'>;
|
|
3
|
+
export declare const parseStringConsecutiveTs: (ingrStr: string) => ParsedIngredientOmitType;
|
|
4
|
+
export {};
|
|
@@ -1,41 +1,41 @@
|
|
|
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.toLowerCase(), original.toLowerCase());
|
|
24
|
-
});
|
|
25
|
-
return updatedStr;
|
|
26
|
-
};
|
|
27
|
-
const parseStringConsecutiveTs = (ingrStr) => {
|
|
28
|
-
var _a;
|
|
29
|
-
const removeTTsIngrName = ingrStr.replace(/t{2,}/g, '');
|
|
30
|
-
const modifiedWords = removeConsecutiveTs(ingrStr);
|
|
31
|
-
if (modifiedWords.length > 0) {
|
|
32
|
-
const parsedIngrNoTs = (0, recipe_ingredient_parser_v3_1.parse)(removeTTsIngrName, 'eng');
|
|
33
|
-
const correctIngrStr = replaceModifiedWords(modifiedWords, (_a = parsedIngrNoTs.ingredient) !== null && _a !== void 0 ? _a : '');
|
|
34
|
-
const parsedIngr = Object.assign(Object.assign({}, parsedIngrNoTs), { ingredient: correctIngrStr });
|
|
35
|
-
return parsedIngr;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return (0, recipe_ingredient_parser_v3_1.parse)(ingrStr, 'eng');
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
exports.parseStringConsecutiveTs = parseStringConsecutiveTs;
|
|
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.toLowerCase(), original.toLowerCase());
|
|
24
|
+
});
|
|
25
|
+
return updatedStr;
|
|
26
|
+
};
|
|
27
|
+
const parseStringConsecutiveTs = (ingrStr) => {
|
|
28
|
+
var _a;
|
|
29
|
+
const removeTTsIngrName = ingrStr.replace(/t{2,}/g, '');
|
|
30
|
+
const modifiedWords = removeConsecutiveTs(ingrStr);
|
|
31
|
+
if (modifiedWords.length > 0) {
|
|
32
|
+
const parsedIngrNoTs = (0, recipe_ingredient_parser_v3_1.parse)(removeTTsIngrName, 'eng');
|
|
33
|
+
const correctIngrStr = replaceModifiedWords(modifiedWords, (_a = parsedIngrNoTs.ingredient) !== null && _a !== void 0 ? _a : '');
|
|
34
|
+
const parsedIngr = Object.assign(Object.assign({}, parsedIngrNoTs), { ingredient: correctIngrStr });
|
|
35
|
+
return parsedIngr;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return (0, recipe_ingredient_parser_v3_1.parse)(ingrStr, 'eng');
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.parseStringConsecutiveTs = parseStringConsecutiveTs;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,76 +1,90 @@
|
|
|
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
|
|
28
|
-
ingredientId
|
|
29
|
-
originalName
|
|
30
|
-
name: string;
|
|
31
|
-
amount
|
|
32
|
-
possibleUnits
|
|
33
|
-
consistency
|
|
34
|
-
shoppingListUnits
|
|
35
|
-
aisle
|
|
36
|
-
image
|
|
37
|
-
imagePath
|
|
38
|
-
nutrition
|
|
39
|
-
totalPriceUSACents
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
export interface
|
|
60
|
-
name: string;
|
|
61
|
-
amount: number;
|
|
62
|
-
unit: string;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
+
estimatedPrices?: {
|
|
41
|
+
estimatedGramPrice?: number;
|
|
42
|
+
estimatedSingleUnitPrice?: number;
|
|
43
|
+
};
|
|
44
|
+
meta?: any;
|
|
45
|
+
categoryPath?: any;
|
|
46
|
+
unit?: string;
|
|
47
|
+
unitShort?: string;
|
|
48
|
+
unitLong?: string;
|
|
49
|
+
original?: any;
|
|
50
|
+
id?: number;
|
|
51
|
+
}
|
|
52
|
+
export interface Nutrition {
|
|
53
|
+
nutrients: Nutrient[];
|
|
54
|
+
properties: Property[];
|
|
55
|
+
flavonoids: Flavonoid[];
|
|
56
|
+
caloricBreakdown: CaloricBreakdown;
|
|
57
|
+
weightPerServing: WeightPerServing;
|
|
58
|
+
}
|
|
59
|
+
export interface Nutrient {
|
|
60
|
+
name: string;
|
|
61
|
+
amount: number;
|
|
62
|
+
unit: string;
|
|
63
|
+
percentOfDailyNeeds: number;
|
|
64
|
+
}
|
|
65
|
+
export interface Property {
|
|
66
|
+
name: string;
|
|
67
|
+
amount: number;
|
|
68
|
+
unit: string;
|
|
69
|
+
}
|
|
70
|
+
export interface Flavonoid {
|
|
71
|
+
name: string;
|
|
72
|
+
amount: number;
|
|
73
|
+
unit: string;
|
|
74
|
+
}
|
|
75
|
+
export interface CaloricBreakdown {
|
|
76
|
+
percentProtein: number;
|
|
77
|
+
percentFat: number;
|
|
78
|
+
percentCarbs: number;
|
|
79
|
+
}
|
|
80
|
+
export interface WeightPerServing {
|
|
81
|
+
amount: number;
|
|
82
|
+
unit: string;
|
|
83
|
+
}
|
|
84
|
+
export type SpoonacularImageSize = '100x100' | '250x250' | '500x500';
|
|
85
|
+
export type OptionsType = {
|
|
86
|
+
returnNutritionData?: boolean;
|
|
87
|
+
imageSize?: SpoonacularImageSize;
|
|
88
|
+
serverUrl?: string;
|
|
89
|
+
};
|
|
90
|
+
export {};
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jclind/ingredient-parser",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.11",
|
|
4
4
|
"description": "Parses given sentence including ingredient information and attempts to return quantity, measurement and ingredient data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"recipe",
|
|
@@ -15,7 +15,15 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
|
-
"build": "
|
|
18
|
+
"build": "rimraf dist && tsc",
|
|
19
|
+
"test": "jest"
|
|
20
|
+
},
|
|
21
|
+
"jest": {
|
|
22
|
+
"preset": "ts-jest",
|
|
23
|
+
"testEnvironment": "node",
|
|
24
|
+
"moduleNameMapper": {
|
|
25
|
+
"^(\\.{1,2}/.*)\\.js$": "$1"
|
|
26
|
+
}
|
|
19
27
|
},
|
|
20
28
|
"repository": {
|
|
21
29
|
"type": "git",
|
|
@@ -28,16 +36,16 @@
|
|
|
28
36
|
},
|
|
29
37
|
"homepage": "https://github.com/jclind/ingredient-parser#readme",
|
|
30
38
|
"dependencies": {
|
|
31
|
-
"@jclind/ingredient-unit-converter": "^1.0.
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"dotenv": "^16.0.3",
|
|
35
|
-
"parse-ingredient": "^0.6.0",
|
|
36
|
-
"recipe-ingredient-parser-v3": "^1.2.18",
|
|
37
|
-
"uuid": "^9.0.0"
|
|
39
|
+
"@jclind/ingredient-unit-converter": "^1.0.6",
|
|
40
|
+
"axios": "^1.0.0",
|
|
41
|
+
"recipe-ingredient-parser-v3": "^1.5.0"
|
|
38
42
|
},
|
|
39
43
|
"devDependencies": {
|
|
40
|
-
"@types/
|
|
41
|
-
"
|
|
44
|
+
"@types/jest": "^30.0.0",
|
|
45
|
+
"@types/node": "^22.0.0",
|
|
46
|
+
"jest": "^30.3.0",
|
|
47
|
+
"rimraf": "^5.0.0",
|
|
48
|
+
"ts-jest": "^29.4.9",
|
|
49
|
+
"typescript": "^5.0.0"
|
|
42
50
|
}
|
|
43
51
|
}
|