Source: index.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
class db {
    /**
     * @description Create a JSON db manager
     * @param {string} path Path to json file
     * @param {dbOptions} [options={debug: false}] Misc options
     */
    constructor(path, options) {
        this.path = path;
        this.options = options || { debug: false };
    }
    /**
     * @description Overwrites the contents with nothing or a passed value.
     * @param {ValidJson|string} [value='']
     * @async
     * @returns Promise<void>
     */
    async overwrite(value) {
        let a = JSON.stringify(value);
        return a
            ? fs.writeFile(this.path, a, (err) => {
                if (err)
                    throw err.message;
                if (this.options.debug) {
                    console.log('Overwritten JSON db.');
                }
            })
            : fs.writeFile(this.path, '', (err) => {
                if (err)
                    throw err.message;
                if (this.options.debug) {
                    console.log('Overwritten JSON db.');
                }
            });
    }
    /**
     * @description Updates the json db with new values.
     * @param {ValidJson} newData New/Changed data to be written/updated.
     * @returns Promise<void>
     */
    async update(newData) {
        let a = JSON.stringify(newData);
        return fs.writeFile(this.path, a, (err) => {
            if (err)
                throw err.message;
            if (this.options.debug) {
                console.log('Updated JSON db.');
            }
        });
    }
    get data() {
        return JSON.parse(fs.readFileSync(this.path, 'utf-8'));
    }
}
let hevc = {
    db: db,
};
exports.default = hevc;