@jclind/ingredient-parser 1.0.36 → 1.0.38

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/decs.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare module 'recipe-ingredient-parser-v3'
2
+ declare module 'react-native-uuid'
@@ -1,4 +1,4 @@
1
- import { IngredientData } from '../../index.js';
1
+ import { IngredientData } from '@jclind/ingredient-parser';
2
2
  export declare const checkIngredient: (name: string) => Promise<import("axios").AxiosResponse<any, any>>;
3
3
  export declare const searchIngredient: (name: string, spoonacularAPIKey: string) => Promise<any>;
4
4
  export declare const getIngredientInformation: (ingrId: number, unit: boolean, spoonacularAPIKey: string) => Promise<any>;
@@ -1,3 +1,3 @@
1
- import { IngredientResponse } from '../../index.js';
1
+ import { IngredientResponse } from '@jclind/ingredient-parser';
2
2
  declare const ingredientParser: (ingrString: string, spoonacularAPIKey: string) => Promise<IngredientResponse>;
3
3
  export default ingredientParser;
@@ -1,2 +1,2 @@
1
- import { ParsedIngredient } from '../../index.js';
1
+ import { ParsedIngredient } from '@jclind/ingredient-parser';
2
2
  export declare const parseIngredientString: (ingrStr: string) => ParsedIngredient;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseIngredientString = void 0;
4
4
  const recipe_ingredient_parser_v3_1 = require("recipe-ingredient-parser-v3");
5
+ // import { ParsedIngredient } from '../../index.js'
5
6
  const convertFractions_js_1 = require("./convertFractions.js");
