| 17 | })(); |
| 18 | |
| 19 | function 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 | |
| 41 | function array_to_object(source: any[], options: { plainObjects: boolean }) { |
| 42 | const obj = options && options.plainObjects ? Object.create(null) : {}; |