mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(storage) rm unused removeMatch
This commit is contained in:
parent
c8d2098e5b
commit
aeb5906de3
2 changed files with 1 additions and 36 deletions
|
|
@ -1,6 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const tryCatch = require('try-catch');
|
||||
const {parse, stringify} = JSON;
|
||||
|
||||
module.exports.set = async (name, data) => {
|
||||
|
|
@ -17,9 +16,7 @@ module.exports.get = async (name) => {
|
|||
|
||||
module.exports.getJson = async (name) => {
|
||||
const data = localStorage.getItem(name);
|
||||
const [, result = data] = tryCatch(parse, data);
|
||||
|
||||
return result;
|
||||
return parse(data);
|
||||
};
|
||||
|
||||
module.exports.clear = () => {
|
||||
|
|
@ -30,13 +27,3 @@ module.exports.remove = (item) => {
|
|||
localStorage.removeItem(item);
|
||||
};
|
||||
|
||||
module.exports.removeMatch = (string) => {
|
||||
const reg = RegExp('^' + string + '.*$');
|
||||
const test = (a) => reg.test(a);
|
||||
const remove = (a) => localStorage.removeItem(a);
|
||||
|
||||
Object.keys(localStorage)
|
||||
.filter(test)
|
||||
.forEach(remove);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -104,25 +104,3 @@ test('cloudcmd: client: storage: clear', async (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: storage: removeMatch', async (t) => {
|
||||
const {localStorage} = global;
|
||||
const removeItem = stub();
|
||||
|
||||
global.localStorage = {
|
||||
removeItem,
|
||||
fileA: 1,
|
||||
fileB: 2,
|
||||
};
|
||||
|
||||
await storage.removeMatch('file');
|
||||
global.localStorage = localStorage;
|
||||
const {args} = removeItem;
|
||||
const expected = [
|
||||
['fileA'],
|
||||
['fileB'],
|
||||
];
|
||||
|
||||
t.deepEqual(args, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue