• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WolferyScripting / resclient-ts / #32

27 Aug 2025 09:08PM UTC coverage: 51.192% (+0.2%) from 51.041%
#32

push

DonovanDMC
1.1.4

230 of 292 branches covered (78.77%)

Branch coverage included in aggregate %.

1660 of 3400 relevant lines covered (48.82%)

10.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.34
/lib/util/Debug.ts
1
import type { Debug as DebugType } from "debug";
1✔
2
import { formatWithOptions } from "node:util";
1✔
3

1✔
4
// the things I do for esm first with cjs support
1✔
5
let debug: DebugType | undefined | null;
1✔
6
function getDebug(): Promise<DebugType | null> | DebugType | null {
38✔
7
    if (debug !== undefined) return debug;
38✔
8
    try {
4✔
9
        // eslint-disable-next-line unicorn/prefer-module
4✔
10
        if (typeof require === "undefined") {
4✔
11
            return import("debug").then(mod => (debug = mod.default)).catch(() => (debug = null));
4✔
12
        } else {
38!
13
        // eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
×
14
            debug = (require("debug") as { default: DebugType; }).default;
×
15
        }
×
16
    } catch {
38!
17
        debug = null;
×
18
    }
×
19
    return debug;
×
20
}
×
21

1✔
22
let maxTotalLength = 2000;
1✔
23
let maxLines = 30;
1✔
24
function formatMaxLength(args: Array<unknown>, d = depth): string {
38✔
25
    const formatted = formatWithOptions({ colors: true, showHidden: false, depth: d }, ...args);
38✔
26
    if (d === Infinity) return formatted;
38!
27
    if (formatted.length > maxTotalLength || formatted.split("\n").length > maxLines) {
38!
28
        d -= 1;
×
29
        if (d >= 0) return formatMaxLength(args, d);
×
30
    }
×
31
    return formatted;
38✔
32
}
38✔
33

1✔
34
let depth = 2;
1✔
35
export function Debug(namspace: string, arg0: unknown, ...args: Array<unknown>): void {
1✔
36
    const log = (dt: DebugType): void => dt(`wolferyjs:${namspace}`)(formatMaxLength([arg0, ...args]));
38✔
37
    const d = getDebug();
38✔
38
    if (d instanceof Promise) {
38✔
39
        void d.then(dt => {
4✔
40
            if (dt) {
4✔
41
                log(dt);
4✔
42
            }
4✔
43
        });
4✔
44
    } else if (d) {
38✔
45
        log(d);
34✔
46
    }
34✔
47
}
38✔
48

1✔
49
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1✔
50
export function createDebug(namespace: string): (formatter: any, ...args: Array<any>) => void {
1✔
51
    const d = getDebug();
×
52
    if (!d || d instanceof Promise) {
×
53
        return () => {}; // noop
×
54
    }
×
55
    return d(`resclient:${namespace}`);
×
56
}
×
57

1✔
58
/**
1✔
59
 * Set the inspection depth for debug messages.
1✔
60
 * @param d The depth.
1✔
61
 */
1✔
62
export function setDebugDepth(d: number): void {
1✔
63
    depth = d;
×
64
}
×
65

1✔
66
/**
1✔
67
 * Set the maximum total length for debug messages.
1✔
68
 * @param d The maximum total length.
1✔
69
 */
1✔
70
export function setDebugMaxTotalLength(d: number): void {
1✔
71
    maxTotalLength = d;
×
72
}
×
73

1✔
74
/**
1✔
75
 * Set the maximum number of lines for debug messages.
1✔
76
 * @param d The maximum number of lines.
1✔
77
 */
1✔
78
export function setDebugMaxLines(d: number): void {
1✔
79
    maxLines = d;
×
80
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc