jsqrz
Version:
Amatör telsizciler için çağrı işareti bilgisi sağlayan cli'dır. Var olan çağrı işaretinin ad soyad, adres, çağrı işareti, çağrı işaretinin fonetik okunuşu ve mors olarak yazılışı bilgisini gösterir.
49 lines (39 loc) • 913 B
JavaScript
import fs from "fs";
import os from "os";
import Tools from "tools";
class LocalStorage extends Tools{
constructor() {
super()
this.db = null;
this.root = `${os.homedir()}/.qrz`;
this.dbPath = `${this.root}/db.json`;
}
checkDB() {
if (!fs.existsSync(this.dbPath)) {
fs.mkdirSync(this.root);
fs.writeFileSync(this.dbPath, "{}");
}
if (!this.db) {
this.db = this.readJsonFile(this.dbPath);
}
}
hasItem(key) {
this.checkDB();
return !!this.db[key];
}
getItem(key) {
this.checkDB();
return this.db[key];
}
async setItem(key, value) {
this.checkDB();
this.db[key] = value;
await this.writeFile(this.dbPath, JSON.stringify(this.db));
}
async removeItem(key) {
this.checkDB();
delete this.db[key];
await this.writeFile(this.dbPath, JSON.stringify(this.db));
}
}
export default new LocalStorage();