recipegen
v1.0.0
Published
## Description The **Recipe Finder Library** is a simple and lightweight JavaScript library that helps you search for recipes based on specific ingredients. By providing an ingredient, the library will return a list of recipes that include that ingredient
Downloads
3
Readme
Recipe Finder Library
Description
The Recipe Finder Library is a simple and lightweight JavaScript library that helps you search for recipes based on specific ingredients. By providing an ingredient, the library will return a list of recipes that include that ingredient in their list of ingredients.
Features
- Contains a predefined list of recipes with their names and ingredients.
- Provides a method to filter recipes by a given ingredient.
- Lightweight and easy to use.
Installation
This library is designed to be included in your project as a script or module. If you plan to publish this as an NPM package, you can install it with:
npm install recipe-finderUsage
Example Code
Here's how to use the Recipe Finder Library in your project:
const recipes = [
{
name: "Pasta with Tomato Sauce",
ingredients: ["pasta", "tomato", "olive oil", "basil"],
},
{
name: "Zucchini Frittata",
ingredients: ["eggs", "zucchini", "salt", "olive oil"],
},
{
name: "Mixed Salad",
ingredients: ["lettuce", "tomatoes", "carrots", "olive oil", "salt"],
},
{
name: "Mushroom Risotto",
ingredients: ["rice", "mushrooms", "vegetable broth", "onion", "olive oil", "parmesan"],
},
{
name: "Margherita Pizza",
ingredients: ["pizza dough", "tomato", "mozzarella", "basil", "olive oil"],
},
{
name: "Caprese Salad",
ingredients: ["buffalo mozzarella", "tomatoes", "basil", "olive oil", "salt", "pepper"],
},
{
name: "Meatballs in Sauce",
ingredients: ["ground meat", "eggs", "breadcrumbs", "parmesan", "tomato", "onion", "salt", "pepper"],
},
{
name: "Carbonara Pasta",
ingredients: ["pasta", "guanciale", "eggs", "pecorino romano", "salt", "pepper"],
},
];
function getRecipesByIngredient(ingredient) {
return recipes.reduce((result, recipe) => {
if (recipe.ingredients.includes(ingredient)) {
result.push(recipe);
}
return result;
}, []);
}
const ingredientToSearch = "mushrooms";
const recipesFound = getRecipesByIngredient(ingredientToSearch);
console.log(`Recipes with ingredient "${ingredientToSearch}":`);
console.log(recipesFound);Output Example
When searching for "mushrooms", the output will be:
Recipes with ingredient "mushrooms":
[
{
name: "Mushroom Risotto",
ingredients: ["rice", "mushrooms", "vegetable broth", "onion", "olive oil", "parmesan"]
}
]API
getRecipesByIngredient(ingredient)
- Description: Returns a list of recipes that include the specified ingredient.
- Parameters:
ingredient(string): The ingredient to search for.
- Returns: An array of recipe objects containing the specified ingredient.
Contributing
Feel free to contribute to this library by submitting issues or pull requests on the GitHub repository.
License
This library is licensed under the MIT License. See the LICENSE file for more details.
Enjoy finding recipes with the Recipe Finder Library!
