<commit_before>'use strict';

function scaleImage(maxWidth, maxHeight, currentWidth, currentHeight) {
  var ratio = currentHeight/currentWidth;

  if (currentWidth >= maxWidth && ratio <= 1) {
    currentWidth = maxWidth;
    currentHeight = currentWidth * ratio;
  }
  else if (currentHeight >= maxHeight) {
    currentHeight = maxHeight;
    currentWidth = currentHeight/ratio;
  }

  return [currentWidth, currentHeight];
}

module.exports = function(imageSource, opts, cb) {
  if(!opts.width || !opts.height){
    return cb(new Error('max height or width required'));
  }
  var img = new Image();
  img.onload = function() {
    var scaledSize = scaleImage(opts.width, opts.height, img.width, img.height);
    var scaledWidth = scaledSize[0];
    var scaledHeight = scaledSize[1];
    var canvas = document.createElement('canvas');
    canvas.height = canvas.width * (img.height/img.width);
    var ctx = canvas.getContext('2d');
    canvas.width = scaledWidth;
    canvas.height = scaledHeight;
    ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
    return cb(null, canvas.toDataURL());
  };

  img.src = URL.createObjectURL(imageSource);
  img.onerror = cb;
};<commit_msg>scaledSize returns object instead of array<commit_after>'use strict';

function scaleImage(maxWidth, maxHeight, currentWidth, currentHeight) {
  var ratio = currentHeight/currentWidth;

  if (currentWidth >= maxWidth && ratio <= 1) {
    currentWidth = maxWidth;
    currentHeight = currentWidth * ratio;
  }
  else if (currentHeight >= maxHeight) {
    currentHeight = maxHeight;
    currentWidth = currentHeight/ratio;
  }

  return {
    width: currentWidth,
    height: currentHeight
  };
}

module.exports = function(imageSource, opts, cb) {
  if(!opts.width || !opts.height){
    return cb(new Error('max height or width required'));
  }
  var img = new Image();
  img.onload = function() {
    var scaledSize = scaleImage(opts.width, opts.height, img.width, img.height);
    var canvas = document.createElement('canvas');
    canvas.height = canvas.width * (img.height/img.width);
    var ctx = canvas.getContext('2d');
    canvas.width = scaledSize.width;
    canvas.height = scaledSize.height;
    ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
    return cb(null, canvas.toDataURL());
  };

  img.src = URL.createObjectURL(imageSource);
  img.onerror = cb;
};
{'fraction_non_alphanumeric': 0.1320355480321625, 'fraction_numerical': 0.004231908590774439, 'mean_word_length': 3.884297520661157, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7176421', 'n_tokens_mistral': 734, 'n_tokens_neox': 713, 'n_words': 175}