From e54f516418237f238383b57d98fec003128f6885 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Wed, 26 Jul 2017 14:40:50 +0900 Subject: [PATCH] Add findStorage() --- browser/lib/findStorage.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 browser/lib/findStorage.js diff --git a/browser/lib/findStorage.js b/browser/lib/findStorage.js new file mode 100644 index 00000000..98d48236 --- /dev/null +++ b/browser/lib/findStorage.js @@ -0,0 +1,14 @@ +const _ = require('lodash') + +export function findStorage (storageKey) { + const cachedStorageList = JSON.parse(localStorage.getItem('storages')) + if (!_.isArray(cachedStorageList)) throw new Error('Target storage doesn\'t exist.') + const storage = _.find(cachedStorageList, {key: storageKey}) + if (storage === undefined) throw new Error('Target storage doesn\'t exist.') + + return storage +} + +export default { + findStorage +}