<commit_before>/*jslint node: true */
'use strict';

var Promise = require('bluebird');
var sharp = require('./build/Release/sharp');

var Sharp = function(input) {
  if (!(this instanceof Sharp)) {
    return new Sharp(input);
  }
  this.options = {
    width: -1,
    height: -1,
    canvas: 'c',
    angle: 0,
    withoutEnlargement: false,
    sharpen: false,
    progressive: false,
    sequentialRead: false,
		quality: 80,
		compressionLevel: 6,
    output: '__jpeg'
  };
  if (typeof input === 'string') {
    this.options.fileIn = input;
  } else if (typeof input ==='object' && input instanceof Buffer) {
    if (input.length > 0) {
      this.options.bufferIn = input;
    } else {
      throw 'Buffer is empty';
    }
  } else {
    throw 'Unsupported input ' + typeof input;
  }
  return this;
};
module.exports = Sharp;

Sharp.prototype.crop = function() {
  this.options.canvas = 'c';
  return this;
};

Sharp.prototype.embedWhite = function() {
  this.options.canvas = 'w';
  return this;
};

Sharp.prototype.embedBlack = function() {
  this.options.canvas = 'b';
  return this;
};

Sharp.prototype.max = function() {
  this.options.canvas = 'm';
  return this;
};

/*
  Rotate output image by 0, 90, 180 or 270 degrees
  Auto-rotation based on the EXIF Orientation tag is represented by an angle of -1
*/
Sharp.prototype.rotate = function(angle) {
  if (typeof angle === 'undefined') {
    this.options.angle = -1;
  } else if (!Number.isNaN(angle) && [0, 90, 180, 270].indexOf(angle) !== -1) {
    this.options.angle = angle;
  } else {
    throw 'Unsupport angle (0, 90, 180, 270) ' + angle;
  }
  return this;
};

/*
  Do not enlarge the output if the input width *or* height are already less than the required dimensions
  This is equivalent to GraphicsMagick's ">" geometry option:
    "change the dimensions of the image only if its width or height exceeds the geometry specification"
*/
Sharp.prototype.withoutEnlargement = function(withoutEnlargement) {
  this.options.withoutEnlargement = (typeof withoutEnlargement === 'boolean') ? withoutEnlargement : true;
  return this;
};

Sharp.prototype.sharpen = function(sharpen) {
  this.options.sharpen = (typeof sharpen === 'boolean') ? sharpen : true;
  return this;
};

Sharp.prototype.progressive = function(progressive) {
  this.options.progressive = (typeof progressive === 'boolean') ? progressive : true;
  return this;
};

Sharp.prototype.sequentialRead = function(sequentialRead) {
  this.options.sequentialRead = (typeof sequentialRead === 'boolean') ? sequentialRead : true;
  return this;
};

Sharp.prototype.quality = function(quality) {
  if (!Number.isNaN(quality) && quality >= 1 && quality <= 100) {
    this.options.quality = quality;
  } else {
    throw 'Invalid quality (1 to 100) ' + quality;
  }
  return this;
};

Sharp.prototype.compressionLevel = function(compressionLevel) {
  if (!Number.isNaN(compressionLevel) && compressionLevel >= -1 && compressionLevel <= 9) {
    this.options.compressionLevel = compressionLevel;
  } else {
    throw 'Invalid compressionLevel (-1 to 9) ' + compressionLevel;
  }
  return this;
};

Sharp.prototype.resize = function(width, height) {
  if (!width) {
    this.options.width = -1;
  } else {
    if (!Number.isNaN(width)) {
      this.options.width = width;
    } else {
      throw 'Invalid width ' + width;
    }
  }
  if (!height) {
    this.options.height = -1;
  } else {
    if (!Number.isNaN(height)) {
      this.options.height = height;
    } else {
      throw 'Invalid height ' + height;
    }
  }
  return this;
};

