diff --git a/docs/api-output.md b/docs/api-output.md index e13cdeab..2eb6feba 100644 --- a/docs/api-output.md +++ b/docs/api-output.md @@ -136,6 +136,8 @@ Use these TIFF options for output image. - `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** output options - `options.quality` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** quality, integer 1-100 (optional, default `80`) - `options.force` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** force TIFF output, otherwise attempt to use input format (optional, default `true`) + - `options.compression` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** compression options: lzw, deflate, jpeg (optional, default `'jpeg'`) + - `options.predictor` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** compression predictor options: none, horizontal, float (optional, default `'none'`) - Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid options diff --git a/docs/api-resize.md b/docs/api-resize.md index 89f2e1cb..fc7e7d72 100644 --- a/docs/api-resize.md +++ b/docs/api-resize.md @@ -17,6 +17,7 @@ By default, the resized image is centre cropped to the exact size specified. Possible reduction kernels are: +- `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation). - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline). - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`. - `lanczos3`: Use a Lanczos kernel with `a=3` (the default). diff --git a/lib/channel.js b/lib/channel.js index 88ffd5a4..8aee9b1a 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -27,7 +27,7 @@ const bool = { * @returns {Sharp} * @throws {Error} Invalid channel */ -const extractChannel = function extractChannel (channel) { +function extractChannel (channel) { if (channel === 'red') { channel = 0; } else if (channel === 'green') { @@ -41,7 +41,7 @@ const extractChannel = function extractChannel (channel) { throw new Error('Cannot extract invalid channel ' + channel); } return this; -}; +} /** * Join one or more channels to the image. @@ -59,7 +59,7 @@ const extractChannel = function extractChannel (channel) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const joinChannel = function joinChannel (images, options) { +function joinChannel (images, options) { if (Array.isArray(images)) { images.forEach(function (image) { this.options.joinChannelIn.push(this._createInputDescriptor(image, options)); @@ -68,7 +68,7 @@ const joinChannel = function joinChannel (images, options) { this.options.joinChannelIn.push(this._createInputDescriptor(images, options)); } return this; -}; +} /** * Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image. @@ -86,14 +86,14 @@ const joinChannel = function joinChannel (images, options) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const bandbool = function bandbool (boolOp) { +function bandbool (boolOp) { if (is.string(boolOp) && is.inArray(boolOp, ['and', 'or', 'eor'])) { this.options.bandBoolOp = boolOp; } else { throw new Error('Invalid bandbool operation ' + boolOp); } return this; -}; +} /** * Decorate the Sharp prototype with channel-related functions. diff --git a/lib/colour.js b/lib/colour.js index 5bf92b4c..e115946c 100644 --- a/lib/colour.js +++ b/lib/colour.js @@ -27,7 +27,7 @@ const colourspace = { * @returns {Sharp} * @throws {Error} Invalid parameter */ -const background = function background (rgba) { +function background (rgba) { const colour = color(rgba); this.options.background = [ colour.red(), @@ -36,7 +36,7 @@ const background = function background (rgba) { Math.round(colour.alpha() * 255) ]; return this; -}; +} /** * Convert to 8-bit greyscale; 256 shades of grey. @@ -48,19 +48,19 @@ const background = function background (rgba) { * @param {Boolean} [greyscale=true] * @returns {Sharp} */ -const greyscale = function greyscale (greyscale) { +function greyscale (greyscale) { this.options.greyscale = is.bool(greyscale) ? greyscale : true; return this; -}; +} /** * Alternative spelling of `greyscale`. * @param {Boolean} [grayscale=true] * @returns {Sharp} */ -const grayscale = function grayscale (grayscale) { +function grayscale (grayscale) { return this.greyscale(grayscale); -}; +} /** * Set the output colourspace. @@ -69,13 +69,13 @@ const grayscale = function grayscale (grayscale) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const toColourspace = function toColourspace (colourspace) { +function toColourspace (colourspace) { if (!is.string(colourspace)) { throw new Error('Invalid output colourspace ' + colourspace); } this.options.colourspace = colourspace; return this; -}; +} /** * Alternative spelling of `toColourspace`. @@ -83,9 +83,9 @@ const toColourspace = function toColourspace (colourspace) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const toColorspace = function toColorspace (colorspace) { +function toColorspace (colorspace) { return this.toColourspace(colorspace); -}; +} /** * Decorate the Sharp prototype with colour-related functions. diff --git a/lib/composite.js b/lib/composite.js index 39d503ee..6d2353e1 100644 --- a/lib/composite.js +++ b/lib/composite.js @@ -46,7 +46,7 @@ const is = require('./is'); * @returns {Sharp} * @throws {Error} Invalid parameters */ -const overlayWith = function overlayWith (overlay, options) { +function overlayWith (overlay, options) { this.options.overlay = this._createInputDescriptor(overlay, options, { allowStream: false }); @@ -87,7 +87,7 @@ const overlayWith = function overlayWith (overlay, options) { } } return this; -}; +} /** * Decorate the Sharp prototype with composite-related functions. diff --git a/lib/input.js b/lib/input.js index 36e94fb2..fd1e4fe9 100644 --- a/lib/input.js +++ b/lib/input.js @@ -9,7 +9,7 @@ const sharp = require('../build/Release/sharp.node'); * Create Object containing input and input-related options. * @private */ -const _createInputDescriptor = function _createInputDescriptor (input, inputOptions, containerOptions) { +function _createInputDescriptor (input, inputOptions, containerOptions) { const inputDescriptor = {}; if (is.string(input)) { // filesystem @@ -75,7 +75,7 @@ const _createInputDescriptor = function _createInputDescriptor (input, inputOpti throw new Error('Invalid input options ' + inputOptions); } return inputDescriptor; -}; +} /** * Handle incoming Buffer chunk on Writable Stream. @@ -84,7 +84,7 @@ const _createInputDescriptor = function _createInputDescriptor (input, inputOpti * @param {String} encoding - unused * @param {Function} callback */ -const _write = function _write (chunk, encoding, callback) { +function _write (chunk, encoding, callback) { /* istanbul ignore else */ if (Array.isArray(this.options.input.buffer)) { /* istanbul ignore else */ @@ -103,26 +103,26 @@ const _write = function _write (chunk, encoding, callback) { } else { callback(new Error('Unexpected data on Writable Stream')); } -}; +} /** * Flattens the array of chunks accumulated in input.buffer. * @private */ -const _flattenBufferIn = function _flattenBufferIn () { +function _flattenBufferIn () { if (this._isStreamInput()) { this.options.input.buffer = Buffer.concat(this.options.input.buffer); } -}; +} /** * Are we expecting Stream-based input? * @private * @returns {Boolean} */ -const _isStreamInput = function _isStreamInput () { +function _isStreamInput () { return Array.isArray(this.options.input.buffer); -}; +} /** * Take a "snapshot" of the Sharp instance, returning a new instance. @@ -139,7 +139,7 @@ const _isStreamInput = function _isStreamInput () { * * @returns {Sharp} */ -const clone = function clone () { +function clone () { const that = this; // Clone existing options const clone = this.constructor.call(); @@ -152,7 +152,7 @@ const clone = function clone () { clone.emit('finish'); }); return clone; -}; +} /** * Fast access to image metadata without decoding any compressed image data. @@ -187,7 +187,7 @@ const clone = function clone () { * @param {Function} [callback] - called with the arguments `(err, metadata)` * @returns {Promise|Sharp} */ -const metadata = function metadata (callback) { +function metadata (callback) { const that = this; if (is.fn(callback)) { if (this._isStreamInput()) { @@ -225,7 +225,7 @@ const metadata = function metadata (callback) { }); } } -}; +} /** * Do not process input images where the number of pixels (width * height) exceeds this limit. @@ -235,7 +235,7 @@ const metadata = function metadata (callback) { * @returns {Sharp} * @throws {Error} Invalid limit */ -const limitInputPixels = function limitInputPixels (limit) { +function limitInputPixels (limit) { // if we pass in false we represent the integer as 0 to disable if (limit === false) { limit = 0; @@ -248,7 +248,7 @@ const limitInputPixels = function limitInputPixels (limit) { throw new Error('Invalid pixel limit (0 to ' + this.constructor.maximum.pixels + ') ' + limit); } return this; -}; +} /** * An advanced setting that switches the libvips access method to `VIPS_ACCESS_SEQUENTIAL`. @@ -256,10 +256,10 @@ const limitInputPixels = function limitInputPixels (limit) { * @param {Boolean} [sequentialRead=true] * @returns {Sharp} */ -const sequentialRead = function sequentialRead (sequentialRead) { +function sequentialRead (sequentialRead) { this.options.sequentialRead = is.bool(sequentialRead) ? sequentialRead : true; return this; -}; +} /** * Decorate the Sharp prototype with input-related functions. diff --git a/lib/operation.js b/lib/operation.js index c86b382c..6297d0d7 100644 --- a/lib/operation.js +++ b/lib/operation.js @@ -29,7 +29,7 @@ const is = require('./is'); * @returns {Sharp} * @throws {Error} Invalid parameters */ -const rotate = function rotate (angle) { +function rotate (angle) { if (!is.defined(angle)) { this.options.angle = -1; } else if (is.integer(angle) && is.inArray(angle, [0, 90, 180, 270])) { @@ -38,7 +38,7 @@ const rotate = function rotate (angle) { throw new Error('Unsupported angle (0, 90, 180, 270) ' + angle); } return this; -}; +} /** * Extract a region of the image. @@ -70,7 +70,7 @@ const rotate = function rotate (angle) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const extract = function extract (options) { +function extract (options) { const suffix = this.options.width === -1 && this.options.height === -1 ? 'Pre' : 'Post'; ['left', 'top', 'width', 'height'].forEach(function (name) { const value = options[name]; @@ -85,7 +85,7 @@ const extract = function extract (options) { this.options.rotateBeforePreExtract = true; } return this; -}; +} /** * Flip the image about the vertical Y axis. This always occurs after rotation, if any. @@ -93,10 +93,10 @@ const extract = function extract (options) { * @param {Boolean} [flip=true] * @returns {Sharp} */ -const flip = function flip (flip) { +function flip (flip) { this.options.flip = is.bool(flip) ? flip : true; return this; -}; +} /** * Flop the image about the horizontal X axis. This always occurs after rotation, if any. @@ -104,10 +104,10 @@ const flip = function flip (flip) { * @param {Boolean} [flop=true] * @returns {Sharp} */ -const flop = function flop (flop) { +function flop (flop) { this.options.flop = is.bool(flop) ? flop : true; return this; -}; +} /** * Sharpen the image. @@ -121,7 +121,7 @@ const flop = function flop (flop) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const sharpen = function sharpen (sigma, flat, jagged) { +function sharpen (sigma, flat, jagged) { if (!is.defined(sigma)) { // No arguments: default to mild sharpen this.options.sharpenSigma = -1; @@ -151,7 +151,7 @@ const sharpen = function sharpen (sigma, flat, jagged) { throw new Error('Invalid sharpen sigma (0.01 - 10000) ' + sigma); } return this; -}; +} /** * Blur the image. @@ -161,7 +161,7 @@ const sharpen = function sharpen (sigma, flat, jagged) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const blur = function blur (sigma) { +function blur (sigma) { if (!is.defined(sigma)) { // No arguments: default to mild blur this.options.blurSigma = -1; @@ -175,7 +175,7 @@ const blur = function blur (sigma) { throw new Error('Invalid blur sigma (0.3 - 1000.0) ' + sigma); } return this; -}; +} /** * Extends/pads the edges of the image with the colour provided to the `background` method. @@ -198,7 +198,7 @@ const blur = function blur (sigma) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const extend = function extend (extend) { +function extend (extend) { if (is.integer(extend) && extend > 0) { this.options.extendTop = extend; this.options.extendBottom = extend; @@ -219,17 +219,17 @@ const extend = function extend (extend) { throw new Error('Invalid edge extension ' + extend); } return this; -}; +} /** * Merge alpha transparency channel, if any, with `background`. * @param {Boolean} [flatten=true] * @returns {Sharp} */ -const flatten = function flatten (flatten) { +function flatten (flatten) { this.options.flatten = is.bool(flatten) ? flatten : true; return this; -}; +} /** * Trim "boring" pixels from all edges that contain values within a percentage similarity of the top-left pixel. @@ -237,7 +237,7 @@ const flatten = function flatten (flatten) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const trim = function trim (tolerance) { +function trim (tolerance) { if (!is.defined(tolerance)) { this.options.trimTolerance = 10; } else if (is.integer(tolerance) && is.inRange(tolerance, 1, 99)) { @@ -246,7 +246,7 @@ const trim = function trim (tolerance) { throw new Error('Invalid trim tolerance (1 to 99) ' + tolerance); } return this; -}; +} /** * Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of `1/gamma` @@ -258,7 +258,7 @@ const trim = function trim (tolerance) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const gamma = function gamma (gamma) { +function gamma (gamma) { if (!is.defined(gamma)) { // Default gamma correction of 2.2 (sRGB) this.options.gamma = 2.2; @@ -268,36 +268,36 @@ const gamma = function gamma (gamma) { throw new Error('Invalid gamma correction (1.0 to 3.0) ' + gamma); } return this; -}; +} /** * Produce the "negative" of the image. * @param {Boolean} [negate=true] * @returns {Sharp} */ -const negate = function negate (negate) { +function negate (negate) { this.options.negate = is.bool(negate) ? negate : true; return this; -}; +} /** * Enhance output image contrast by stretching its luminance to cover the full dynamic range. * @param {Boolean} [normalise=true] * @returns {Sharp} */ -const normalise = function normalise (normalise) { +function normalise (normalise) { this.options.normalise = is.bool(normalise) ? normalise : true; return this; -}; +} /** * Alternative spelling of normalise. * @param {Boolean} [normalize=true] * @returns {Sharp} */ -const normalize = function normalize (normalize) { +function normalize (normalize) { return this.normalise(normalize); -}; +} /** * Convolve the image with the specified kernel. @@ -324,7 +324,7 @@ const normalize = function normalize (normalize) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const convolve = function convolve (kernel) { +function convolve (kernel) { if (!is.object(kernel) || !Array.isArray(kernel.kernel) || !is.integer(kernel.width) || !is.integer(kernel.height) || !is.inRange(kernel.width, 3, 1001) || !is.inRange(kernel.height, 3, 1001) || @@ -348,7 +348,7 @@ const convolve = function convolve (kernel) { } this.options.convKernel = kernel; return this; -}; +} /** * Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0. @@ -359,7 +359,7 @@ const convolve = function convolve (kernel) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const threshold = function threshold (threshold, options) { +function threshold (threshold, options) { if (!is.defined(threshold)) { this.options.threshold = 128; } else if (is.bool(threshold)) { @@ -375,7 +375,7 @@ const threshold = function threshold (threshold, options) { this.options.thresholdGrayscale = false; } return this; -}; +} /** * Perform a bitwise boolean operation with operand image. @@ -393,7 +393,7 @@ const threshold = function threshold (threshold, options) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const boolean = function boolean (operand, operator, options) { +function boolean (operand, operator, options) { this.options.boolean = this._createInputDescriptor(operand, options); if (is.string(operator) && is.inArray(operator, ['and', 'or', 'eor'])) { this.options.booleanOp = operator; @@ -401,7 +401,7 @@ const boolean = function boolean (operand, operator, options) { throw new Error('Invalid boolean operator ' + operator); } return this; -}; +} /** * Decorate the Sharp prototype with operation-related functions. diff --git a/lib/output.js b/lib/output.js index 2e63f53f..d464c48b 100644 --- a/lib/output.js +++ b/lib/output.js @@ -19,7 +19,7 @@ const sharp = require('../build/Release/sharp.node'); * @returns {Promise} - when no callback is provided * @throws {Error} Invalid parameters */ -const toFile = function toFile (fileOut, callback) { +function toFile (fileOut, callback) { if (!fileOut || fileOut.length === 0) { const errOutputInvalid = new Error('Invalid output'); if (is.fn(callback)) { @@ -41,7 +41,7 @@ const toFile = function toFile (fileOut, callback) { } } return this; -}; +} /** * Write output to a Buffer. @@ -59,14 +59,14 @@ const toFile = function toFile (fileOut, callback) { * @param {Function} [callback] * @returns {Promise} - when no callback is provided */ -const toBuffer = function toBuffer (options, callback) { +function toBuffer (options, callback) { if (is.object(options)) { if (is.bool(options.resolveWithObject)) { this.options.resolveWithObject = options.resolveWithObject; } } return this._pipeline(is.fn(options) ? options : callback); -}; +} /** * Include all metadata (EXIF, XMP, IPTC) from the input image in the output image. @@ -77,7 +77,7 @@ const toBuffer = function toBuffer (options, callback) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const withMetadata = function withMetadata (withMetadata) { +function withMetadata (withMetadata) { this.options.withMetadata = is.bool(withMetadata) ? withMetadata : true; if (is.object(withMetadata)) { if (is.defined(withMetadata.orientation)) { @@ -89,7 +89,7 @@ const withMetadata = function withMetadata (withMetadata) { } } return this; -}; +} /** * Use these JPEG options for output image. @@ -105,7 +105,7 @@ const withMetadata = function withMetadata (withMetadata) { * @returns {Sharp} * @throws {Error} Invalid options */ -const jpeg = function jpeg (options) { +function jpeg (options) { if (is.object(options)) { if (is.defined(options.quality)) { if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) { @@ -140,7 +140,7 @@ const jpeg = function jpeg (options) { } } return this._updateFormatOut('jpeg', options); -}; +} /** * Use these PNG options for output image. @@ -152,7 +152,7 @@ const jpeg = function jpeg (options) { * @returns {Sharp} * @throws {Error} Invalid options */ -const png = function png (options) { +function png (options) { if (is.object(options)) { if (is.defined(options.progressive)) { this._setBooleanOption('pngProgressive', options.progressive); @@ -169,7 +169,7 @@ const png = function png (options) { } } return this._updateFormatOut('png', options); -}; +} /** * Use these WebP options for output image. @@ -182,7 +182,7 @@ const png = function png (options) { * @returns {Sharp} * @throws {Error} Invalid options */ -const webp = function webp (options) { +function webp (options) { if (is.object(options) && is.defined(options.quality)) { if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) { this.options.webpQuality = options.quality; @@ -204,7 +204,7 @@ const webp = function webp (options) { this._setBooleanOption('webpNearLossless', options.nearLossless); } return this._updateFormatOut('webp', options); -}; +} /** * Use these TIFF options for output image. @@ -216,7 +216,7 @@ const webp = function webp (options) { * @returns {Sharp} * @throws {Error} Invalid options */ -const tiff = function tiff (options) { +function tiff (options) { if (is.object(options) && is.defined(options.quality)) { if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) { this.options.tiffQuality = options.quality; @@ -243,15 +243,15 @@ const tiff = function tiff (options) { } } return this._updateFormatOut('tiff', options); -}; +} /** * Force output to be raw, uncompressed uint8 pixel data. * @returns {Sharp} */ -const raw = function raw () { +function raw () { return this._updateFormatOut('raw'); -}; +} /** * Force output to a given format. @@ -260,7 +260,7 @@ const raw = function raw () { * @returns {Sharp} * @throws {Error} unsupported format or options */ -const toFormat = function toFormat (format, options) { +function toFormat (format, options) { if (is.object(format) && is.string(format.id)) { format = format.id; } @@ -268,7 +268,7 @@ const toFormat = function toFormat (format, options) { throw new Error('Unsupported output format ' + format); } return this[format](options); -}; +} /** * Use tile-based deep zoom (image pyramid) output. @@ -294,7 +294,7 @@ const toFormat = function toFormat (format, options) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const tile = function tile (tile) { +function tile (tile) { if (is.object(tile)) { // Size of square tiles, in pixels if (is.defined(tile.size)) { @@ -339,7 +339,7 @@ const tile = function tile (tile) { throw new Error('Invalid tile format ' + this.options.formatOut); } return this._updateFormatOut('dz'); -}; +} /** * Update the output format unless options.force is false, @@ -350,10 +350,10 @@ const tile = function tile (tile) { * @param {Boolean} [options.force=true] - force output format, otherwise attempt to use input format * @returns {Sharp} */ -const _updateFormatOut = function _updateFormatOut (formatOut, options) { +function _updateFormatOut (formatOut, options) { this.options.formatOut = (is.object(options) && options.force === false) ? 'input' : formatOut; return this; -}; +} /** * Update a Boolean attribute of the this.options Object. @@ -362,31 +362,31 @@ const _updateFormatOut = function _updateFormatOut (formatOut, options) { * @param {Boolean} val * @throws {Error} Invalid key */ -const _setBooleanOption = function _setBooleanOption (key, val) { +function _setBooleanOption (key, val) { if (is.bool(val)) { this.options[key] = val; } else { throw new Error('Invalid ' + key + ' (boolean) ' + val); } -}; +} /** * Called by a WriteableStream to notify us it is ready for data. * @private */ -const _read = function _read () { +function _read () { if (!this.options.streamOut) { this.options.streamOut = true; this._pipeline(); } -}; +} /** * Invoke the C++ image processing pipeline * Supports callback, stream and promise variants * @private */ -const _pipeline = function _pipeline (callback) { +function _pipeline (callback) { const that = this; if (typeof callback === 'function') { // output=file/buffer @@ -480,7 +480,7 @@ const _pipeline = function _pipeline (callback) { }); } } -}; +} // Deprecated output options /* istanbul ignore next */ diff --git a/lib/resize.js b/lib/resize.js index b5337d30..3ccc6743 100644 --- a/lib/resize.js +++ b/lib/resize.js @@ -101,7 +101,7 @@ const interpolator = { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const resize = function resize (width, height, options) { +function resize (width, height, options) { if (is.defined(width)) { if (is.integer(width) && is.inRange(width, 1, this.constructor.maximum.width)) { this.options.width = width; @@ -144,7 +144,7 @@ const resize = function resize (width, height, options) { } } return this; -}; +} /** * Crop the resized image to the exact size specified, the default behaviour. @@ -172,7 +172,7 @@ const resize = function resize (width, height, options) { * @returns {Sharp} * @throws {Error} Invalid parameters */ -const crop = function crop (crop) { +function crop (crop) { this.options.canvas = 'crop'; if (!is.defined(crop)) { // Default @@ -193,7 +193,7 @@ const crop = function crop (crop) { throw is.invalidParameterError('crop', 'valid crop id/name/strategy', crop); } return this; -}; +} /** * Preserving aspect ratio, resize the image to the maximum `width` or `height` specified @@ -218,10 +218,10 @@ const crop = function crop (crop) { * * @returns {Sharp} */ -const embed = function embed () { +function embed () { this.options.canvas = 'embed'; return this; -}; +} /** * Preserving aspect ratio, resize the image to be as large as possible @@ -242,10 +242,10 @@ const embed = function embed () { * * @returns {Sharp} */ -const max = function max () { +function max () { this.options.canvas = 'max'; return this; -}; +} /** * Preserving aspect ratio, resize the image to be as small as possible @@ -255,20 +255,20 @@ const max = function max () { * * @returns {Sharp} */ -const min = function min () { +function min () { this.options.canvas = 'min'; return this; -}; +} /** * Ignoring the aspect ratio of the input, stretch the image to * the exact `width` and/or `height` provided via `resize`. * @returns {Sharp} */ -const ignoreAspectRatio = function ignoreAspectRatio () { +function ignoreAspectRatio () { this.options.canvas = 'ignore_aspect'; return this; -}; +} /** * Do not enlarge the output image if the input image width *or* height are already less than the required dimensions. @@ -277,10 +277,10 @@ const ignoreAspectRatio = function ignoreAspectRatio () { * @param {Boolean} [withoutEnlargement=true] * @returns {Sharp} */ -const withoutEnlargement = function withoutEnlargement (withoutEnlargement) { +function withoutEnlargement (withoutEnlargement) { this.options.withoutEnlargement = is.bool(withoutEnlargement) ? withoutEnlargement : true; return this; -}; +} /** * Decorate the Sharp prototype with resize-related functions. diff --git a/lib/utility.js b/lib/utility.js index f47d5c52..67aaafa8 100644 --- a/lib/utility.js +++ b/lib/utility.js @@ -22,7 +22,7 @@ const sharp = require('../build/Release/sharp.node'); * @param {Number} [options.items=100] - is the maximum number of operations to cache * @returns {Object} */ -const cache = function cache (options) { +function cache (options) { if (is.bool(options)) { if (options) { // Default cache settings of 50MB, 20 files, 100 items @@ -35,7 +35,7 @@ const cache = function cache (options) { } else { return sharp.cache(); } -}; +} cache(true); /** @@ -57,9 +57,9 @@ cache(true); * @param {Number} [concurrency] * @returns {Number} concurrency */ -const concurrency = function concurrency (concurrency) { +function concurrency (concurrency) { return sharp.concurrency(is.integer(concurrency) ? concurrency : null); -}; +} /** * Provides access to internal task counters. @@ -71,9 +71,9 @@ const concurrency = function concurrency (concurrency) { * * @returns {Object} */ -const counters = function counters () { +function counters () { return sharp.counters(); -}; +} /** * Get and set use of SIMD vector unit instructions. @@ -95,9 +95,9 @@ const counters = function counters () { * @param {Boolean} [simd=false] * @returns {Boolean} */ -const simd = function simd (simd) { +function simd (simd) { return sharp.simd(is.bool(simd) ? simd : null); -}; +} simd(false); /** diff --git a/package.json b/package.json index 84a6f3a1..2067f1f2 100644 --- a/package.json +++ b/package.json @@ -72,17 +72,17 @@ "tar": "^2.2.1" }, "devDependencies": { - "async": "^2.1.4", + "async": "^2.2.0", "bufferutil": "^3.0.0", "cc": "^1.0.0", - "cross-env": "^3.2.3", + "cross-env": "^4.0.0", "documentation": "^4.0.0-beta.18", "exif-reader": "^1.0.2", "icc": "^1.0.0", "mocha": "^3.2.0", - "nyc": "^10.1.2", + "nyc": "^10.2.0", "rimraf": "^2.5.4", - "semistandard": "^9.2.1", + "semistandard": "^10.0.0", "unzip": "^0.1.11" }, "license": "Apache-2.0", diff --git a/test/bench/random.js b/test/bench/random.js index 23d668bd..426cd0a1 100644 --- a/test/bench/random.js +++ b/test/bench/random.js @@ -15,7 +15,7 @@ const min = 320; const max = 960; const randomDimension = function () { - return Math.ceil(Math.random() * (max - min) + min); + return Math.ceil((Math.random() * (max - min)) + min); }; new Benchmark.Suite('random').add('imagemagick', { diff --git a/test/fixtures/index.js b/test/fixtures/index.js index 8467fc0d..eee48a16 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -25,8 +25,8 @@ const fingerprint = function (image, callback) { let fingerprint = ''; for (let col = 0; col < 8; col++) { for (let row = 0; row < 8; row++) { - const left = data[row * 8 + col]; - const right = data[row * 8 + col + 1]; + const left = data[(row * 8) + col]; + const right = data[(row * 8) + col + 1]; fingerprint = fingerprint + (left < right ? '1' : '0'); } } diff --git a/test/unit/io.js b/test/unit/io.js index 2a31d5a9..fe211f19 100644 --- a/test/unit/io.js +++ b/test/unit/io.js @@ -1168,7 +1168,7 @@ describe('Input/output', function () { sharp(fixtures.inputJpg).metadata(function (err, metadata) { if (err) throw err; sharp(fixtures.inputJpg) - .limitInputPixels(metadata.width * metadata.height - 1) + .limitInputPixels((metadata.width * metadata.height) - 1) .toBuffer(function (err) { assert.strictEqual(true, !!err); done(); diff --git a/test/unit/tile.js b/test/unit/tile.js index c829ce08..7af2736e 100644 --- a/test/unit/tile.js +++ b/test/unit/tile.js @@ -187,7 +187,7 @@ describe('Tile', function () { assert.strictEqual(2225, info.height); assert.strictEqual(3, info.channels); assert.strictEqual('undefined', typeof info.size); - assertDeepZoomTiles(directory, 512 + 2 * 16, 13, done); + assertDeepZoomTiles(directory, 512 + (2 * 16), 13, done); }); }); });