mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-06 21:49:03 +00:00
more robust storage path handling
This commit is contained in:
parent
7b2761460e
commit
f7a888e590
3
extension/env/storage.mjs
vendored
3
extension/env/storage.mjs
vendored
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user