-
Notifications
You must be signed in to change notification settings - Fork 17
/
row.ts
46 lines (38 loc) · 958 Bytes
/
row.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {Cell} from './cell';
import {IXLSXExtractOptions} from './types';
export class Row {
cells: Array<Cell> = [];
getFormat(options: IXLSXExtractOptions) {
switch (options.format) {
case 'json':
return this.toJson();
case 'array':
return this.toArray();
case 'obj':
return this;
// case 'tsv':
default:
return this.toTSV(options);
}
}
toTSV(options: IXLSXExtractOptions): string {
return this.cells.map(cell => cell.toTSV(options)).join(options.tsv_delimiter || '\t') + options.tsv_endofline;
}
toJson(): string {
return JSON.stringify(this.toArray());
}
toArray(): Array<string | number | undefined> {
return this.cells.map(cell => cell.val);
}
push(cell: Cell) {
this.cells.push(cell);
}
count(): number {
return this.cells.length;
}
isEmpty(): boolean {
return (this.cells.length === 0) || (this.cells.filter(function(cell) {
return (cell.val !== null);
}).length === 0);
}
}