@jclind/ingredient-parser 1.2.2 → 1.2.3

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.
@@ -1,3 +1,3 @@
1
- import { IngredientResponse } from '../../types.js';
2
- declare const ingredientParser: (ingrString: string, spoonacularAPIKey: string) => Promise<IngredientResponse>;
1
+ import { IngredientResponse, OptionsType } from '../../types.js';
2
+ declare const ingredientParser: (ingrString: string, spoonacularAPIKey: string, options: OptionsType) => Promise<IngredientResponse>;
3
3
  export default ingredientParser;
@@ -23,7 +23,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  const calculatePrice_js_1 = require("./calculatePrice.js");
24
24
  const parseIngredientString_js_1 = require("./parseIngredientString.js");
25
25
  const getIngredientInfo_js_1 = require("./getIngredientInfo.js");
26
- const ingredientParser = (ingrString, spoonacularAPIKey) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const ingredientParser = (ingrString, spoonacularAPIKey, options) => __awaiter(void 0, void 0, void 0, function* () {
27
27
  // const parsedIngr: ParsedIngredient = parse(ingrString, 'eng')
28
28
  const parsedIngr = (0, parseIngredientString_js_1.parseIngredientString)(ingrString);
29
29
  let ingrData = null;
@@ -38,10 +38,10 @@ const ingredientParser = (ingrString, spoonacularAPIKey) => __awaiter(void 0, vo
38
38
  };
39
39
  }
40
40
  if (parsedIngr.ingredient && ingrData) {
41
- const { estimatedPrices, meta, categoryPath, unit, unitShort, unitLong, original, id } = ingrData, reducedIngrData = __rest(ingrData, ["estimatedPrices", "meta", "categoryPath", "unit", "unitShort", "unitLong", "original", "id"]);
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
42
  const totalPrice = (0, calculatePrice_js_1.calculatePrice)(parsedIngr.quantity, parsedIngr.unit, estimatedPrices);
43
43
  const imagePath = `https://spoonacular.com/cdn/ingredients_100x100/${reducedIngrData.image}`;
44
- const updatedIngrData = Object.assign(Object.assign({}, reducedIngrData), { imagePath, totalPriceUSACents: totalPrice });
44
+ const updatedIngrData = Object.assign(Object.assign(Object.assign({}, reducedIngrData), { imagePath, totalPriceUSACents: totalPrice }), ((options === null || options === void 0 ? void 0 : options.returnNutritionData) && { nutrition }));
45
45
  return {
46
46
  ingredientData: updatedIngrData,
47
47
  parsedIngredient: parsedIngr,
@@ -43,11 +43,10 @@ const parseIngredientString = (ingrStr) => {
43
43
  return 'tbsp';
44
44
  }
45
45
  else {
46
- return 'tbsps';
46
+ return 'tbsp';
47
47
  }
48
48
  });
49
49
  const parsedIngrRes = (0, parseStringConsecutiveTs_js_1.parseStringConsecutiveTs)(prepIngrText);
50
- console.log(parsedIngrRes);
51
50
  if (!parsedIngrRes.ingredient) {
52
51
  return Object.assign(Object.assign({}, parsedIngrRes), { originalIngredientString: ingrStr, comment });
53
52
  }
@@ -26,12 +26,11 @@ const replaceModifiedWords = (words, str) => {
26
26
  };
27
27
  const parseStringConsecutiveTs = (ingrStr) => {
28
28
  var _a;
29
- // Fixes bug where words with 'tt' in them will replace
29
+ // const ingrStrToLower = ingrStr.toLowerCase()
30
30
  const removeTTsIngrName = ingrStr.replace(/t{2,}/g, '');
31
31
  const modifiedWords = removeConsecutiveTs(ingrStr);
32
32
  if (modifiedWords.length > 0) {
33
33
  const parsedIngrNoTs = (0, recipe_ingredient_parser_v3_1.parse)(removeTTsIngrName, 'eng');
34
- console.log('parsedIngrNoTs', parsedIngrNoTs);
35
34
  const correctIngrStr = replaceModifiedWords(modifiedWords, (_a = parsedIngrNoTs.ingredient) !== null && _a !== void 0 ? _a : '');
36
35
  const parsedIngr = Object.assign(Object.assign({}, parsedIngrNoTs), { ingredient: correctIngrStr });
37
36
  return parsedIngr;
package/dist/types.d.ts CHANGED
@@ -70,4 +70,7 @@ export interface WeightPerServing {
70
70
  amount: number;
71
71
  unit: string;
72
72
  }
73
+ export type OptionsType = {
74
+ returnNutritionData: boolean;
75
+ };
73
76
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jclind/ingredient-parser",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Parses given sentence including ingredient information and attempts to return quantity, measurement and ingredient data",
5
5
  "keywords": [
6
6
  "recipe",