mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-17 08:05:19 +00:00
30 lines
803 B
JavaScript
30 lines
803 B
JavaScript
define(function(){
|
|
var baseKey = "";
|
|
|
|
/*
|
|
* Simple module for storing data in the browser's local storage
|
|
*/
|
|
return {
|
|
setBaseKey: function(key) {
|
|
baseKey = key;
|
|
},
|
|
set: function(key, value) {
|
|
key = baseKey+":"+key;
|
|
localStorage[key] = JSON.stringify(value);
|
|
},
|
|
get: function(key, def) {
|
|
key = baseKey+":"+key;
|
|
try {
|
|
var v = JSON.parse(localStorage[key]);
|
|
return v == null ? def : v;;
|
|
} catch(err) {
|
|
console.error(err);
|
|
return localStorage[key] || def;
|
|
}
|
|
},
|
|
remove: function(key) {
|
|
key = baseKey+":"+key;
|
|
localStorage.removeItem(key);
|
|
}
|
|
};
|
|
}); |