Compare commits

..

1 Commits

Author SHA1 Message Date
34227e5c4b Added console wrapper
Some checks failed
Build / Build NPM Project (push) Successful in 53s
Build / Publish Documentation (push) Failing after 10s
Build / Tag Version (push) Successful in 15s
2025-10-18 17:03:49 -04:00
2 changed files with 7 additions and 7 deletions

View File

@@ -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",

View File

@@ -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,
} }
} }