mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
20 lines
526 B
JavaScript
20 lines
526 B
JavaScript
define(function(){
|
|
/*
|
|
* Simple module for storing data in the browser's local storage
|
|
*/
|
|
return {
|
|
set: function(key, value) {
|
|
localStorage[key] = JSON.stringify(value);
|
|
},
|
|
get: function(key, def) {
|
|
try {
|
|
return JSON.parse(localStorage[key]) || def;
|
|
} catch(err) {
|
|
return localStorage[key] || def;
|
|
}
|
|
},
|
|
remove: function(key) {
|
|
localStorage.removeItem(key);
|
|
}
|
|
};
|
|
}); |