From 42f744ba09aa6aa92caa2de4548771ea1926353d Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Thu, 13 Jul 2023 06:46:46 +0300 Subject: [PATCH 1/5] Ignore package json files in prettier --- .prettierignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..cce0279 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +package.json +package-lock.json From 666293149371b1eacd23b78e62cd84b212704abf Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Thu, 13 Jul 2023 07:04:45 +0300 Subject: [PATCH 2/5] Add AUTHORS list --- AUTHORS | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 AUTHORS diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..b4a14f1 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,16 @@ +Timur Shemsedinov +Mykola Bilochub +Julia Gerasymenko +Dmytro Nechai +Denys Otrishko +Timur Sevimli +Dmitry Semigradsky +Eugene Lepeico +Serhii Moskovko +Georg Oldenburger +Bob_chemist +Aleksandr Kukharenko +Ivan Tymoshenko +Oleksandr Khodos +Nikita Machehin +Roman Popov <1@rom4.ru> From 5351b9a299b3abd1c603152f21932841b2fcab9e Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Thu, 13 Jul 2023 07:07:44 +0300 Subject: [PATCH 3/5] Fix eslint issue: class-methods-use-this --- metalog.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/metalog.js b/metalog.js index dee7799..ae7c194 100644 --- a/metalog.js +++ b/metalog.js @@ -83,6 +83,7 @@ class Console { this._groupIndent = 0; this._counts = new Map(); this._times = new Map(); + this._readline = readline; } assert(assertion, ...args) { @@ -94,8 +95,8 @@ class Console { } clear() { - readline.cursorTo(process.stdout, 0, 0); - readline.clearScreenDown(process.stdout); + this._readline.cursorTo(process.stdout, 0, 0); + this._readline.clearScreenDown(process.stdout); } count(label = 'default') { From fb6efd83a15f6c532cc78fc210a82f18623273ea Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Thu, 13 Jul 2023 07:12:13 +0300 Subject: [PATCH 4/5] Use private fields --- metalog.js | 60 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/metalog.js b/metalog.js index ae7c194..f3ee037 100644 --- a/metalog.js +++ b/metalog.js @@ -78,71 +78,73 @@ const getNextReopen = () => { }; class Console { + #write; + #groupIndent = 0; + #counts = new Map(); + #times = new Map(); + #readline = readline; + constructor(write) { - this._write = write; - this._groupIndent = 0; - this._counts = new Map(); - this._times = new Map(); - this._readline = readline; + this.#write = write; } assert(assertion, ...args) { try { console.assert(assertion, ...args); } catch (err) { - this._write('error', this._groupIndent, err.stack); + this.#write('error', this.#groupIndent, err.stack); } } clear() { - this._readline.cursorTo(process.stdout, 0, 0); - this._readline.clearScreenDown(process.stdout); + this.#readline.cursorTo(process.stdout, 0, 0); + this.#readline.clearScreenDown(process.stdout); } count(label = 'default') { - let cnt = this._counts.get(label) || 0; + let cnt = this.#counts.get(label) || 0; cnt++; - this._counts.set(label, cnt); - this._write('debug', this._groupIndent, `${label}: ${cnt}`); + this.#counts.set(label, cnt); + this.#write('debug', this.#groupIndent, `${label}: ${cnt}`); } countReset(label = 'default') { - this._counts.delete(label); + this.#counts.delete(label); } debug(...args) { - this._write('debug', this._groupIndent, ...args); + this.#write('debug', this.#groupIndent, ...args); } dir(...args) { - this._write('debug', this._groupIndent, ...args); + this.#write('debug', this.#groupIndent, ...args); } trace(...args) { const msg = util.format(...args); const err = new Error(msg); - this._write('debug', this._groupIndent, `Trace${err.stack}`); + this.#write('debug', this.#groupIndent, `Trace${err.stack}`); } info(...args) { - this._write('info', this._groupIndent, ...args); + this.#write('info', this.#groupIndent, ...args); } log(...args) { - this._write('log', this._groupIndent, ...args); + this.#write('log', this.#groupIndent, ...args); } warn(...args) { - this._write('warn', this._groupIndent, ...args); + this.#write('warn', this.#groupIndent, ...args); } error(...args) { - this._write('error', this._groupIndent, ...args); + this.#write('error', this.#groupIndent, ...args); } group(...args) { if (args.length !== 0) this.log(...args); - this._groupIndent += INDENT; + this.#groupIndent += INDENT; } groupCollapsed(...args) { @@ -150,34 +152,34 @@ class Console { } groupEnd() { - if (this._groupIndent.length === 0) return; - this._groupIndent -= INDENT; + if (this.#groupIndent.length === 0) return; + this.#groupIndent -= INDENT; } table(tabularData) { - this._write('log', 0, JSON.stringify(tabularData)); + this.#write('log', 0, JSON.stringify(tabularData)); } time(label = 'default') { - this._times.set(label, process.hrtime()); + this.#times.set(label, process.hrtime()); } timeEnd(label = 'default') { - const startTime = this._times.get(label); + const startTime = this.#times.get(label); const totalTime = process.hrtime(startTime); const totalTimeMs = totalTime[0] * 1e3 + totalTime[1] / 1e6; this.timeLog(label, `${label}: ${totalTimeMs}ms`); - this._times.delete(label); + this.#times.delete(label); } timeLog(label, ...args) { - const startTime = this._times.get(label); + const startTime = this.#times.get(label); if (startTime === undefined) { const msg = `Warning: No such label '${label}'`; - this._write('warn', this._groupIndent, msg); + this.#write('warn', this.#groupIndent, msg); return; } - this._write('debug', this._groupIndent, ...args); + this.#write('debug', this.#groupIndent, ...args); } } From d39bedeb79a3864c5bbde503e7e941c7d5d7ab5c Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Thu, 13 Jul 2023 07:15:17 +0300 Subject: [PATCH 5/5] Update .d.ts typings --- metalog.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metalog.d.ts b/metalog.d.ts index 9f548b7..355d7e6 100644 --- a/metalog.d.ts +++ b/metalog.d.ts @@ -1,4 +1,4 @@ -import EventEmitter = require('node:events'); +import { EventEmitter } from 'node:events'; interface LoggerOptions { path: string;