lib/output.js
function toFormat (format, options) {
  if (is.object(format) && is.string(format.id)) {
    format = format.id;
  }
  if (format === 'jpg') format = 'jpeg';
  if (!is.inArray(format, ['jpeg', 'png', 'webp', 'tiff', 'raw'])) {
    throw new Error('Unsupported output format ' + format);
  }
  return this[format](options);
}
function toFormat (format, options) {
  if (is.object(format) && is.string(format.id)) {
    format = format.id;
  }
  if (format === 'jpg') format = 'jpeg';
  if (!is.inArray(format, ['jpeg', 'png', 'webp', 'tiff', 'raw'])) {
    throw new Error('Unsupported output format ' + format);
  }
  return this[format](options);
}
function toFormat ( format , options ) { if ( is . object ( format ) && is . string ( format . id ) ) { format = format . id ; } if ( format === 'jpg' ) format = 'jpeg' ; if ( ! is . inArray ( format , [ 'jpeg' , 'png' , 'webp' , 'tiff' , 'raw' ] ) ) { throw new Error ( 'Unsupported output format ' + format ) ; } return this [ format ] ( options ) ; }
Force output to a given format.

@example
// Convert any input to PNG output
const data = await sharp(input)
.toFormat('png')
.toBuffer();

@param {(String|Object)} format - as a String or an Object with an 'id' attribute
@param {Object} options - output options
@returns {Sharp}
@throws {Error} unsupported format or options
Force output to a given format .