forked from KatrinaCloyd/MemoryCardGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
35 lines (29 loc) · 831 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
export function findById(id, array) {
for (let item of array) {
if (id === item.name) {
return item;
}
}
}
const USERS = 'users';
const CURRENTUSER = 'current user';
export function saveUsers(user) {
localStorage.setItem(USERS, JSON.stringify(user));
}
export function setCurrentUser(currentUser) {
localStorage.setItem(CURRENTUSER, JSON.stringify(currentUser));
}
export function getUsers() {
let stringyUser = localStorage.getItem(USERS);
if (!stringyUser) {
const emptyArray = [];
return emptyArray;
}
let parsedUser = JSON.parse(stringyUser);
return parsedUser;
}
export function getCurrentUser() {
let stringyUser = localStorage.getItem(CURRENTUSER);
let parsedCurrentUser = JSON.parse(stringyUser);
return parsedCurrentUser;
}