lib/src/util/support/debug.ts

14 lines
409 B
TypeScript
Raw Normal View History

2021-06-02 01:59:40 +00:00
export function isDebugging(key: string): boolean {
const env = 'EXTOLLO_DEBUG_' + key.split(/(?:\s|\.)+/).join('_').toUpperCase()
return process.env[env] === 'yes'
}
export function ifDebugging(key: string, run: () => any) {
if ( isDebugging(key) ) run()
}
export function logIfDebugging(key: string, ...output: any[]) {
ifDebugging(key, () => console.log(`[debug: ${key}]`, ...output))
}