I am making a plugin for Firefox, this is (more or less) my first time working with JavaScript. Is this a reasonable design for working with both values and lists in a database?
function set(key, value) {
// Sets a key-value pair in the browser's local storage
browser.storage.local.set({ [key]: value });
}
function get(key) {
// Gets the value of a key from the browser's local storage
return browser.storage.local.get(key)
}
function remove(key) {
// Removes a key-value pair from the browser's local storage
browser.storage.local.remove(key)
}
function getList(key) {
// Gets a list from the browser's local storage
return get(key).then(result => {
if (result[key] === undefined) {
return [];
}
return result[key];
});
}
function pushToList(key, value) {
// Pushes a value to a list in the browser's local storage
getList(key).then(list => {
list.push(value);
set(key, list);
});
}
function removeFromList(key, value) {
// Removes a value from a list in the browser's local storage
getList(key).then(list => {
let index = list.indexOf(value);
if (index > -1) {
list.splice(index, 1);
set(key, list);
}
});
}
export { set, get, remove, getList, pushToList, removeFromList };
Edit:
My end goal is to store things like settings (key, value) and lists of tabs and similar info (key, [value, value, value]). The code below is a library of functions to be used by the rest of my code.
Actually I do plan to store more complex json data as well, specifically I will store and edit Tab objects if that makes a difference.