-
Notifications
You must be signed in to change notification settings - Fork 3
/
storage.js
29 lines (28 loc) · 1.1 KB
/
storage.js
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
29
(function(window, document, undefined){
function TurtleStorage (prefix, storage) {
return Turtle.extend(this, {prefix: prefix, storage: storage});
}
Turtle.extend(TurtleStorage.prototype, {
prefixedKey: function prefixedKey(key) {return this.prefix + "." + key;},
keys: function keys() {
var limit = this.storage.length, found = [];
for(var i = 0; i < limit; i++) {
var key = this.storage.key(i);
if (key && key.indexOf(this.prefix) === 0) {
found.push(key.replace(this.prefix+".", ""));
}
}
return found.sort();
},
setItem: function setItem(key, value) {
return this.storage.setItem(this.prefixedKey(key), value);
},
getItem: function getItem(key) {
return this.storage.getItem(this.prefixedKey(key));
},
removeItem: function removeItem(key) {
return this.storage.removeItem(this.prefixedKey(key));
}
});
window.Turtle.Storage = TurtleStorage;
})(this, this.document);