diff --git a/package.json b/package.json index 3ab9344..f543c26 100644 --- a/package.json +++ b/package.json @@ -19,5 +19,8 @@ "ts-jest": "^27.0.5", "ts-node": "^10.2.1", "typescript": "^4.4.3" + }, + "scripts": { + "build": "npm run build --workspaces --if-present" } } diff --git a/packages/logger/package.json b/packages/logger/package.json index de5d982..1168769 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -12,7 +12,7 @@ "main": "./dist/Logger.js", "types": "./dist/Logger.d.ts", "dependencies": { - "ansi-colors": "^4.1.1" + "picocolors": "^1.0.0" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^4.5.0", diff --git a/packages/logger/src/Logger.ts b/packages/logger/src/Logger.ts index 5f2f928..cf75479 100644 --- a/packages/logger/src/Logger.ts +++ b/packages/logger/src/Logger.ts @@ -1,5 +1,5 @@ -import colors, { black, white, blue, yellow, green } from 'ansi-colors' -import { theme, logType, ObjectArray } from '../typing/types' +import { black, blue, green, white, yellow } from 'picocolors' +import { logType, theme } from '../typing/types' export default class Logger implements Console { @@ -51,12 +51,12 @@ export default class Logger implements Console { /** * `count` function object value */ - private countCount: ObjectArray = {} + private countCount: Record = {} /** * `time` function object value */ - private timeCount: ObjectArray = {} + private timeCount: Record = {} /** * Construct a new Logger @@ -66,12 +66,6 @@ export default class Logger implements Console { public prefix: string = 'Logger' ) { Logger.loggers.push(this) - - // If Firefox disable colors - // @ts-ignore - if (typeof InstallTrigger !== 'undefined') { - colors.enabled = false - } } /** @@ -129,7 +123,7 @@ export default class Logger implements Console { * @param label Display label, default to `default` */ public count(label: string = 'default'): void { - if (!Object.prototype.hasOwnProperty.call(this.countCount, label)) { + if (!(label in this.countCount)) { this.countCount[label] = 0 } this.log(`${label}:`, ++this.countCount[label]) @@ -274,7 +268,7 @@ export default class Logger implements Console { * @param label Timer label */ public time(label: string = 'default'): void { - if (!Object.prototype.hasOwnProperty.call(this.timeCount, label)) { + if (!this.timeCount[label]) { this.timeCount[label] = new Date() return } @@ -363,7 +357,7 @@ export default class Logger implements Console { const spacers: Array = ['', ''] if (Logger.prefixLen > prefixLen) { const diff = Logger.prefixLen - prefixLen - const diff2 = diff /2 + const diff2 = diff / 2 spacers[0] = this.buildSpace(diff2 - (diff % 2 !== 0 ? 1 : 0)) spacers[1] = this.buildSpace(diff2) } @@ -373,9 +367,9 @@ export default class Logger implements Console { if (Logger.timestamp) { const now = new Date() - const h = now.getHours() >= 10 ? now.getHours().toString() : `0${now.getHours()}` - const m = now.getMinutes() >= 10 ? now.getMinutes().toString() : `0${now.getMinutes()}` - const s = now.getSeconds() >= 10 ? now.getSeconds().toString() : `0${now.getSeconds()}` + const h = now.getHours().toString().padStart(2, '0') + const m = now.getMinutes().toString().padStart(2, '0') + const s = now.getSeconds().toString().padStart(2, '0') res.unshift(`${this.blackOrWhite('<')}${yellow(h)}:${yellow(m)}:${yellow(s)}${this.blackOrWhite('>')}`) } return res.concat(