/*
  Write output image data to a file
*/
Sharp.prototype.toFile = function(output, callback) {
  if (!output || output.length === 0) {
    callback('Invalid output');
  } else {
    if (this.options.fileIn === output) {
      callback('Cannot use same file for input and output');
    } else {
      return this._sharp(output, callback);<commit_msg>fix error types, support promises on convenience methods<commit_after>/*jslint node: true */
'use strict';

var Promise = require('bluebird');
var sharp = require('./build/Release/sharp');

var Sharp = function(input) {
  if (!(this instanceof Sharp)) {
    return new Sharp(input);
  }
  this.options = {
    width: -1,
    height: -1,
    canvas: 'c',
    angle: 0,
    withoutEnlargement: false,
    sharpen: false,
    progressive: false,
    sequentialRead: false,
		quality: 80,
		compressionLevel: 6,
    output: '__jpeg'
  };
  if (typeof input === 'string') {
    this.options.fileIn = input;
  } else if (typeof input ==='object' && input instanceof Buffer) {
    if (input.length > 0) {
      this.options.bufferIn = input;
    } else {
      throw new Error('Buffer is empty');
    }
  } else {
    throw new Error('Unsupported input ' + typeof input);
  }
  return this;
};
module.exports = Sharp;

Sharp.prototype.crop = function() {
  this.options.canvas = 'c';
  return this;
};

Sharp.prototype.embedWhite = function() {
  this.options.canvas = 'w';
  return this;
};

Sharp.prototype.embedBlack = function() {
  this.options.canvas = 'b';
  return this;
};

Sharp.prototype.max = function() {
  this.options.canvas = 'm';
  return this;
};

/*
  Rotate output image by 0, 90, 180 or 270 degrees
  Auto-rotation based on the EXIF Orientation tag is represented by an angle of -1
*/
Sharp.prototype.rotate = function(angle) {
  if (typeof angle === 'undefined') {
    this.options.angle = -1;
  } else if (!Number.isNaN(angle) && [0, 90, 180, 270].indexOf(angle) !== -1) {
    this.options.angle = angle;
  } else {
    throw 'Unsupport angle (0, 90, 180, 270) ' + angle;
  }
  return this;
};

/*
  Do not enlarge the output if the input width *or* height are already less than the required dimensions
  This is equivalent to GraphicsMagick's ">" geometry option:
    "change the dimensions of the image only if its width or height exceeds the geometry specification"
*/
Sharp.prototype.withoutEnlargement = function(withoutEnlargement) {
  this.options.withoutEnlargement = (typeof withoutEnlargement === 'boolean') ? withoutEnlargement : true;
  return this;
};

Sharp.prototype.sharpen = function(sharpen) {
  this.options.sharpen = (typeof sharpen === 'boolean') ? sharpen : true;
  return this;
};

Sharp.prototype.progressive = function(progressive) {
  this.options.progressive = (typeof progressive === 'boolean') ? progressive : true;
  return this;
};

Sharp.prototype.sequentialRead = function(sequentialRead) {
  this.options.sequentialRead = (typeof sequentialRead === 'boolean') ? sequentialRead : true;
  return this;
};

Sharp.prototype.quality = function(quality) {
  if (!Number.isNaN(quality) && quality >= 1 && quality <= 100) {
    this.options.quality = quality;
  } else {
    throw new Error('Invalid quality (1 to 100) ' + quality);
  }
  return this;
};

Sharp.prototype.compressionLevel = function(compressionLevel) {
  if (!Number.isNaN(compressionLevel) && compressionLevel >= -1 && compressionLevel <= 9) {
    this.options.compressionLevel = compressionLevel;
  } else {
    throw new Error('Invalid compressionLevel (-1 to 9) ' + compressionLevel);
  }
  return this;
};

Sharp.prototype.resize = function(width, height) {
  if (!width) {
    this.options.width = -1;
  } else {
    if (!Number.isNaN(width)) {
      this.options.width = width;
    } else {
      throw new Error('Invalid width ' + width);
    }
  }
  if (!height) {
    this.options.height = -1;
  } else {
    if (!Number.isNaN(height)) {
      this.options.height = height;
    } else {
      throw new Error('Invalid height ' + height);
    }
  }
  return this;
};

/*
  Write output image data to a file
*/
Sharp.prototype.toFile = function(output, callback) {
  if (!output || output.length === 0) {
    var err = new Error('Invalid output');
    if (typeof callback === 'function') {
      callback(err);
    } else {
      return Promise.reject(err);
    }
  } else {
    if (this.options.fileIn === output) {
      var err = new Error('Cannot use same file for input and output');
      if (typeof callback === 'function') {
        callback(err);
      } else {
        return Promise.reject(err);
      }
    } else {
      return this._sharp(output, callback);
{'fraction_non_alphanumeric': 0.1395830793612093, 'fraction_numerical': 0.012678288431061807, 'mean_word_length': 3.2729166666666667, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '2153004', 'n_tokens_mistral': 2663, 'n_tokens_neox': 2530, 'n_words': 716}