From 5551c2987699f5ff17e273d4665db2bf66fbd9ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Sj=C3=B6green?= Date: Tue, 24 Sep 2024 13:38:26 +0200 Subject: [PATCH] fix: Allow more `console` methods (#19) --- deno.json | 2 +- mod.ts | 43 +++++++++++++++++-------------------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/deno.json b/deno.json index 956829e..bc6da23 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@denosaurs/wait", - "version": "0.2.0", + "version": "0.2.1", "exports": { ".": "./mod.ts", "./spinners": "./spinners.ts", diff --git a/mod.ts b/mod.ts index 9e4aece..bdf21b9 100644 --- a/mod.ts +++ b/mod.ts @@ -46,23 +46,7 @@ export interface PersistOptions { text?: string; } -export interface Console { - log: typeof console.log; - warn: typeof console.warn; - error: typeof console.error; - info: typeof console.info; - debug: typeof console.debug; - time: typeof console.time; - timeEnd: typeof console.timeEnd; - trace: typeof console.trace; - dir: typeof console.dir; - assert: typeof console.assert; - count: typeof console.count; - countReset: typeof console.countReset; - table: typeof console.table; - dirxml: typeof console.dirxml; - timeLog: typeof console.timeLog; -} +export type Console = typeof globalThis.console; export function wait(opts: string | SpinnerOptions): Spinner { if (typeof opts === "string") { @@ -140,24 +124,31 @@ export class Spinner { #interceptConsole(): void { const methods: (keyof Console)[] = [ "log", - "warn", - "error", - "info", "debug", - "time", - "timeEnd", - "trace", + "info", "dir", + "dirxml", + "warn", + "error", "assert", "count", "countReset", "table", - "dirxml", + "time", "timeLog", + "timeEnd", + "group", + "groupCollapsed", + "groupEnd", + "clear", + "trace", + "profile", + "profileEnd", + "timeStamp", ]; for (const method of methods) { - const original = (console as Console)[method]; - (console as Console)[method] = (...args: unknown[]) => { + const original = console[method] as (...args: unknown[]) => void; + console[method] = (...args: unknown[]) => { if (this.isSpinning) { this.stop(); this.clear();