37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| class ExtractResult {
 | |
|     constructor(data) {
 | |
|         this._data = data || [];
 | |
| 
 | |
|     }
 | |
|     row(index) {
 | |
|         return this._data[index];
 | |
|     }
 | |
|     column(index) {
 | |
|         return [...new Array(this._data.length).keys()].map(
 | |
|             i => this._data[i][index]
 | |
|         );
 | |
|     }
 | |
|     squash() {
 | |
|         return this._data.reduce((p, c) => p.concat(c), []);
 | |
|     }
 | |
|     get data() {
 | |
|         return this._data;
 | |
|     }
 | |
|     toString(rowsCount) {
 | |
|         let data = rowsCount > 0 ? this._data.slice(0, rowsCount) : this._data;
 | |
|         return data.slice().reduce(
 | |
|             (csv, lineCells) => {
 | |
|                 if (!lineCells || !lineCells.length) {
 | |
|                     return csv + "\n";
 | |
|                 }
 | |
|                 let line = lineCells.reduce(
 | |
|                     (lineText, cell, idx) => {
 | |
|                         cell = '"' + cell.trim().replace(/"/g, '""') + '"';
 | |
|                         return lineText + cell + (idx == lineCells.length - 1 ? "" : ",")
 | |
|                     }, "");
 | |
|                 return csv + line + "\n";
 | |
|             },
 | |
|             ""
 | |
|         );
 | |
|     }
 | |
| } |