Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@leafer/debug

Package Overview
Dependencies
Maintainers
1
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafer/debug - npm Package Compare versions

Comparing version
1.0.0-beta.15
to
1.0.0-beta.16
+68
src/Debug.ts
import { IBooleanMap } from '@leafer/interface'
export class Debug {
static enable: boolean
static filterList: string[] = []
static excludeList: string[] = []
// other
static showRepaint: boolean
static showHitView: boolean | string | string[]
static showBoundsView: boolean | string | string[]
public name: string
public repeatMap: IBooleanMap = {}
constructor(name: string) {
this.name = name
}
static get(name: string): Debug {
return new Debug(name)
}
static set filter(name: string | string[]) {
if (!name) name = []
else if (typeof name === 'string') name = [name]
this.filterList = name
}
static set exclude(name: string | string[]) {
if (!name) name = []
else if (typeof name === 'string') name = [name]
this.excludeList = name
}
log(...messages: unknown[]): void {
if (D.enable) {
if (D.filterList.length && D.filterList.every(name => name !== this.name)) return
if (D.excludeList.length && D.excludeList.some(name => name === this.name)) return
console.log('%c' + this.name, 'color:#21ae62', ...messages)
}
}
warn(...messages: unknown[]): void {
if (D.enable) console.warn(this.name, ...messages)
}
repeat(name: string, ...messages: unknown[]) {
if (!this.repeatMap[name]) {
this.warn('repeat:' + name, ...messages)
this.repeatMap[name] = true
}
}
error(...messages: unknown[]): void {
try {
throw new Error()
} catch (e) {
console.error(this.name, ...messages, e)
}
}
}
const D = Debug
import { IncrementId } from '@leafer/math'
import { Debug } from './Debug'
interface ids {
[name: string]: number
}
interface names {
[name: string]: string
}
const debug = Debug.get('RunTime')
export class Run {
static currentId: number
static currentTime: number
static currentName: string
static idMap: ids = {}
static nameMap: names = {}
static nameToIdMap: ids = {}
static start(name: string, microsecond?: boolean): number {
const id = IncrementId.create(IncrementId.RUNTIME)
R.currentId = R.idMap[id] = microsecond ? performance.now() : Date.now()
R.currentName = R.nameMap[id] = name
R.nameToIdMap[name] = id
return id
}
static end(id: number, microsecond?: boolean): void {
const time = R.idMap[id]
const name = R.nameMap[id]
R.idMap[id] = R.nameMap[id] = R.nameToIdMap[name] = undefined
if (microsecond) {
debug.log(name, performance.now() - time, 'µs')
} else {
debug.log(name, Date.now() - time, 'ms')
}
}
static endOfName(name: string, microsecond?: boolean): void {
const id = R.nameToIdMap[name]
if (id !== undefined) R.end(id, microsecond)
}
}
const R = Run
+4
-3
{
"name": "@leafer/debug",
"version": "1.0.0-beta.15",
"version": "1.0.0-beta.16",
"description": "@leafer/debug",

@@ -10,2 +10,3 @@ "author": "Chao (Leafer) Wan",

"files": [
"src",
"types",

@@ -25,7 +26,7 @@ "dist"

"dependencies": {
"@leafer/math": "1.0.0-beta.15"
"@leafer/math": "1.0.0-beta.16"
},
"devDependencies": {
"@leafer/interface": "1.0.0-beta.15"
"@leafer/interface": "1.0.0-beta.16"
}
}