All files / src/commands/util _head_tail_util.js

100% Statements 12/12
100% Branches 4/4
100% Functions 1/1
100% Lines 10/10

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 221x 1x   1x   8x 8x   8x 2x         6x 6x   6x        
import * as FileOp from 'fs/operations-with-permissions/file-operations';
import * as OutputFactory from 'emulator-output/output-factory';
 
const DEFAULT_LINE_COUNT = 10;
 
export const trimFileContent = (fs, filePath, options, trimmingFn) => {
  const {file, err} = FileOp.readFile(fs, filePath);
 
  if (err) {
    return {
      err: OutputFactory.makeErrorOutput(err)
    };
  };
 
  const linesCount = options.lines ? Number(options.lines) : DEFAULT_LINE_COUNT;
  const trimmedLines = trimmingFn(file.get('content').split('\n'), linesCount);
 
  return {
    content: trimmedLines.join('\n')
  };
};