From f7a888e590ad53b0ce56f226657f989a9dee1393 Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Tue, 5 Oct 2021 00:09:39 +1100 Subject: [PATCH] more robust storage path handling --- extension/env/storage.mjs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extension/env/storage.mjs b/extension/env/storage.mjs index 91674f2..132f2f7 100644 --- a/extension/env/storage.mjs +++ b/extension/env/storage.mjs @@ -21,6 +21,7 @@ const _queue = [], * @returns {Promise} value ?? fallback */ export const get = (path, fallback = undefined) => { + if (typeof path === 'string') path = [path]; if (!path.length) return fallback; return new Promise((res, rej) => chrome.storage.local.get(async (values) => { @@ -44,6 +45,7 @@ export const get = (path, fallback = undefined) => { * @returns {Promise} resolves when data has been saved */ export const set = (path, value) => { + if (typeof path === 'string') path = [path]; if (!path.length) return undefined; const precursor = _queue[_queue.length - 1] || undefined, interaction = new Promise(async (res, rej) => { @@ -86,6 +88,7 @@ export const set = (path, value) => { * @returns {object} an object with the wrapped get/set functions */ export const db = (namespace, getFunc = get, setFunc = set) => { + if (typeof namespace === 'string') namespace = [namespace]; return { get: (path = [], fallback = undefined) => getFunc([...namespace, ...path], fallback), set: (path, value) => setFunc([...namespace, ...path], value),