6
7
  const parseIngredientString = (ingrStr) => {
7
8
  var _a, _b;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- import ingredientParser from './funcs/ingredientParser.js';
2
- import { ParsedIngredient as ParsedIngredientType, IngredientData as IngredientDataType, IngredientResponse as IngredientResponseType } from '../index.js';
3
- export { ingredientParser, ParsedIngredientType, IngredientDataType, IngredientResponseType, };
1
+ export * from './funcs/ingredientParser';
2
+ export * from '@jclind/ingredient-parser';
package/dist/index.js CHANGED
@@ -1,5 +1,18 @@
1
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
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ingredientParser = void 0;
4
- const ingredientParser_js_1 = require("./funcs/ingredientParser.js");
5
- exports.ingredientParser = ingredientParser_js_1.default;
17
+ __exportStar(require("./funcs/ingredientParser"), exports);
18
+ __exportStar(require("@jclind/ingredient-parser"), exports);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jclind/ingredient-parser",
3
- "version": "1.0.36",
4
- "description": "Parses given sentence including ingredient information and attemps to return quantity, measurement and ingredient data",
3
+ "version": "1.0.38",
4
+ "description": "Parses given sentence including ingredient information and attempts to return quantity, measurement and ingredient data",
5
5
  "keywords": [
6
6
  "recipe",
7
7
  "ingredient",
@@ -9,13 +9,8 @@
9
9
  "units"
10
10
  ],
11
11
  "main": "dist/index.js",
12
- "types": "dist/index.d.ts",
13
- "typings": "dist/index.d.ts",
12
+ "types": "types/index.d.ts",
14
13
  "type": "module",
15
- "files": [
16
- "dist",
17
- "types.js"
18
- ],
19
14
  "scripts": {
20
15
  "build": "tsc"
21
16
  },
@@ -0,0 +1,15 @@
1
+ import axios from 'axios'
2
+
3
+ export const mongoHttp = axios.create({
4
+ baseURL:
5
+ 'https://us-east-1.aws.data.mongodb-api.com/app/prepify-ixumn/endpoint',
6
+ headers: {
7
+ 'Content-type': 'application/json',
8
+ },
9
+ })
10
+ export const spoonacularHttp = axios.create({
11
+ baseURL: 'https://api.spoonacular.com/food/ingredients/',
12
+ headers: {
13
+ 'Content-type': 'application/json',
14
+ },
15
+ })
@@ -0,0 +1,50 @@
1
+ import { mongoHttp, spoonacularHttp } from './http.js'
2
+ import { IngredientData } from '@jclind/ingredient-parser'
3
+ export const checkIngredient = async (name: string) => {
4
+ return await mongoHttp.get(`checkIngredient?name=${name}`)
5
+ }
6
+ export const searchIngredient = async (
7
+ name: string,
8
+ spoonacularAPIKey: string
9
+ ) => {
10
+ let searchedIngr: any
11
+ try {
12
+ searchedIngr = await spoonacularHttp.get(
13
+ `search?query=${name}&number=1&apiKey=${spoonacularAPIKey}`
14
+ )
15
+ } catch (error: any) {
16
+ const res: any = error.response.data
17
+ if (res.code === 401) {
18
+ throw new Error('API Key Not Valid')
19
+ } else {
20
+ throw new Error('Error Occurred, Please Try Again')
21
+ }
22
+ }
23
+ return searchedIngr
24
+ }
25
+ export const getIngredientInformation = async (
26
+ ingrId: number,
27
+ unit: boolean,
28
+ spoonacularAPIKey: string
29
+ ) => {
30
+ let ingrData: any
31
+ try {
32
+ ingrData = await spoonacularHttp.get(
33
+ `${ingrId}/information?amount=1&${
34
+ unit ? 'unit=grams&' : ''
35
+ }apiKey=${spoonacularAPIKey}`
36
+ )
37
+ } catch (error: any) {
38
+ const res: any = error.response.data
39
+ if (res.code === 401) {
40
+ throw new Error('API Key Not Valid')
41
+ } else {
42
+ throw new Error('Error Occurred, Please Try Again')
43
+ }
44
+ }
45
+
46
+ return ingrData
47
+ }
48
+ export const setMongoDBIngrData = async (data: IngredientData) => {
49
+ return await mongoHttp.post(`addIngredient`, data)
50
+ }
@@ -0,0 +1,25 @@
1
+ //@ts-ignore
2
+ import { converter } from '@jclind/ingredient-unit-converter'
3
+
4
+ export const calculatePrice = (
5
+ quantity: number | null,
6
+ unit: string | null,
7
+ price: { estimatedSingleUnitPrice: number; estimatedGramPrice: number }
8
+ ): number | null => {
9
+ if (!quantity) return price.estimatedSingleUnitPrice
10
+ if (!unit) return price.estimatedSingleUnitPrice * quantity
11
+
12
+ let convertedUnit
13
+ try {
14
+ convertedUnit = converter(quantity, unit)
15
+ } catch (error) {
16
+ return null
17
+ }
18
+
19
+ if (!convertedUnit || convertedUnit.error)
20
+ return price.estimatedSingleUnitPrice * quantity
21
+
22
+ const convertedGrams = Number(convertedUnit.quantity)
23
+ const total: number = convertedGrams * price.estimatedGramPrice
24
+ return Math.ceil(total * 100) / 100
25
+ }
@@ -0,0 +1,29 @@
1
+ export const convertFractions = (str: string): string => {
2
+ const fractions = {
3
+ '¼': '1/4',
4
+ '½': '1/2',
5
+ '¾': '3/4',
6
+ '⅓': '1/3',
7
+ '⅔': '2/3',
8
+ '⅛': '1/8',
9
+ '⅜': '3/8',
10
+ '⅝': '5/8',
11
+ '⅞': '7/8',
12
+ '⅕': '1/5',
13
+ '⅖': '2/5',
14
+ '⅗': '3/5',
15
+ '⅘': '4/5',
16
+ '⅙': '1/6',
17
+ '⅚': '5/6',
18
+ '⅐': '1/7',
19
+ '⅑': '1/9',
20
+ '⅒': '1/10',
21
+ }
22
+
23
+ for (const [fraction, value] of Object.entries(fractions)) {
24
+ const re = new RegExp(fraction, 'g')
25
+ str = str.replace(re, value)
26
+ }
27
+
28
+ return str
29
+ }
@@ -0,0 +1,20 @@
1
+ import { checkIngredient } from '../api/requests.js'
2
+ import { getSpoonacularIngrData } from './getSpoonacularIngrData.js'
3
+
4
+ export async function getIngredientInfo(
5
+ ingrName: string,
6
+ spoonacularAPIKey: string
7
+ ) {
8
+ const ingrNameLower = ingrName.toLowerCase()
9
+ if (!ingrNameLower) throw new Error('Ingredient Invalid')
10
+ const mongoIngrData = await checkIngredient(ingrNameLower)
11
+ if (!mongoIngrData.data) {
12
+ const ingrData = await getSpoonacularIngrData(
13
+ ingrNameLower,
14
+ spoonacularAPIKey
15
+ )
16
+ return ingrData
17
+ } else {
18
+ return mongoIngrData.data
19
+ }
20
+ }
@@ -0,0 +1,44 @@
1
+ import {
2
+ getIngredientInformation,
3
+ searchIngredient,
4
+ setMongoDBIngrData,
5
+ } from '../api/requests.js'
6
+
7
+ export async function getSpoonacularIngrData(
8
+ name: string,
9
+ spoonacularAPIKey: string
10
+ ) {
11
+ const searchedIngr = await searchIngredient(name, spoonacularAPIKey)
12
+ if (searchedIngr.error) return searchedIngr
13
+ const ingrId = searchedIngr?.data?.results[0]?.id ?? null
14
+
15
+ if (!ingrId) throw new Error(`No Data Found, unknown ingredient: ${name}`)
16
+
17
+ const ingrDataGram = await getIngredientInformation(
18
+ ingrId,
19
+ true,
20
+ spoonacularAPIKey
21
+ )
22
+ const ingrDataSingleUnit = await getIngredientInformation(
23
+ ingrId,
24
+ false,
25
+ spoonacularAPIKey
26
+ )
27
+
28
+ if (ingrDataGram.error || ingrDataSingleUnit.error) return ingrDataGram
29
+
30
+ const estimatedGramPrice = ingrDataGram.data.estimatedCost.value
31
+ const estimatedSingleUnitPrice = ingrDataSingleUnit.data.estimatedCost.value
32
+
33
+ const ingrData = {
34
+ ...ingrDataGram.data,
35
+ name,
36
+ ingredientId: ingrId,
37
+ estimatedPrices: { estimatedGramPrice, estimatedSingleUnitPrice },
38
+ }
39
+
40
+ const mongoDBIngrData = ingrData
41
+ const mongoRes = await setMongoDBIngrData(mongoDBIngrData)
42
+ const _id = mongoRes.data.insertedId
43
+ return { ...mongoDBIngrData, _id }
44
+ }
@@ -0,0 +1,72 @@
1
+ import { calculatePrice } from './calculatePrice.js'
2
+ import { parseIngredientString } from './parseIngredientString.js'
3
+ import { getIngredientInfo } from './getIngredientInfo.js'
4
+ import {
5
+ IngredientResponse,
6
+ ParsedIngredient,
7
+ IngredientData,
8
+ } from '@jclind/ingredient-parser'
9
+
10
+ const ingredientParser = async (
11
+ ingrString: string,
12
+ spoonacularAPIKey: string
13
+ ): Promise<IngredientResponse> => {
14
+ // const parsedIngr: ParsedIngredient = parse(ingrString, 'eng')
15
+ const parsedIngr: ParsedIngredient = parseIngredientString(ingrString)
16
+
17
+ let ingrData = null
18
+ try {
19
+ ingrData = await getIngredientInfo(
20
+ parsedIngr.ingredient || '',
21
+ spoonacularAPIKey
22
+ )
23
+ } catch (error: any) {
24
+ return {
25
+ error: { message: error.message },
26
+ ingredientData: null,
27
+ parsedIngredient: parsedIngr ?? null,
28
+ }
29
+ }
30
+ if (parsedIngr.ingredient && ingrData) {
31
+ const {
32
+ estimatedPrices,
33
+ meta,
34
+ categoryPath,
35
+ unit,
36
+ unitShort,
37
+ unitLong,
38
+ original,
39
+ id,
40
+ ...reducedIngrData
41
+ } = ingrData
42
+
43
+ const totalPrice = calculatePrice(
44
+ parsedIngr.quantity,
45
+ parsedIngr.unit,
46
+ estimatedPrices
47
+ )
48
+
49
+ const imagePath = `https://spoonacular.com/cdn/ingredients_100x100/${reducedIngrData.image}`
50
+ const updatedIngrData: IngredientData = {
51
+ ...reducedIngrData,
52
+ imagePath,
53
+ totalPriceUSACents: totalPrice,
54
+ }
55
+
56
+ return {
57
+ ingredientData: updatedIngrData,
58
+ parsedIngredient: parsedIngr,
59
+ }
60
+ } else {
61
+ return {
62
+ error: {
63
+ message:
64
+ 'Ingredient not formatted correctly or Ingredient Unknown. Please pass ingredient comments/instructions after a comma',
65
+ },
66
+ ingredientData: null,
67
+ parsedIngredient: parsedIngr,
68
+ }
69
+ }
70
+ }
71
+
72
+ export default ingredientParser
@@ -0,0 +1,77 @@
1
+ import { ParsedIngredient } from '@jclind/ingredient-parser'
2
+ import { parse } from 'recipe-ingredient-parser-v3'
3
+ // import { ParsedIngredient } from '../../index.js'
4
+ import { convertFractions } from './convertFractions.js'
5
+
6
+ export const parseIngredientString = (ingrStr: string): ParsedIngredient => {
7
+ // Define regular expressions for text inside parentheses and text before the first comma
8
+ const parenRegex = /(\(.*?\))/
9
+ const commaRegex = /^(.*?)(?=,)/
10
+
11
+ // Extract the text inside the parentheses and the text before the first comma using regular expressions
12
+ const parenthesesStr = ingrStr.match(parenRegex)?.[1] ?? ''
13
+
14
+ const textWithoutParenthesesStr = ingrStr.replace(parenthesesStr, '')
15
+ // Find the index of the first ',' character
16
+ const commaIndex = textWithoutParenthesesStr.indexOf(',')
17
+
18
+ let ingrText: string
19
+ let comment: string
20
+
21
+ // If there is no comma in the string don't include a comment
22
+ if (commaIndex !== -1) {
23
+ ingrText = convertFractions(
24
+ textWithoutParenthesesStr
25
+ .substring(0, commaIndex)
26
+ .replace(parenRegex, '')
27
+ .trim()
28
+ )
29
+ comment = (
30
+ textWithoutParenthesesStr
31
+ .replace(parenRegex, '')
32
+ .substring(commaIndex + 1) +
33
+ ' ' +
34
+ parenthesesStr
35
+ ).trim()
36
+ } else {
37
+ ingrText = convertFractions(ingrStr.replace(parenRegex, '').trim())
38
+ comment = parenthesesStr.trim()
39
+ }
40
+
41
+ const prepIngrText = ingrText.replace(/\b(lb|lbs)\b/g, match => {
42
+ // Replace lb or lbs with pound or pounds respectively
43
+ if (match === 'lb') {
44
+ return 'pound'
45
+ } else {
46
+ return 'pounds'
47
+ }
48
+ })
49
+
50
+ const parsedIngrRes: Omit<
51
+ ParsedIngredient,
52
+ 'originalIngredientString' | 'comment'
53
+ > = parse(prepIngrText, 'eng')
54
+
55
+ if (!parsedIngrRes.ingredient) {
56
+ return { ...parsedIngrRes, originalIngredientString: ingrStr, comment }
57
+ }
58
+
59
+ const wordsToRemove = ['small', 'medium', 'large', 'fresh', 'canned']
60
+ const regex = new RegExp('\\b(' + wordsToRemove.join('|') + ')\\b', 'gi')
61
+
62
+ const formattedIngrName = parsedIngrRes.ingredient
63
+ .trim()
64
+ .replace(/\s{2,}/g, ' ') // Replace multiple whitespace characters with a single space
65
+ .replace(/,/g, '') // Remove commas
66
+ .replace(/^(fluid|fl|oz) /, '') // Remove "fluid ", "fl ", or "oz " at the beginning of the string
67
+ .replace(regex, '')
68
+
69
+ .trim()
70
+
71
+ return {
72
+ ...parsedIngrRes,
73
+ ingredient: formattedIngrName,
74
+ originalIngredientString: ingrStr,
75
+ comment,
76
+ }
77
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './funcs/ingredientParser'
2
+ export * from '@jclind/ingredient-parser'
package/tsconfig.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ "experimentalDecorators": true /* Enable experimental support for TC39 stage 2 draft decorators. */,
18
+ "emitDecoratorMetadata": true /* Emit design-type metadata for decorated declarations in source files. */,
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
27
+ /* Modules */
28
+ "module": "commonjs" /* Specify what module code is generated. */,
29
+ // "rootDir": "./", /* Specify the root folder within your source files. */
30
+ // "moduleResolution": "NodeNext" /* Specify how TypeScript looks up a file from a given module specifier. */,
31
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
+ // "resolveJsonModule": true, /* Enable importing .json files. */
39
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
40
+
41
+ /* JavaScript Support */
42
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
43
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
44
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
45
+
46
+ /* Emit */
47
+ "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
48
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
49
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
50
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
51
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
52
+ "outDir": "dist" /* Specify an output folder for all emitted files. */,
53
+ // "removeComments": true, /* Disable emitting comments. */
54
+ // "noEmit": true, /* Disable emitting files from a compilation. */
55
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
56
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
57
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
58
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
59
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
60
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
61
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
62
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
63
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
64
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
65
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
66
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
67
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
68
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
69
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
70
+
71
+ /* Interop Constraints */
72
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
73
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74
+ // "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
75
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
76
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
77
+
78
+ /* Type Checking */
79
+ "strict": true /* Enable all strict type-checking options. */
80
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
81
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
82
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
83
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
84
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
85
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
86
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
87
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
88
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
89
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
90
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
91
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
92
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
93
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
94
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
95
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
96
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
97
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
98
+
99
+ /* Completeness */
100
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
101
+ },
102
+ "include": ["src/**/*", "types/**/*"],
103
+ "exclude": ["node_modules", "**/*.spec.ts"]
104
+ }
@@ -0,0 +1,83 @@
1
+ declare module '@jclind/ingredient-parser' {
2
+ type StringOrNull = string | null
3
+ type NumberOrNull = number | null
4
+
5
+ export type IngredientResponse =
6
+ | {
7
+ parsedIngredient: ParsedIngredient
8
+ ingredientData: IngredientData
9
+ id?: string
10
+ }
11
+ | {
12
+ error: { message: string }
13
+ parsedIngredient: ParsedIngredient
14
+ ingredientData: IngredientData | null
15
+ id?: string
16
+ }
17
+
18
+ export type ParsedIngredient = {
19
+ quantity: NumberOrNull
20
+ unit: StringOrNull
21
+ unitPlural: StringOrNull
22
+ symbol: StringOrNull
23
+ ingredient: StringOrNull
24
+ originalIngredientString: string
25
+ minQty: NumberOrNull
26
+ maxQty: NumberOrNull
27
+ comment: StringOrNull
28
+ }
29
+
30
+ export interface IngredientData {
31
+ _id: string
32
+ ingredientId: number
33
+ originalName: string
34
+ name: string
35
+ amount: number
36
+ possibleUnits: string[]
37
+ consistency: string
38
+ shoppingListUnits: string[]
39
+ aisle: string
40
+ image: string
41
+ imagePath: string
42
+ nutrition: Nutrition
43
+ totalPriceUSACents: number
44
+ }
45
+
46
+ export interface Nutrition {
47
+ nutrients: Nutrient[]
48
+ properties: Property[]
49
+ flavonoids: Flavonoid[]
50
+ caloricBreakdown: CaloricBreakdown
51
+ weightPerServing: WeightPerServing
52
+ }
53
+
54
+ export interface Nutrient {
55
+ name: string
56
+ amount: number
57
+ unit: string
58
+ percentOfDailyNeeds: number
59
+ }
60
+
61
+ export interface Property {
62
+ name: string
63
+ amount: number
64
+ unit: string
65
+ }
66
+
67
+ export interface Flavonoid {
68
+ name: string
69
+ amount: number
70
+ unit: string
71
+ }
72
+
73
+ export interface CaloricBreakdown {
74
+ percentProtein: number
75
+ percentFat: number
76
+ percentCarbs: number
77
+ }
78
+
79
+ export interface WeightPerServing {
80
+ amount: number
81
+ unit: string
82
+ }
83
+ }