open-nutrition-engine 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/calculations/index.d.ts.map +1 -1
- package/dist/calculations/index.js.map +1 -1
- package/dist/data/extended_staples.json +91869 -22046
- package/dist/data/index.d.ts.map +1 -1
- package/dist/data/index.js.map +1 -1
- package/package.json +7 -4
- package/src/calculations/index.ts +0 -65
- package/src/data/curries.ts +0 -542
- package/src/data/dairy.ts +0 -328
- package/src/data/dal.ts +0 -221
- package/src/data/drinksDesserts.ts +0 -318
- package/src/data/extended_staples.json +0 -59178
- package/src/data/fruits.ts +0 -249
- package/src/data/grains.ts +0 -992
- package/src/data/index.ts +0 -85
- package/src/data/master/verified_fitness_staples.json +0 -262507
- package/src/data/nonveg.ts +0 -450
- package/src/data/snacks.ts +0 -440
- package/src/index.ts +0 -3
- package/src/types/index.ts +0 -93
package/src/data/index.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { FoodCategory, DietType, FoodItem } from '../types';
|
|
2
|
-
import { GRAINS } from './grains';
|
|
3
|
-
import { DAL } from './dal';
|
|
4
|
-
import { CURRIES } from './curries';
|
|
5
|
-
import { DAIRY } from './dairy';
|
|
6
|
-
import { SNACKS } from './snacks';
|
|
7
|
-
import { FRUITS } from './fruits';
|
|
8
|
-
import { NON_VEG } from './nonveg';
|
|
9
|
-
import { DRINKS_DESSERTS } from './drinksDesserts';
|
|
10
|
-
import EXTENDED_STAPLES from './extended_staples.json';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Aggregated local food database. Contains 2,500 instant in-memory fitness
|
|
14
|
-
* and Indian staples with Hindi names, serving sizes, and exact macros.
|
|
15
|
-
*/
|
|
16
|
-
export const FOODS: FoodItem[] = [
|
|
17
|
-
...GRAINS,
|
|
18
|
-
...DAL,
|
|
19
|
-
...CURRIES,
|
|
20
|
-
...DAIRY,
|
|
21
|
-
...SNACKS,
|
|
22
|
-
...FRUITS,
|
|
23
|
-
...NON_VEG,
|
|
24
|
-
...DRINKS_DESSERTS,
|
|
25
|
-
...(EXTENDED_STAPLES as unknown as FoodItem[]),
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
/** Fast lookup by stable food id. */
|
|
29
|
-
const FOOD_INDEX = new Map(FOODS.map((food) => [food.id, food]));
|
|
30
|
-
|
|
31
|
-
export const getFoodById = (id: string): FoodItem | undefined => FOOD_INDEX.get(id);
|
|
32
|
-
|
|
33
|
-
/** Count of foods in the database (exposed for future UI/stats use). */
|
|
34
|
-
export const FOOD_COUNT = FOODS.length;
|
|
35
|
-
|
|
36
|
-
/** Shared filter options used by the search UI. */
|
|
37
|
-
export type DietFilter = 'all' | DietType;
|
|
38
|
-
export type CategoryFilter = 'all' | FoodCategory;
|
|
39
|
-
|
|
40
|
-
export interface FoodSearchFilters {
|
|
41
|
-
query: string;
|
|
42
|
-
category: CategoryFilter;
|
|
43
|
-
diet: DietFilter;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Filter the database by text (name or Hindi name) and facet filters with relevance ranking. */
|
|
47
|
-
export const searchFoods = ({ query, category, diet }: FoodSearchFilters): FoodItem[] => {
|
|
48
|
-
const q = query.trim().toLowerCase();
|
|
49
|
-
|
|
50
|
-
const filtered = FOODS.filter((food) => {
|
|
51
|
-
if (category !== 'all' && food.category !== category) return false;
|
|
52
|
-
if (diet !== 'all' && food.diet !== diet) return false;
|
|
53
|
-
if (q === '') return true;
|
|
54
|
-
return (
|
|
55
|
-
food.name.toLowerCase().includes(q) ||
|
|
56
|
-
(food.hindiName !== undefined && food.hindiName.toLowerCase().includes(q)) ||
|
|
57
|
-
(food.aliases !== undefined && food.aliases.some((alias) => alias.toLowerCase().includes(q)))
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (q === '') return filtered;
|
|
62
|
-
|
|
63
|
-
return filtered.sort((a, b) => {
|
|
64
|
-
const aName = a.name.toLowerCase();
|
|
65
|
-
const bName = b.name.toLowerCase();
|
|
66
|
-
|
|
67
|
-
// 1. Exact match
|
|
68
|
-
const aExact = aName === q;
|
|
69
|
-
const bExact = bName === q;
|
|
70
|
-
if (aExact !== bExact) return aExact ? -1 : 1;
|
|
71
|
-
|
|
72
|
-
// 2. Starts with query
|
|
73
|
-
const aStarts = aName.startsWith(q);
|
|
74
|
-
const bStarts = bName.startsWith(q);
|
|
75
|
-
if (aStarts !== bStarts) return aStarts ? -1 : 1;
|
|
76
|
-
|
|
77
|
-
// 3. Word boundary match (e.g. "Egg" matches "Boiled Egg" before "Eggplant")
|
|
78
|
-
const wordRegex = new RegExp(`\\b${q}`, 'i');
|
|
79
|
-
const aWord = wordRegex.test(aName);
|
|
80
|
-
const bWord = wordRegex.test(bName);
|
|
81
|
-
if (aWord !== bWord) return aWord ? -1 : 1;
|
|
82
|
-
|
|
83
|
-
return aName.localeCompare(bName);
|
|
84
|
-
});
|
|
85
|
-
};
|