lib/diff.js
function diffImage(existing, proposed, options) {
  let { bytes, dateformat, imageSize, Table, toFile, colors } = utils;

  existing = toFile(existing, options);
  proposed = toFile(proposed, options);

  let table = new Table({ head: ['Attribute', 'Existing', 'Replacement', 'Diff'] });
  let dimensionsA = imageSize(existing.path);
  let dimensionsB = imageSize(proposed.path);
  let statA = existing.stat;
  let statB = proposed.stat;

  let isSmaller = existing.size > proposed.size;
  let sizeDiff = isSmaller ? '-' : '+';
  sizeDiff += bytes(Math.abs(existing.size - proposed.size));

  // dates
  let mtimeA = statA ? dateformat(statA.mtime) : 'New';
  let mtimeB = statB ? dateformat(statB.mtime) : 'New';
  if (statA.mtime && statB.mtime && statA.mtime < statB.mtime) {
    mtimeB = colors.green(mtimeB);
  } else {
    mtimeA = colors.green(mtimeA);
  }

  let birthtimeA = statA ? dateformat(statA.birthtime) : 'New';
  let birthtimeB = statB ? dateformat(statB.birthtime) : 'New';
  if (statA.birthtime && statB.birthtime && statA.birthtime < statB.birthtime) {
    birthtimeB = colors.green(birthtimeB);
  } else {
    birthtimeA = colors.green(birthtimeA);
  }

  // size
  let sizeA = bytes(existing.size);
  let sizeB = bytes(proposed.size);

  if (isSmaller) {
    sizeDiff = colors.red(sizeDiff);
    dimensionsA = colors.green(dimensionsA);
    sizeA = colors.green(sizeA);
  } else {
    sizeDiff = colors.green(sizeDiff);
    dimensionsB = colors.green(dimensionsB);
    sizeB = colors.green(sizeB);
  }

  table.push(['Path', existing.relative, proposed.relative, '']);
  table.push(['Size', sizeA, sizeB, sizeDiff]);
  table.push(['Dimensions', dimensionsA, dimensionsB, 'N/A']);
  table.push(['Date created', birthtimeA, birthtimeB, 'N/A']);
  table.push(['Date modified', mtimeA, mtimeB, 'N/A']);
  return table.toString();
}
function diffImage(existing, proposed, options) {
  let { bytes, dateformat, imageSize, Table, toFile, colors } = utils;

  existing = toFile(existing, options);
  proposed = toFile(proposed, options);

  let table = new Table({ head: ['Attribute', 'Existing', 'Replacement', 'Diff'] });
  let dimensionsA = imageSize(existing.path);
  let dimensionsB = imageSize(proposed.path);
  let statA = existing.stat;
  let statB = proposed.stat;

  let isSmaller = existing.size > proposed.size;
  let sizeDiff = isSmaller ? '-' : '+';
  sizeDiff += bytes(Math.abs(existing.size - proposed.size));

  // dates
  let mtimeA = statA ? dateformat(statA.mtime) : 'New';
  let mtimeB = statB ? dateformat(statB.mtime) : 'New';
  if (statA.mtime && statB.mtime && statA.mtime < statB.mtime) {
    mtimeB = colors.green(mtimeB);
  } else {
    mtimeA = colors.green(mtimeA);
  }

  let birthtimeA = statA ? dateformat(statA.birthtime) : 'New';
  let birthtimeB = statB ? dateformat(statB.birthtime) : 'New';
  if (statA.birthtime && statB.birthtime && statA.birthtime < statB.birthtime) {
    birthtimeB = colors.green(birthtimeB);
  } else {
    birthtimeA = colors.green(birthtimeA);
  }

  // size
  let sizeA = bytes(existing.size);
  let sizeB = bytes(proposed.size);

  if (isSmaller) {
    sizeDiff = colors.red(sizeDiff);
    dimensionsA = colors.green(dimensionsA);
    sizeA = colors.green(sizeA);
  } else {
    sizeDiff = colors.green(sizeDiff);
    dimensionsB = colors.green(dimensionsB);
    sizeB = colors.green(sizeB);
  }

  table.push(['Path', existing.relative, proposed.relative, '']);
  table.push(['Size', sizeA, sizeB, sizeDiff]);
  table.push(['Dimensions', dimensionsA, dimensionsB, 'N/A']);
  table.push(['Date created', birthtimeA, birthtimeB, 'N/A']);
  table.push(['Date modified', mtimeA, mtimeB, 'N/A']);
  return table.toString();
}
function diffImage ( existing , proposed , options ) { let { bytes , dateformat , imageSize , Table , toFile , colors } = utils ; existing = toFile ( existing , options ) ; proposed = toFile ( proposed , options ) ; let table = new Table ( { head : [ 'Attribute' , 'Existing' , 'Replacement' , 'Diff' ] } ) ; let dimensionsA = imageSize ( existing . path ) ; let dimensionsB = imageSize ( proposed . path ) ; let statA = existing . stat ; let statB = proposed . stat ; let isSmaller = existing . size > proposed . size ; let sizeDiff = isSmaller ? '-' : '+' ; sizeDiff += bytes ( Math . abs ( existing . size - proposed . size ) ) ; // dates let mtimeA = statA ? dateformat ( statA . mtime ) : 'New' ; let mtimeB = statB ? dateformat ( statB . mtime ) : 'New' ; if ( statA . mtime && statB . mtime && statA . mtime < statB . mtime ) { mtimeB = colors . green ( mtimeB ) ; } else { mtimeA = colors . green ( mtimeA ) ; } let birthtimeA = statA ? dateformat ( statA . birthtime ) : 'New' ; let birthtimeB = statB ? dateformat ( statB . birthtime ) : 'New' ; if ( statA . birthtime && statB . birthtime && statA . birthtime < statB . birthtime ) { birthtimeB = colors . green ( birthtimeB ) ; } else { birthtimeA = colors . green ( birthtimeA ) ; } // size let sizeA = bytes ( existing . size ) ; let sizeB = bytes ( proposed . size ) ; if ( isSmaller ) { sizeDiff = colors . red ( sizeDiff ) ; dimensionsA = colors . green ( dimensionsA ) ; sizeA = colors . green ( sizeA ) ; } else { sizeDiff = colors . green ( sizeDiff ) ; dimensionsB = colors . green ( dimensionsB ) ; sizeB = colors . green ( sizeB ) ; } table . push ( [ 'Path' , existing . relative , proposed . relative , '' ] ) ; table . push ( [ 'Size' , sizeA , sizeB , sizeDiff ] ) ; table . push ( [ 'Dimensions' , dimensionsA , dimensionsB , 'N/A' ] ) ; table . push ( [ 'Date created' , birthtimeA , birthtimeB , 'N/A' ] ) ; table . push ( [ 'Date modified' , mtimeA , mtimeB , 'N/A' ] ) ; return table . toString ( ) ; }
Shows table of the differences in stats between two binary files.
@param {String} `filepath` File path of the existing (old) file.
@param {Buffer} `contents` Buffered contents of the proposed (new) file.
Shows table of the differences in stats between two binary files .