TypeScript: Ensure 'FormatEnum' keys match reality #4475

Renames format.jp2k as format.jp2 for consistency
This commit is contained in:
Lovell Fuller
2026-01-02 08:04:46 +00:00
parent 006d37b2d0
commit d161e45e06
7 changed files with 47 additions and 15 deletions

8
lib/index.d.ts vendored
View File

@@ -840,7 +840,7 @@ declare namespace sharp {
* @returns A sharp instance that can be used to chain operations
*/
toFormat(
format: keyof FormatEnum | AvailableFormatInfo,
format: keyof FormatEnum | AvailableFormatInfo | "avif",
options?:
| OutputOptions
| JpegOptions
@@ -1911,16 +1911,13 @@ declare namespace sharp {
}
interface FormatEnum {
avif: AvailableFormatInfo;
dcraw: AvailableFormatInfo;
dz: AvailableFormatInfo;
exr: AvailableFormatInfo;
fits: AvailableFormatInfo;
gif: AvailableFormatInfo;
heif: AvailableFormatInfo;
input: AvailableFormatInfo;
jpeg: AvailableFormatInfo;
jpg: AvailableFormatInfo;
jp2: AvailableFormatInfo;
jxl: AvailableFormatInfo;
magick: AvailableFormatInfo;
@@ -1932,8 +1929,7 @@ declare namespace sharp {
raw: AvailableFormatInfo;
svg: AvailableFormatInfo;
tiff: AvailableFormatInfo;
tif: AvailableFormatInfo;
v: AvailableFormatInfo;
vips: AvailableFormatInfo;
webp: AvailableFormatInfo;
}

View File

@@ -76,7 +76,7 @@ function toFile (fileOut, callback) {
err = new Error('Missing output file path');
} else if (is.string(this.options.input.file) && path.resolve(this.options.input.file) === path.resolve(fileOut)) {
err = new Error('Cannot use same file for input and output');
} else if (jp2Regex.test(path.extname(fileOut)) && !this.constructor.format.jp2k.output.file) {
} else if (jp2Regex.test(path.extname(fileOut)) && !this.constructor.format.jp2.output.file) {
err = errJp2Save();
}
if (err) {
@@ -950,7 +950,7 @@ function gif (options) {
*/
function jp2 (options) {
/* node:coverage ignore next 41 */
if (!this.constructor.format.jp2k.output.buffer) {
if (!this.constructor.format.jp2.output.buffer) {
throw errJp2Save();
}
if (is.object(options)) {

View File

@@ -24,7 +24,7 @@ const format = sharp.format();
format.heif.output.alias = ['avif', 'heic'];
format.jpeg.output.alias = ['jpe', 'jpg'];
format.tiff.output.alias = ['tif'];
format.jp2k.output.alias = ['j2c', 'j2k', 'jp2', 'jpx'];
format.jp2.output.alias = ['j2c', 'j2k', 'jp2', 'jpx'];
/**
* An Object containing the available interpolators and their proper values