MCPcopy Create free account
hub / github.com/ProtonDriveApps/sdk / printIterable

Function printIterable

cli/src/cli/formatters.ts:15–38  ·  view source on GitHub ↗
(
    iterable: AsyncIterable<T> | T[],
    json: boolean,
    humanReadableWriter: (item: T) => void = (item) => console.log(formatReadableJson(item)),
    jsonTransform: (item: T) => object = (json) => json,
)

Source from the content-addressed store, hash-verified

13}
14
15export async function printIterable<T extends object>(
16 iterable: AsyncIterable<T> | T[],
17 json: boolean,
18 humanReadableWriter: (item: T) => void = (item) => console.log(formatReadableJson(item)),
19 jsonTransform: (item: T) => object = (json) => json,
20): Promise<void> {
21 if (json) {
22 // Output streaming JSON array format
23 process.stdout.write('[\n');
24 let isFirst = true;
25 for await (const item of iterable) {
26 if (!isFirst) {
27 process.stdout.write(',\n');
28 }
29 process.stdout.write(JSON.stringify(jsonTransform(item)));
30 isFirst = false;
31 }
32 process.stdout.write('\n]\n');
33 } else {
34 for await (const item of iterable) {
35 humanReadableWriter(item);
36 }
37 }
38}
39
40export function formatReadableJson(json: object) {
41 // Prints the JSON in a readable format without the depth limit.

Callers 13

actionMethod · 0.90
copyNodeMethod · 0.90
copyNodesMethod · 0.90
moveNodesMethod · 0.90
actionMethod · 0.90
actionMethod · 0.90
actionMethod · 0.90
actionMethod · 0.90
printDevicesMethod · 0.90
printChildrenMethod · 0.90
printSharedNodesMethod · 0.90
printSharedWithMeMethod · 0.90

Calls 3

formatReadableJsonFunction · 0.85
logMethod · 0.65
writeMethod · 0.45

Tested by

no test coverage detected