MCPcopy Create free account
hub / github.com/backnotprop/plannotator / parsePaginatedArray

Function parsePaginatedArray

packages/shared/cli-pagination.ts:8–56  ·  view source on GitHub ↗
(stdout: string)

Source from the content-addressed store, hash-verified

6 * them. Single-page output (the common case) round-trips through the same path.
7 */
8export function parsePaginatedArray<T>(stdout: string): T[] {
9 const trimmed = stdout.trim();
10 if (!trimmed) return [];
11
12 const slices: string[] = [];
13 let depth = 0;
14 let inString = false;
15 let escape = false;
16 let start = -1;
17
18 for (let i = 0; i < trimmed.length; i++) {
19 const c = trimmed[i];
20 if (inString) {
21 if (escape) {
22 escape = false;
23 } else if (c === "\\") {
24 escape = true;
25 } else if (c === '"') {
26 inString = false;
27 }
28 continue;
29 }
30 if (c === '"') {
31 inString = true;
32 continue;
33 }
34 if (c === "[" || c === "{") {
35 if (depth === 0 && c === "[") start = i;
36 depth++;
37 } else if (c === "]" || c === "}") {
38 depth--;
39 if (depth === 0 && c === "]" && start !== -1) {
40 slices.push(trimmed.slice(start, i + 1));
41 start = -1;
42 }
43 }
44 }
45
46 if (slices.length === 0) {
47 return JSON.parse(trimmed) as T[];
48 }
49
50 const merged: T[] = [];
51 for (const slice of slices) {
52 const page = JSON.parse(slice) as T[];
53 if (Array.isArray(page)) merged.push(...page);
54 }
55 return merged;
56}

Callers 3

fetchGhPRFunction · 0.90
fetchGlMRFunction · 0.90
pr-gitlab.test.tsFile · 0.85

Calls 2

parseMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected