From 90670ebb7b728fe4c2804485e242375002e6d8cd Mon Sep 17 00:00:00 2001 From: Killer Boss Original <73131550+killerbossoriginal@users.noreply.github.com> Date: Wed, 12 Apr 2023 18:37:16 +0200 Subject: [PATCH] . --- src/index.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 50ae587..2f54248 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,8 +5,9 @@ const writeDB = promisify(fs.writeFile); class MitDB { readonly db; - fn: string; - options?: any; + filename: string; + options: any; + dirname: string; /** * @constructor @@ -15,17 +16,18 @@ class MitDB { * @param options Options to pass in the constructor * @param options.dirname where to put the database? */ - constructor(fn: string, options?: { dirname: string }) { - let dirname; + constructor(filename: string, options?: { dirname: string }) { if (options && options.dirname) { - dirname = options.dirname; + this.dirname = options.dirname; } else { - dirname = 'data'; + this.dirname = 'data'; } - if (!fs.existsSync(dirname)) fs.mkdirSync(dirname); + this.filename = filename; - this.db = `./${dirname}/${fn}` + if (!fs.existsSync(this.dirname)) fs.mkdirSync(this.dirname); + + this.db = `./${this.dirname}/${this.filename}`; } /** @@ -99,7 +101,7 @@ class MitDB { /** * - * @param callbackfn + * @param callbackfilename */ forEach(callback: (value: any, key: any) => void) { const file = fs.readFileSync(this.db);