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:
parent
04753c07da
commit
6af46847d3
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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<number> = {}
|
||||
private countCount: Record<string, number> = {}
|
||||
|
||||
/**
|
||||
* `time` function object value
|
||||
*/
|
||||
private timeCount: ObjectArray<Date> = {}
|
||||
private timeCount: Record<string, Date> = {}
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user