Skip to content

Commit

Permalink
Add console helper
Browse files Browse the repository at this point in the history
  • Loading branch information
achainjere committed Oct 10, 2023
1 parent d198d77 commit 9679bbd
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions src/helpers/console.helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CONSOLE_LOG_STYLES, LogInterface } from '../models/index.js';
import { LogInterface } from '../models/index.js';
import { TypeHelper } from './type.helper.js';
import { TreeHelper } from './tree.helper.js';

Expand All @@ -10,40 +10,32 @@ export abstract class ConsoleHelper {
) {
const parentLog = ConsoleHelper.format(parent);

console.group(
`%c ${ parentLog.title }`,
ConsoleHelper.log(
parentLog.title,
colors && colors[0] ? colors[0] : '',
...(parentLog.data ?? []),
true,
...parentLog.data ?? []
);

children.forEach((child, index) => {
const childLog = ConsoleHelper.format(child);

console.log(
`%c ${ childLog.title }`,
ConsoleHelper.log(
childLog.title,
colors && colors[index + 1] ? colors[index + 1] : '',
...(childLog.data ?? []),
);
false,
...childLog.data ?? []
)
}
)

console.groupEnd();
}

static logBlue(title: string, ...data: any[]) {
console.log(`%c ${ title }`, CONSOLE_LOG_STYLES.blue, ...data);
}

static logGreen(title: string, ...data: any[]) {
console.log(`%c ${ title }`, CONSOLE_LOG_STYLES.green, ...data);
}

static logGrey(title: string, ...data: any[]) {
console.log(`%c ${ title }`, CONSOLE_LOG_STYLES.grey, ...data);
}
static log(title: string, style: string, isGroup: boolean = false, ...data: any[]) {
const fn = isGroup ? console.group : console.log;

static logRed(title: string, ...data: any[]) {
console.log(`%c ${ title }`, CONSOLE_LOG_STYLES.red, ...data);
fn.call(console, `%c ${ title }`, style, ...data);
}

private static format(log: LogInterface | string | any): LogInterface {
Expand Down

0 comments on commit 9679bbd

Please sign in to comment.