mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Update dev deps, deconstify all the functions, API doc refresh
This commit is contained in:
@@ -19,7 +19,7 @@ const sharp = require('../build/Release/sharp.node');
|
||||
* @returns {Promise<Object>} - 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<Buffer>} - 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 */
|
||||
|
||||
Reference in New Issue
Block a user