move localStorage util to localStorage.js,

update main,js to rquire localStroage,
add simple unit tests to localStroage.test.js,
create symlink of testenv.js to source/assets/scripts,
update package.json with proper recursive call

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu
2022-11-10 01:35:41 +00:00
parent 9bbb2e48f7
commit 1718c7cedb
5 changed files with 78 additions and 21 deletions

View File

@@ -0,0 +1,21 @@
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));
}