cse110-fa22-group29/source/assets/scripts/localStorage.js
Arthur Lu 8b2ae89bd2 switch localStorage mock to mock-local-storage,
fix unit tests to work with ES6 import syntax,
remove testenv module
2022-11-11 02:39:40 +00:00

19 lines
525 B
JavaScript

/**
* @returns {Array<Object>} An array of reviews found in localStorage
*/
export 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
*/
export function saveReviewsToStorage(reviews) {
localStorage.setItem('reviews', JSON.stringify(reviews));
}