MCPcopy Create free account
hub / github.com/openai/openai-node / compact_queue

Function compact_queue

src/internal/qs/utils.ts:19–39  ·  view source on GitHub ↗
(queue: Array<{ obj: T; prop: string }>)

Source from the content-addressed store, hash-verified

17})();
18
19function compact_queue<T extends Record<string, any>>(queue: Array<{ obj: T; prop: string }>) {
20 while (queue.length > 1) {
21 const item = queue.pop();
22 if (!item) continue;
23
24 const obj = item.obj[item.prop];
25
26 if (isArray(obj)) {
27 const compacted: unknown[] = [];
28
29 for (let j = 0; j < obj.length; ++j) {
30 if (typeof obj[j] !== 'undefined') {
31 compacted.push(obj[j]);
32 }
33 }
34
35 // @ts-ignore
36 item.obj[item.prop] = compacted;
37 }
38 }
39}
40
41function array_to_object(source: any[], options: { plainObjects: boolean }) {
42 const obj = options && options.plainObjects ? Object.create(null) : {};

Callers 1

compactFunction · 0.85

Calls 1

isArrayFunction · 0.90

Tested by

no test coverage detected