All files / src/models json-array.js

56% Statements 14/25
100% Branches 2/2
25% Functions 1/4
56% Lines 14/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 26193x 193x 193x 193x 193x 10x 10x 193x 193x     193x 193x               193x 193x     193x  
/**
 * Helper to print a real JSON array with starting `[` and ending `]`
 */
export class JsonArray {
  constructor() {
    this._isFirst = true;
  }
 
  open() {
    process.stdout.write('[\n');
  }
 
  push(log) {
    if (this._isFirst) {
      this._isFirst = false;
    } else {
      process.stdout.write(',\n');
    }
    process.stdout.write(`  ${JSON.stringify(log)}`);
  }
 
  close() {
    process.stdout.write('\n]');
  }
}