2017-03-14 23:05:07 -04:00
|
|
|
/**
|
|
|
|
* Thin wrapper around localStorage.getItem(). Parses JSON and returns undefined if the value
|
|
|
|
* is not set yet.
|
|
|
|
*/
|
2017-04-26 23:54:53 -04:00
|
|
|
export function getLocal(key, fallback=undefined) {
|
2017-03-14 23:05:07 -04:00
|
|
|
const itemRaw = localStorage.getItem(key);
|
2017-04-26 23:54:53 -04:00
|
|
|
return itemRaw === null ? fallback : JSON.parse(itemRaw);
|
2017-03-14 23:05:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Thin wrapper around localStorage.setItem(). Converts value to JSON.
|
|
|
|
*/
|
|
|
|
export function setLocal(key, value) {
|
|
|
|
localStorage.setItem(key, JSON.stringify(value));
|
2017-04-10 08:32:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Thin wrapper around localStorage.getItem(). Parses JSON and returns undefined if the value
|
|
|
|
* is not set yet.
|
|
|
|
*/
|
2017-04-13 14:52:26 -04:00
|
|
|
export function getSession(key, fallback=undefined) {
|
2017-04-10 08:32:40 -04:00
|
|
|
const itemRaw = sessionStorage.getItem(key);
|
2017-04-13 14:52:26 -04:00
|
|
|
return itemRaw === null ? fallback : JSON.parse(itemRaw);
|
2017-04-10 08:32:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Thin wrapper around localStorage.setItem(). Converts value to JSON.
|
|
|
|
*/
|
|
|
|
export function setSession(key, value) {
|
|
|
|
sessionStorage.setItem(key, JSON.stringify(value));
|
2017-04-09 11:06:23 -04:00
|
|
|
}
|