Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
34227e5c4b |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.27.6",
|
"version": "0.27.7",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
12
src/misc.ts
12
src/misc.ts
@@ -24,12 +24,13 @@ export function compareVersions(target: string, vs: string): -1 | 0 | 1 {
|
|||||||
export function consoleInterceptor(
|
export function consoleInterceptor(
|
||||||
out: null | {debug: Function, log: Function, info: Function, warn: Function, error: Function} = console,
|
out: null | {debug: Function, log: Function, info: Function, warn: Function, error: Function} = console,
|
||||||
map?: {[K in LogLevels]?: LogLevels | 'none'}
|
map?: {[K in LogLevels]?: LogLevels | 'none'}
|
||||||
): {debug: Function, log: Function, info: Function, warn: Function, error: Function, stderr: string[], stdout: string[]} {
|
): {debug: Function, log: Function, info: Function, warn: Function, error: Function, output: {debug: any[], log: any[], info: any[], warn: any[], error: any[], stderr: any[], stdout: any[]}} {
|
||||||
const stderr: any[] = [], stdout: any[] = [];
|
const logs: any = {debug: [], log: [], info: [], warn: [], error: [], stderr: [], stdout: [],}
|
||||||
const cWrapper = (type: 'debug' | 'log' | 'info' | 'warn' | 'error') => ((...args: any[]) => {
|
const cWrapper = (type: 'debug' | 'log' | 'info' | 'warn' | 'error') => ((...args: any[]) => {
|
||||||
if(out) out[type](...args);
|
if(out) out[type](...args);
|
||||||
if(type == 'error') stderr.push(...args);
|
logs[type].push(...args);
|
||||||
else stdout.push(...args);
|
if(type == 'error') logs.stderr.push(...args);
|
||||||
|
else logs.stdout.push(...args);
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
debug: map?.debug != 'none' ? cWrapper(map?.debug || 'debug') : () => {},
|
debug: map?.debug != 'none' ? cWrapper(map?.debug || 'debug') : () => {},
|
||||||
@@ -37,8 +38,7 @@ export function consoleInterceptor(
|
|||||||
info: map?.info != 'none' ? cWrapper(map?.info || 'info') : () => {},
|
info: map?.info != 'none' ? cWrapper(map?.info || 'info') : () => {},
|
||||||
warn: map?.warn != 'none' ? cWrapper(map?.warn || 'warn') : () => {},
|
warn: map?.warn != 'none' ? cWrapper(map?.warn || 'warn') : () => {},
|
||||||
error: map?.error != 'none' ? cWrapper(map?.error || 'error') : () => {},
|
error: map?.error != 'none' ? cWrapper(map?.error || 'error') : () => {},
|
||||||
stderr,
|
output: logs
|
||||||
stdout,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user