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

graphty-org / graphty-monorepo / 20661584252

02 Jan 2026 03:50PM UTC coverage: 77.924% (+7.3%) from 70.62%
20661584252

push

github

apowers313
ci: fix flakey performance test

13438 of 17822 branches covered (75.4%)

Branch coverage included in aggregate %.

41247 of 52355 relevant lines covered (78.78%)

145534.85 hits per line

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

89.29
/graphty-element/src/data/format-detection.ts
1
export type FormatType = "json" | "graphml" | "gexf" | "csv" | "gml" | "dot" | "pajek";
7✔
2

3
export interface FormatInfo {
4
    name: string;
5
    extensions: string[];
6
    mimeTypes: string[];
7
}
8

9
const FORMAT_INFO: Record<FormatType, FormatInfo> = {
3✔
10
    json: {
3✔
11
        name: "JSON",
3✔
12
        extensions: [".json"],
3✔
13
        mimeTypes: ["application/json"],
3✔
14
    },
3✔
15
    graphml: {
3✔
16
        name: "GraphML",
3✔
17
        extensions: [".graphml", ".xml"],
3✔
18
        mimeTypes: ["application/graphml+xml", "application/xml", "text/xml"],
3✔
19
    },
3✔
20
    gexf: {
3✔
21
        name: "GEXF",
3✔
22
        extensions: [".gexf"],
3✔
23
        mimeTypes: ["application/gexf+xml", "application/xml", "text/xml"],
3✔
24
    },
3✔
25
    csv: {
3✔
26
        name: "CSV",
3✔
27
        extensions: [".csv", ".edges", ".edgelist"],
3✔
28
        mimeTypes: ["text/csv", "text/plain"],
3✔
29
    },
3✔
30
    gml: {
3✔
31
        name: "GML",
3✔
32
        extensions: [".gml"],
3✔
33
        mimeTypes: ["text/plain"],
3✔
34
    },
3✔
35
    dot: {
3✔
36
        name: "DOT",
3✔
37
        extensions: [".dot", ".gv"],
3✔
38
        mimeTypes: ["text/vnd.graphviz", "text/plain"],
3✔
39
    },
3✔
40
    pajek: {
3✔
41
        name: "Pajek NET",
3✔
42
        extensions: [".net", ".paj"],
3✔
43
        mimeTypes: ["text/plain"],
3✔
44
    },
3✔
45
};
3✔
46

47
/**
48
 * Detect graph data format from filename and/or content
49
 * @param filename - File name (can be empty)
50
 * @param content - File content sample (can be empty)
51
 * @returns Detected format or null if unknown
52
 */
53
export function detectFormat(filename: string, content: string): FormatType | null {
3✔
54
    // 1. Try extension first (fast path)
55
    if (filename) {
26✔
56
        const extMatch = /\.[^.]+$/.exec(filename.toLowerCase());
20✔
57
        const ext = extMatch?.[0];
20✔
58
        if (ext) {
20✔
59
            // Check each format's extensions
60
            for (const [format, info] of Object.entries(FORMAT_INFO)) {
20✔
61
                if (info.extensions.includes(ext)) {
98✔
62
                    // Special case: .xml could be GraphML or GEXF, need content check
63
                    if (ext === ".xml" && content) {
9!
64
                        const xmlFormat = detectXMLFormat(content);
2✔
65
                        if (xmlFormat) {
2✔
66
                            return xmlFormat;
2✔
67
                        }
2✔
68
                    }
2✔
69

70
                    return format as FormatType;
7✔
71
                }
7✔
72
            }
98✔
73
        }
11✔
74
    }
20✔
75

76
    // 2. Inspect content
77
    if (!content) {
26!
78
        return null;
5✔
79
    }
5✔
80

81
    const trimmed = content.trim();
12✔
82

83
    // XML-based formats
84
    if (trimmed.startsWith("<?xml") || trimmed.startsWith("<")) {
26✔
85
        return detectXMLFormat(trimmed);
4✔
86
    }
4✔
87

88
    // JSON
89
    if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
26✔
90
        return "json";
2✔
91
    }
2✔
92

93
    // Text-based formats
94
    if (/graph\s*\[/i.test(trimmed)) {
26!
95
        return "gml";
1✔
96
    }
1✔
97

98
    if (/^\*vertices/i.test(trimmed)) {
26!
99
        return "pajek";
1✔
100
    }
1✔
101

102
    if (/^\s*(strict\s+)?(di)?graph\s+/i.test(trimmed)) {
26!
103
        return "dot";
1✔
104
    }
1✔
105

106
    // CSV (very generic, check last)
107
    if (/^[\w-]+\s*,\s*[\w-]+/m.test(trimmed)) {
26!
108
        return "csv";
×
109
    }
✔
110

111
    return null;
3✔
112
}
3✔
113

114
function detectXMLFormat(content: string): FormatType | null {
6✔
115
    if (content.includes('xmlns="http://graphml.graphdrawing.org')) {
6✔
116
        return "graphml";
4✔
117
    }
4!
118

119
    if (content.includes('xmlns="http://gexf.net')) {
2✔
120
        return "gexf";
2✔
121
    }
2!
122

123
    return null;
×
124
}
×
125

126
/**
127
 * Gets detailed information about a specific graph data format.
128
 * @param format - The format type identifier
129
 * @returns FormatInfo object with format details
130
 */
131
export function getFormatInfo(format: FormatType): FormatInfo {
3✔
132
    return FORMAT_INFO[format];
×
133
}
×
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