Created
May 9, 2023 18:38
-
-
Save moritztim/d14435541fb9e7ef9313a1a726d9b263 to your computer and use it in GitHub Desktop.
Simple (and incomplete) utility to allow for an (incomplete) analog to console.group() and console.groupEnd() in Deno's log lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { denoLog } from "https://deno.land/std@/log/mod.ts"; | |
/** Singleton to keep track of the current groups */ | |
class Groups { | |
private static _groups: string[] = []; | |
public static get groups() { | |
return Groups._groups; | |
} | |
public static push(name: string) { | |
Groups._groups.push(name); | |
} | |
public static pop() { | |
return Groups._groups.pop(); | |
} | |
} | |
const group = (name: string, ...args: unknown[]) => { | |
denoLog.info(`${name}...`, ...args); | |
Groups.push(name); | |
} | |
const groupEnd = (message?: string, ...args: unknown[]) => { | |
denoLog.info(message ?? `Done ${Groups.pop() ?? ""}.`, ...args); | |
} | |
export default { | |
...denoLog, | |
group, | |
groupEnd | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment