-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.js
42 lines (37 loc) · 1.05 KB
/
storage.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
35
36
37
38
39
40
41
42
class LS{
constructor(){
this.city;
this.country;
this.unit;
this.defaultCity = 'Cairo';
this.defaultCountry = 'EG';
this.defaultUnit = 'metric';
}
getLocation(){
if(localStorage.getItem('city') === null){
this.city = this.defaultCity;
}else{
this.city = localStorage.getItem('city');
}
if (localStorage.getItem('country') === null) {
this.country = this.defaultCountry;
} else {
this.country = localStorage.getItem('country');
}
if (localStorage.getItem('unit') === null) {
this.unit = this.defaultUnit;
} else {
this.unit = localStorage.getItem('unit');
}
return{
city: this.city,
country: this.country,
unit: this.unit,
}
}
setLocation(city, country, unit){
localStorage.setItem('city', city);
localStorage.setItem('country', country);
localStorage.setItem('unit', unit);
}
}