Skip to content

Commit

Permalink
fix: Allow more console methods (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliassjogreen authored Sep 24, 2024
1 parent 66d251a commit 5551c29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@denosaurs/wait",
"version": "0.2.0",
"version": "0.2.1",
"exports": {
".": "./mod.ts",
"./spinners": "./spinners.ts",
Expand Down
43 changes: 17 additions & 26 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 5551c29

Please sign in to comment.