mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-17 08:05:19 +00:00
28 lines
728 B
JavaScript
28 lines
728 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 {
|
|
return JSON.parse(localStorage[key]) || def;
|
|
} catch(err) {
|
|
return localStorage[key] || def;
|
|
}
|
|
},
|
|
remove: function(key) {
|
|
key = baseKey+":"+key;
|
|
localStorage.removeItem(key);
|
|
}
|
|
};
|
|
}); |