add tests to insight storage + remove used code
This commit is contained in:
parent
d511103081
commit
bd698257f9
6 changed files with 124 additions and 93 deletions
|
|
@ -46,38 +46,4 @@ LocalStorage.prototype.clear = function(cb) {
|
|||
return cb();
|
||||
};
|
||||
|
||||
LocalStorage.prototype.allKeys = function(cb) {
|
||||
var l = localStorage.length;
|
||||
var ret = [];
|
||||
|
||||
for(var i=0; i<l; i++)
|
||||
ret.push(localStorage.key(i));
|
||||
|
||||
return cb(null, ret);
|
||||
};
|
||||
|
||||
LocalStorage.prototype.getFirst = function(prefix, opts, cb) {
|
||||
opts = opts || {};
|
||||
var that = this;
|
||||
|
||||
this.allKeys(function(err, allKeys) {
|
||||
var keys = _.filter(allKeys, function(k) {
|
||||
if ((k === prefix) || k.indexOf(prefix) === 0) return true;
|
||||
});
|
||||
|
||||
if (keys.length === 0)
|
||||
return cb(new Error('not found'));
|
||||
|
||||
if (opts.onlyKey)
|
||||
return cb(null, null, keys[0]);
|
||||
|
||||
that.getItem(keys[0], function(err, data) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
return cb(null, data, keys[0]);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = LocalStorage;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue