1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-04-22 10:52:11 +00:00

feat: Use picolors to reduce size

Signed-off-by: Avior <f.bouillon@aptatio.com>
This commit is contained in:
Florian Bouillon 2023-03-22 10:54:54 +01:00
parent 04753c07da
commit 6af46847d3
Signed by: Florian Bouillon
GPG Key ID: E05B3A94178D3A7C
3 changed files with 14 additions and 17 deletions

View File

@ -19,5 +19,8 @@
"ts-jest": "^27.0.5", "ts-jest": "^27.0.5",
"ts-node": "^10.2.1", "ts-node": "^10.2.1",
"typescript": "^4.4.3" "typescript": "^4.4.3"
},
"scripts": {
"build": "npm run build --workspaces --if-present"
} }
} }

View File

@ -12,7 +12,7 @@
"main": "./dist/Logger.js", "main": "./dist/Logger.js",
"types": "./dist/Logger.d.ts", "types": "./dist/Logger.d.ts",
"dependencies": { "dependencies": {
"ansi-colors": "^4.1.1" "picocolors": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.5.0", "@typescript-eslint/eslint-plugin": "^4.5.0",

View File

@ -1,5 +1,5 @@
import colors, { black, white, blue, yellow, green } from 'ansi-colors' import { black, blue, green, white, yellow } from 'picocolors'
import { theme, logType, ObjectArray } from '../typing/types' import { logType, theme } from '../typing/types'
export default class Logger implements Console { export default class Logger implements Console {
@ -51,12 +51,12 @@ export default class Logger implements Console {
/** /**
* `count` function object value * `count` function object value
*/ */
private countCount: ObjectArray<number> = {} private countCount: Record<string, number> = {}
/** /**
* `time` function object value * `time` function object value
*/ */
private timeCount: ObjectArray<Date> = {} private timeCount: Record<string, Date> = {}
/** /**
* Construct a new Logger * Construct a new Logger
@ -66,12 +66,6 @@ export default class Logger implements Console {
public prefix: string = 'Logger' public prefix: string = 'Logger'
) { ) {
Logger.loggers.push(this) 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` * @param label Display label, default to `default`
*/ */
public count(label: string = 'default'): void { public count(label: string = 'default'): void {
if (!Object.prototype.hasOwnProperty.call(this.countCount, label)) { if (!(label in this.countCount)) {
this.countCount[label] = 0 this.countCount[label] = 0
} }
this.log(`${label}:`, ++this.countCount[label]) this.log(`${label}:`, ++this.countCount[label])
@ -274,7 +268,7 @@ export default class Logger implements Console {
* @param label Timer label * @param label Timer label
*/ */
public time(label: string = 'default'): void { public time(label: string = 'default'): void {
if (!Object.prototype.hasOwnProperty.call(this.timeCount, label)) { if (!this.timeCount[label]) {
this.timeCount[label] = new Date() this.timeCount[label] = new Date()
return return
} }
@ -373,9 +367,9 @@ export default class Logger implements Console {
if (Logger.timestamp) { if (Logger.timestamp) {
const now = new Date() const now = new Date()
const h = now.getHours() >= 10 ? now.getHours().toString() : `0${now.getHours()}` const h = now.getHours().toString().padStart(2, '0')
const m = now.getMinutes() >= 10 ? now.getMinutes().toString() : `0${now.getMinutes()}` const m = now.getMinutes().toString().padStart(2, '0')
const s = now.getSeconds() >= 10 ? now.getSeconds().toString() : `0${now.getSeconds()}` const s = now.getSeconds().toString().padStart(2, '0')
res.unshift(`${this.blackOrWhite('<')}${yellow(h)}:${yellow(m)}:${yellow(s)}${this.blackOrWhite('>')}`) res.unshift(`${this.blackOrWhite('<')}${yellow(h)}:${yellow(m)}:${yellow(s)}${this.blackOrWhite('>')}`)
} }
return res.concat( return res.concat(