Spaces:
Running
Running
File size: 778 Bytes
e13a8b7 9b42531 e13a8b7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import * as path from "path";
const fs = require('fs')
export interface IMealJson {
Name: string;
RecipeIngredientParts: string[];
Calories: number;
CarbohydrateContent: number;
ProteinContent: number;
FatContent: number;
Images: string[];
Category: string;
}
const filePath = path.join(__dirname, '../../resources/meals.json');
export const loadMealsDataset = (): IMealJson[] => {
let data: IMealJson[] = JSON.parse(fs.readFileSync(filePath, 'utf8'));
// remove duplicates by name
const uniqueNames = new Set(data.map(e => e.Name));
data = data.filter(e => {
const found = uniqueNames.has(e.Name)
uniqueNames.delete(e.Name);
return found;
});
console.log(`Loaded ${data.length} meals from dataset`)
return data;
}
|