@jclind/ingredient-parser 1.2.8 → 1.2.10

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 CHANGED
@@ -1,3 +1,4 @@
1
- import ingredientParser from './src/funcs/ingredientParser';
2
- export { ingredientParser };
3
- export * from './types';
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
- // 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
+ "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);
@@ -1,2 +1 @@
1
- export declare const mongoHttp: import("axios").AxiosInstance;
2
- export declare const spoonacularHttp: import("axios").AxiosInstance;
1
+ export declare const spoonacularHttp: import("axios").AxiosInstance;
@@ -1,16 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.spoonacularHttp = exports.mongoHttp = void 0;
4
- const axios_1 = require("axios");
5
- exports.mongoHttp = axios_1.default.create({
6
- baseURL: 'https://us-east-1.aws.data.mongodb-api.com/app/prepify-ixumn/endpoint',
7
- headers: {
8
- 'Content-type': 'application/json',
9
- },
10
- });
11
- exports.spoonacularHttp = axios_1.default.create({
12
- baseURL: 'https://api.spoonacular.com/food/ingredients/',
13
- headers: {
14
- 'Content-type': 'application/json',
15
- },
16
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.spoonacularHttp = void 0;
4
+ const axios_1 = require("axios");
5
+ exports.spoonacularHttp = axios_1.default.create({
6
+ baseURL: 'https://api.spoonacular.com/food/ingredients/',
7
+ headers: {
8
+ 'Content-type': 'application/json',
9
+ },
10
+ });
@@ -1,5 +1,2 @@
1
- import { IngredientData } from '../../types.js';
2
- export declare const checkIngredient: (name: string) => Promise<import("axios").AxiosResponse<any, any>>;
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
+ export declare const searchIngredient: (name: string, spoonacularAPIKey: string) => Promise<any>;
2
+ export declare const getIngredientInformation: (ingrId: number, unit: boolean, spoonacularAPIKey: string) => Promise<any>;
@@ -1,55 +1,47 @@
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.setMongoDBIngrData = exports.getIngredientInformation = exports.searchIngredient = exports.checkIngredient = void 0;
13
- const http_js_1 = require("./http.js");
14
- const checkIngredient = (name) => __awaiter(void 0, void 0, void 0, function* () {
15
- return yield http_js_1.mongoHttp.get(`checkIngredient?name=${name}`);
16
- });
17
- exports.checkIngredient = checkIngredient;
18
- const searchIngredient = (name, spoonacularAPIKey) => __awaiter(void 0, void 0, void 0, function* () {
19
- let searchedIngr;
20
- try {
21
- searchedIngr = yield http_js_1.spoonacularHttp.get(`search?query=${name}&number=1&apiKey=${spoonacularAPIKey}`);
22
- }
23
- catch (error) {
24
- const res = error.response.data;
25
- if (res.code === 401) {
26
- throw new Error('API Key Not Valid');
27
- }
28
- else {
29
- throw new Error('Error Occurred, Please Try Again');
30
- }
31
- }
32
- return searchedIngr;
33
- });
34
- exports.searchIngredient = searchIngredient;
35
- const getIngredientInformation = (ingrId, unit, spoonacularAPIKey) => __awaiter(void 0, void 0, void 0, function* () {
36
- let ingrData;
37
- try {
38
- ingrData = yield http_js_1.spoonacularHttp.get(`${ingrId}/information?amount=1&${unit ? 'unit=grams&' : ''}apiKey=${spoonacularAPIKey}`);
39
- }
40
- catch (error) {
41
- const res = error.response.data;
42
- if (res.code === 401) {
43
- throw new Error('API Key Not Valid');
44
- }
45
- else {
46
- throw new Error('Error Occurred, Please Try Again');
47
- }
48
- }
49
- return ingrData;
50
- });
51
- exports.getIngredientInformation = getIngredientInformation;
52
- const setMongoDBIngrData = (data) => __awaiter(void 0, void 0, void 0, function* () {
53
- return yield http_js_1.mongoHttp.post(`addIngredient`, data);
54
- });
55
- exports.setMongoDBIngrData = setMongoDBIngrData;
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 = void 0;
13
+ const http_js_1 = require("./http.js");
14
+ const searchIngredient = (name, spoonacularAPIKey) => __awaiter(void 0, void 0, void 0, function* () {
15
+ let searchedIngr;
16
+ try {
17
+ searchedIngr = yield http_js_1.spoonacularHttp.get(`search?query=${name}&number=1&apiKey=${spoonacularAPIKey}`);
18
+ }
19
+ catch (error) {
20
+ const res = error.response.data;
21
+ if (res.code === 401) {
22
+ throw new Error('API Key Not Valid');
23
+ }
24
+ else {
25
+ throw new Error('Error Occurred, Please Try Again');
26
+ }
27
+ }
28
+ return searchedIngr;
29
+ });
30
+ exports.searchIngredient = searchIngredient;
31
+ const getIngredientInformation = (ingrId, unit, spoonacularAPIKey) => __awaiter(void 0, void 0, void 0, function* () {
32
+ let ingrData;
33
+ try {
34
+ ingrData = yield http_js_1.spoonacularHttp.get(`${ingrId}/information?amount=1&${unit ? 'unit=grams&' : ''}apiKey=${spoonacularAPIKey}`);
35
+ }
36
+ catch (error) {
37
+ const res = error.response.data;
38
+ if (res.code === 401) {
39
+ throw new Error('API Key Not Valid');
40
+ }
41
+ else {
42
+ throw new Error('Error Occurred, Please Try Again');
43
+ }
44
+ }
45
+ return ingrData;
46
+ });
47
+ exports.getIngredientInformation = getIngredientInformation;
@@ -1,4 +1,4 @@
1
- export declare const calculatePrice: (quantity: number | null, unit: string | null, price: {
2
- estimatedSingleUnitPrice: number;
3
- estimatedGramPrice: number;
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,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
- if (!quantity)
7
- return price.estimatedSingleUnitPrice;
8
- if (!unit)
9
- return price.estimatedSingleUnitPrice * quantity;
10
- let convertedUnit;
11
- try {
12
- convertedUnit = (0, ingredient_unit_converter_1.converter)(quantity, unit);
13
- }
14
- catch (error) {
15
- return null;
16
- }
17
- if (!convertedUnit || 'error' in convertedUnit)
18
- return price.estimatedSingleUnitPrice * quantity;
19
- const convertedGrams = Number(convertedUnit.quantity);
20
- const total = convertedGrams * price.estimatedGramPrice;
21
- return Math.ceil(total * 100) / 100;
22
- };
23
- exports.calculatePrice = calculatePrice;
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
+ if (quantity === null)
7
+ return price.estimatedSingleUnitPrice;
8
+ if (!unit)
9
+ return price.estimatedSingleUnitPrice * quantity;
10
+ let convertedUnit;
11
+ try {
12
+ convertedUnit = (0, ingredient_unit_converter_1.converter)(quantity, unit);
13
+ }
14
+ catch (error) {
15
+ return null;
16
+ }
17
+ if (!convertedUnit || 'error' in convertedUnit)
18
+ return price.estimatedSingleUnitPrice * quantity;
19
+ const convertedGrams = Number(convertedUnit.quantity);
20
+ const total = convertedGrams * price.estimatedGramPrice;
21
+ return Math.ceil(total * 100) / 100;
22
+ };
23
+ 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
- const re = new RegExp(fraction, 'g');
27
- str = str.replace(re, value);
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 @@
1
- export declare function getIngredientInfo(ingrName: string, spoonacularAPIKey: string): Promise<any>;
1
+ export declare function getIngredientInfo(ingrName: string, spoonacularAPIKey: string): Promise<any>;
@@ -1,30 +1,22 @@
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 = void 0;
13
- const requests_js_1 = require("../api/requests.js");
14
- const getSpoonacularIngrData_js_1 = require("./getSpoonacularIngrData.js");
15
- function getIngredientInfo(ingrName, spoonacularAPIKey) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const ingrNameLower = ingrName.toLowerCase();
18
- if (!ingrNameLower)
19
- throw new Error('Ingredient Invalid');
20
- const mongoIngrData = yield (0, requests_js_1.checkIngredient)(ingrNameLower);
21
- if (!mongoIngrData.data) {
22
- const ingrData = yield (0, getSpoonacularIngrData_js_1.getSpoonacularIngrData)(ingrNameLower, spoonacularAPIKey);
23
- return ingrData;
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 getSpoonacularIngrData_js_1 = require("./getSpoonacularIngrData.js");
14
+ function getIngredientInfo(ingrName, spoonacularAPIKey) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const ingrNameLower = ingrName.toLowerCase();
17
+ if (!ingrNameLower)
18
+ throw new Error('Ingredient Invalid');
19
+ const ingrData = yield (0, getSpoonacularIngrData_js_1.getSpoonacularIngrData)(ingrNameLower, spoonacularAPIKey);
20
+ return ingrData;
21
+ });
22
+ }
@@ -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 = void 0;
13
- const requests_js_1 = require("../api/requests.js");
14
- function getSpoonacularIngrData(name, spoonacularAPIKey) {
15
- var _a, _b, _c;
16
- return __awaiter(this, void 0, void 0, function* () {
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
- const mongoDBIngrData = ingrData;
31
- const mongoRes = yield (0, requests_js_1.setMongoDBIngrData)(mongoDBIngrData);
32
- const _id = mongoRes.data.insertedId;
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,62 @@
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
- // const parsedIngr: ParsedIngredient = parse(ingrString, 'eng')
28
- const parsedIngr = (0, parseIngredientString_js_1.parseIngredientString)(ingrString);
29
- let ingrData = null;
30
- try {
31
- ingrData = yield (0, getIngredientInfo_js_1.getIngredientInfo)(parsedIngr.ingredient || '', spoonacularAPIKey);
32
- }
33
- catch (error) {
34
- return {
35
- error: { message: error.message },
36
- ingredientData: null,
37
- parsedIngredient: parsedIngr !== null && parsedIngr !== void 0 ? parsedIngr : null,
38
- };
39
- }
40
- if (parsedIngr.ingredient && ingrData) {
41
- const { estimatedPrices, meta, categoryPath, unit, unitShort, unitLong, original, id, nutrition } = ingrData, reducedIngrData = __rest(ingrData, ["estimatedPrices", "meta", "categoryPath", "unit", "unitShort", "unitLong", "original", "id", "nutrition"]);
42
- const totalPrice = (0, calculatePrice_js_1.calculatePrice)(parsedIngr.quantity, parsedIngr.unit, estimatedPrices);
43
- const imagePath = `https://spoonacular.com/cdn/ingredients_100x100/${reducedIngrData.image}`;
44
- const updatedIngrData = Object.assign(Object.assign(Object.assign({}, reducedIngrData), { imagePath, totalPriceUSACents: totalPrice }), ((options === null || options === void 0 ? void 0 : options.returnNutritionData) && { nutrition }));
45
- return {
46
- ingredientData: updatedIngrData,
47
- parsedIngredient: parsedIngr,
48
- };
49
- }
50
- else {
51
- return {
52
- error: {
53
- message: 'Ingredient not formatted correctly or Ingredient Unknown. Please pass ingredient comments/instructions after a comma',
54
- },
55
- ingredientData: null,
56
- parsedIngredient: parsedIngr,
57
- };
58
- }
59
- });
60
- exports.default = ingredientParser;
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);
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 = (0, calculatePrice_js_1.calculatePrice)(parsedIngr.quantity, parsedIngr.unit, estimatedPrices);
44
+ const imageSize = (_a = options === null || options === void 0 ? void 0 : options.imageSize) !== null && _a !== void 0 ? _a : '100x100';
45
+ const imagePath = `https://spoonacular.com/cdn/ingredients_${imageSize}/${reducedIngrData.image}`;
46
+ const updatedIngrData = Object.assign(Object.assign(Object.assign({}, reducedIngrData), { imagePath, totalPriceUSACents: totalPrice }), ((options === null || options === void 0 ? void 0 : options.returnNutritionData) && { nutrition }));
47
+ return {
48
+ ingredientData: updatedIngrData,
49
+ parsedIngredient: parsedIngr,
50
+ };
51
+ }
52
+ else {
53
+ return {
54
+ error: {
55
+ message: 'Ingredient not formatted correctly or Ingredient Unknown. Please pass ingredient comments/instructions after a comma',
56
+ },
57
+ ingredientData: null,
58
+ parsedIngredient: parsedIngr,
59
+ };
60
+ }
61
+ });
62
+ 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
- // import { ParsedIngredient } from '../../index.js'
5
- const convertFractions_js_1 = require("./convertFractions.js");
6
- const parseStringConsecutiveTs_js_1 = require("./parseStringConsecutiveTs.js");
7
- const parseIngredientString = (ingrStr) => {
8
- var _a, _b;
9
- // Define regular expressions for text inside parentheses and text before the first comma
10
- const parenRegex = /(\(.*?\))/;
11
- const commaRegex = /^(.*?)(?=,)/;
12
- // Extract the text inside the parentheses and the text before the first comma using regular expressions
13
- const parenthesesStr = (_b = (_a = ingrStr.match(parenRegex)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : '';
14
- const textWithoutParenthesesStr = ingrStr.replace(parenthesesStr, '');
15
- // Find the index of the first ',' character
16
- const commaIndex = textWithoutParenthesesStr.indexOf(',');
17
- let ingrText;
18
- let comment;
19
- // If there is no comma in the string don't include a comment
20
- if (commaIndex !== -1) {
21
- ingrText = (0, convertFractions_js_1.convertFractions)(textWithoutParenthesesStr
22
- .substring(0, commaIndex)
23
- .replace(parenRegex, '')
24
- .trim());
25
- comment = (textWithoutParenthesesStr
26
- .replace(parenRegex, '')
27
- .substring(commaIndex + 1) +
28
- ' ' +
29
- parenthesesStr).trim();
30
- }
31
- else {
32
- ingrText = (0, convertFractions_js_1.convertFractions)(ingrStr.replace(parenRegex, '').trim());
33
- comment = parenthesesStr.trim();
34
- }
35
- const prepIngrText = ingrText.replace(/\b(lb|lbs|tablespoon|tablespoon)\b/gi, match => {
36
- if (match === 'lb') {
37
- return 'pound';
38
- }
39
- else if (match === 'lbs') {
40
- return 'pounds';
41
- }
42
- else if (match === 'tablespoon') {
43
- return 'tbsp';
44
- }
45
- else {
46
- return 'tbsp';
47
- }
48
- });
49
- const parsedIngrRes = (0, parseStringConsecutiveTs_js_1.parseStringConsecutiveTs)(prepIngrText);
50
- if (!parsedIngrRes.ingredient) {
51
- return Object.assign(Object.assign({}, parsedIngrRes), { originalIngredientString: ingrStr, comment });
52
- }
53
- const wordsToRemove = ['small', 'medium', 'large', 'fresh', 'canned'];
54
- const regex = new RegExp('\\b(' + wordsToRemove.join('|') + ')\\b', 'gi');
55
- const formattedIngrName = parsedIngrRes.ingredient
56
- .trim()
57
- .replace(/\s{2,}/g, ' ') // Replace multiple whitespace characters with a single space
58
- .replace(/,/g, '') // Remove commas
59
- .replace(/^(fluid|fl|oz) /, '') // Remove "fluid ", "fl ", or "oz " at the beginning of the string
60
- .replace(regex, '')
61
- .trim();
62
- return Object.assign(Object.assign({}, parsedIngrRes), { ingredient: formattedIngrName, originalIngredientString: ingrStr, comment });
63
- };
64
- exports.parseIngredientString = parseIngredientString;
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,45 +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 ingrStrToLower = ingrStr.toLowerCase()
30
- const removeTTsIngrName = ingrStr.replace(/t{2,}/g, '');
31
- const modifiedWords = removeConsecutiveTs(ingrStr);
32
- console.log(modifiedWords);
33
- if (modifiedWords.length > 0) {
34
- const parsedIngrNoTs = (0, recipe_ingredient_parser_v3_1.parse)(removeTTsIngrName, 'eng');
35
- console.log(parsedIngrNoTs);
36
- const correctIngrStr = replaceModifiedWords(modifiedWords, (_a = parsedIngrNoTs.ingredient) !== null && _a !== void 0 ? _a : '');
37
- console.log(correctIngrStr);
38
- const parsedIngr = Object.assign(Object.assign({}, parsedIngrNoTs), { ingredient: correctIngrStr });
39
- return parsedIngr;
40
- }
41
- else {
42
- return (0, recipe_ingredient_parser_v3_1.parse)(ingrStr, 'eng');
43
- }
44
- };
45
- 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,78 @@
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 type OptionsType = {
74
- returnNutritionData: boolean;
75
- };
76
- export {};
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 type SpoonacularImageSize = '100x100' | '250x250' | '500x500';
74
+ export type OptionsType = {
75
+ returnNutritionData?: boolean;
76
+ imageSize?: SpoonacularImageSize;
77
+ };
78
+ 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.8",
3
+ "version": "1.2.10",
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": "del dist\\ && tsc"
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.5",
32
- "@types/axios": "^0.14.0",
33
- "convert-units": "^2.3.4",
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/node": "^18.11.18",
41
- "typescript": "^4.9.4"
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
  }