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