trilium/src/public/javascripts/services/options.js

55 lines
875 B
JavaScript
Raw Normal View History

import server from "./server.js";
const loadListeners = [];
class Options {
load(arr) {
this.arr = arr;
}
get(key) {
return this.arr[key];
}
2019-11-20 03:53:04 +08:00
getNames() {
return Object.keys(this.arr);
}
getJson(key) {
try {
return JSON.parse(this.arr[key]);
}
catch (e) {
return null;
}
}
getInt(key) {
return parseInt(this.arr[key]);
}
getFloat(key) {
return parseFloat(this.arr[key]);
}
is(key) {
return this.arr[key] === 'true';
}
set(key, value) {
this.arr[key] = value;
}
async save(key, value) {
this.set(key, value);
const payload = {};
payload[key] = value;
await server.put(`options`, payload);
}
}
const options = new Options();
export default options;