UNPKG

todolists

Version:
40 lines 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs"); const path = require("path"); class DataBase { constructor(dbPath) { this.dbPath = dbPath || path.join(__dirname, '../../'); this.init(); } init() { this.dbPath = path.join(this.dbPath, '.database.json'); if (fs.existsSync(this.dbPath)) { try { this.dataObject = JSON.parse(fs.readFileSync(this.dbPath).toString()); } catch (e) { console.error('[DataBase error]'); console.error(e); } return; } fs.writeFileSync(this.dbPath, '[]'); try { this.dataObject = []; } catch (e) { console.error('[DataBase error]'); console.error(e); } return; } writeData(data) { fs.writeFileSync(this.dbPath, data); } readData() { return this.dataObject; } } exports.default = DataBase; //# sourceMappingURL=data_base.js.map