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

yiming-liao / logry / 16359356526

18 Jul 2025 12:47AM UTC coverage: 95.783% (-1.0%) from 96.831%
16359356526

push

github

yiming-liao
fix(transport): force log delivery in edge mode regardless of conditions

432 of 486 branches covered (88.89%)

Branch coverage included in aggregate %.

3929 of 4067 relevant lines covered (96.61%)

4.3 hits per line

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

67.95
/src/modules/formatters/utils/format-object.ts
1
import { internalLog } from "@/internal";
1✔
2

1✔
3
export type StringifyFormat = "raw" | "json" | "compact" | "pretty";
1✔
4

1✔
5
/**
1✔
6
 * Converts an object into different string formats.
1✔
7
 *
1✔
8
 * @param input - The object to stringify.
1✔
9
 * @param style - Stringify style: raw, json, compact, or pretty.
1✔
10
 * @returns Formatted string or raw object.
1✔
11
 */
1✔
12
export const formatObject = (
1✔
13
  input: Record<string, unknown>,
5✔
14
  style: StringifyFormat = "pretty",
5✔
15
  indent: number = 0,
5✔
16
): Record<string, unknown> | string => {
5✔
17
  try {
5✔
18
    switch (style) {
5✔
19
      case "raw":
5✔
20
        return input;
2✔
21

5✔
22
      case "json":
5✔
23
        return JSON.stringify(input);
2✔
24

5✔
25
      case "pretty": {
5✔
26
        const indentSpaces = " ".repeat(indent);
1✔
27
        return `\n${JSON.stringify(input, null, 2)
1✔
28
          .split("\n")
1✔
29
          .map((line) => indentSpaces + line)
1✔
30
          .join("\n")}`;
1✔
31
      }
1✔
32

5✔
33
      case "compact":
5!
34
        if (typeof input !== "object" || input === null) {
×
35
          return "";
×
36
        }
×
37
        return Object.entries(input)
×
38
          .map(([key, val]) => {
✔
39
            let value;
2✔
40
            if (typeof val === "object" && val !== null) {
2!
41
              value = JSON.stringify(val);
×
42
            } else if (typeof val === "string" && /\s/.test(val)) {
2!
43
              value = `"${val}"`;
×
44
            } else {
2✔
45
              value = String(val);
2✔
46
            }
2✔
47
            return `${key}=${value}`;
2✔
48
          })
×
49
          .join(" ");
×
50

5✔
51
      default:
5!
52
        internalLog({
×
53
          type: "warn",
×
54
          message: `Unknown style "${style}", using "json" as fallback.`,
×
55
        });
×
56
        return JSON.stringify(input); // Fallback to single-line JSON
5✔
57
    }
5✔
58
  } catch (error) {
5!
59
    internalLog({
×
60
      type: "error",
×
61
      message: `Failed to stringify object. ${error instanceof Error ? error.message : String(error)}`,
×
62
    });
×
63
    return "";
×
64
  }
×
65
};
5✔
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