| 46 | File(output?: "tuples"): Value[][]; |
| 47 | File(output?: "tuples" | "objects"): { [k: string]: Value }[] | Value[][]; |
| 48 | File(output?: "tuples" | "objects"): { [k: string]: Value }[] | Value[][] { |
| 49 | const rows: Value[][] = []; |
| 50 | while (true) { |
| 51 | const tempointer = this.pointer; |
| 52 | const row: Value[] = this.Row(); |
| 53 | if (row.length > 0) { |
| 54 | this.linePointer = tempointer; |
| 55 | rows.push(row); |
| 56 | } else { |
| 57 | if (this.linePointer && this.pointer !== this.input.length) { |
| 58 | rows.pop(); |
| 59 | this.pointer = this.linePointer; |
| 60 | } |
| 61 | break; |
| 62 | } |
| 63 | if (this.EOF()) { |
| 64 | if (this.linePointer && this.pointer !== this.input.length) { |
| 65 | rows.pop(); |
| 66 | this.pointer = this.linePointer; |
| 67 | } |
| 68 | break; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (output && output === "objects") { |
| 73 | if (rows.length === 0) { |
| 74 | return []; |
| 75 | } |
| 76 | const headers = rows.shift()!.map(k => k.trim()); |
| 77 | return rows.map(row => headers.reduce<{ [k: string]: Value }>((data, k, i) => { |
| 78 | data[k] = row[i] |
| 79 | return data; |
| 80 | }, {})); |
| 81 | } else { |
| 82 | return rows; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | Row(): Value[] { |
| 87 | const row: Value[] = []; |