1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-28 09:39:41 +02:00
mealie/frontend/src/utils/recipe.js

32 lines
805 B
JavaScript
Raw Normal View History

export const recipe = {
/**
* Sorts a list of recipes in place
* @param {Array<Object>} list of recipes
* @param {Boolean} inverse - Z or A First
*/
sortAToZ(list) {
list.sort((a, b) => {
var textA = a.name.toUpperCase();
var textB = b.name.toUpperCase();
return textA < textB ? -1 : textA > textB ? 1 : 0;
});
},
sortByCreated(list) {
list.sort((a, b) => (a.dateAdded > b.dateAdded ? -1 : 1));
},
sortByUpdated(list) {
list.sort((a, b) => (a.dateUpdated > b.dateUpdated ? -1 : 1));
},
sortByRating(list) {
list.sort((a, b) => (a.rating > b.rating ? -1 : 1));
},
/**
*
* @param {Array<Object>} list
* @returns String / Recipe Slug
*/
randomRecipe(list) {
return list[Math.floor(Math.random() * list.length)];
},
};