mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2024-09-20 08:47:56 +00:00
21 lines
576 B
JavaScript
21 lines
576 B
JavaScript
|
module.exports = {getReviewsFromStorage, saveReviewsToStorage};
|
||
|
|
||
|
/**
|
||
|
* @returns {Array<Object>} An array of reviews found in localStorage
|
||
|
*/
|
||
|
function getReviewsFromStorage() {
|
||
|
let result = JSON.parse(localStorage.getItem('reviews'))
|
||
|
if (result) {
|
||
|
return result;
|
||
|
}
|
||
|
return new Array(0);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Takes in an array of reviews, converts it to a string, and then
|
||
|
* saves that string to 'reviews' in localStorage
|
||
|
* @param {Array<Object>} reviews An array of reviews
|
||
|
*/
|
||
|
function saveReviewsToStorage(reviews) {
|
||
|
localStorage.setItem('reviews', JSON.stringify(reviews));
|
||
|
}
|