blob: 6861758f1642aec489e88d2458e8f9ad1ad93115 (
plain)
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
|
var baseKey = '';
/*
* Simple module for storing data in the browser's local storage
*/
module.exports = {
setBaseKey: function(key) {
baseKey = key;
},
set: function(key, value) {
key = baseKey+':'+key;
localStorage[key] = JSON.stringify(value);
},
get: function(key, def) {
key = baseKey+':'+key;
if (localStorage[key] === undefined) return def;
try {
var v = JSON.parse(localStorage[key]);
return v == null ? def : v;;
} catch(err) {
return localStorage[key] || def;
}
},
remove: function(key) {
key = baseKey+':'+key;
localStorage.removeItem(key);
}
};
|