From ff50cfac6ae31e8683c73778b9f05d52369fb7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sat, 10 Feb 2024 16:13:19 +0100 Subject: [PATCH] chore: update dependencies --- package.json | 20 ++++++++--------- src/PngDecoder.ts | 8 +++---- src/PngEncoder.ts | 12 +++++++--- src/internalTypes.ts | 52 ++++++++++++++++++++++++++------------------ src/types.ts | 2 +- 5 files changed, 55 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index 406ad8b..6db8112 100644 --- a/package.json +++ b/package.json @@ -42,19 +42,19 @@ }, "homepage": "https://github.com/image-js/fast-png#readme", "devDependencies": { - "@types/jest": "^29.5.3", - "@types/node": "^20.4.2", - "eslint": "^8.45.0", - "eslint-config-cheminfo-typescript": "^11.3.1", - "jest": "^29.6.1", + "@types/jest": "^29.5.12", + "@types/node": "^20.11.17", + "eslint": "^8.56.0", + "eslint-config-cheminfo-typescript": "^12.1.0", + "jest": "^29.7.0", "pngjs": "^7.0.0", - "prettier": "^3.0.0", - "rimraf": "^5.0.1", - "ts-jest": "^29.1.1", - "typescript": "^5.1.6" + "prettier": "^3.2.5", + "rimraf": "^5.0.5", + "ts-jest": "^29.1.2", + "typescript": "^5.3.3" }, "dependencies": { - "@types/pako": "^2.0.0", + "@types/pako": "^2.0.3", "iobuffer": "^5.3.2", "pako": "^2.1.0" } diff --git a/src/PngDecoder.ts b/src/PngDecoder.ts index c059efb..6dab44a 100644 --- a/src/PngDecoder.ts +++ b/src/PngDecoder.ts @@ -152,7 +152,7 @@ export default class PngDecoder extends IOBuffer { image.height = this.readUint32(); image.depth = checkBitDepth(this.readUint8()); - const colorType: ColorType = this.readUint8(); + const colorType = this.readUint8() as ColorType; this._colorType = colorType; let channels: number; switch (colorType) { @@ -176,15 +176,15 @@ export default class PngDecoder extends IOBuffer { } this._png.channels = channels; - this._compressionMethod = this.readUint8(); + this._compressionMethod = this.readUint8() as CompressionMethod; if (this._compressionMethod !== CompressionMethod.DEFLATE) { throw new Error( `Unsupported compression method: ${this._compressionMethod}`, ); } - this._filterMethod = this.readUint8(); - this._interlaceMethod = this.readUint8(); + this._filterMethod = this.readUint8() as FilterMethod; + this._interlaceMethod = this.readUint8() as InterlaceMethod; } // https://www.w3.org/TR/PNG/#11PLTE diff --git a/src/PngEncoder.ts b/src/PngEncoder.ts index b5e5d67..fc1c7ec 100644 --- a/src/PngEncoder.ts +++ b/src/PngEncoder.ts @@ -146,11 +146,13 @@ function checkInteger(value: number, name: string): number { throw new TypeError(`${name} must be a positive integer`); } -function getColorType(data: ImageData): { +interface GetColorTypeReturn { channels: number; depth: BitDepth; colorType: ColorType; -} { +} + +function getColorType(data: ImageData): GetColorTypeReturn { const { channels = 4, depth = 8 } = data; if (channels !== 4 && channels !== 3 && channels !== 2 && channels !== 1) { throw new RangeError(`unsupported number of channels: ${channels}`); @@ -159,7 +161,11 @@ function getColorType(data: ImageData): { throw new RangeError(`unsupported bit depth: ${depth}`); } - const returnValue = { channels, depth, colorType: ColorType.UNKNOWN }; + const returnValue: GetColorTypeReturn = { + channels, + depth, + colorType: ColorType.UNKNOWN, + }; switch (channels) { case 4: returnValue.colorType = ColorType.TRUECOLOUR_ALPHA; diff --git a/src/internalTypes.ts b/src/internalTypes.ts index 91b96fa..543ef81 100644 --- a/src/internalTypes.ts +++ b/src/internalTypes.ts @@ -1,24 +1,34 @@ -export enum ColorType { - UNKNOWN = -1, - GREYSCALE = 0, - TRUECOLOUR = 2, - INDEXED_COLOUR = 3, - GREYSCALE_ALPHA = 4, - TRUECOLOUR_ALPHA = 6, -} +export const ColorType = { + UNKNOWN: -1, + GREYSCALE: 0, + TRUECOLOUR: 2, + INDEXED_COLOUR: 3, + GREYSCALE_ALPHA: 4, + TRUECOLOUR_ALPHA: 6, +} as const; +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type ColorType = (typeof ColorType)[keyof typeof ColorType]; -export enum CompressionMethod { - UNKNOWN = -1, - DEFLATE = 0, -} +export const CompressionMethod = { + UNKNOWN: -1, + DEFLATE: 0, +} as const; +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type CompressionMethod = + (typeof CompressionMethod)[keyof typeof CompressionMethod]; -export enum FilterMethod { - UNKNOWN = -1, - ADAPTIVE = 0, -} +export const FilterMethod = { + UNKNOWN: -1, + ADAPTIVE: 0, +} as const; +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type FilterMethod = (typeof FilterMethod)[keyof typeof FilterMethod]; -export enum InterlaceMethod { - UNKNOWN = -1, - NO_INTERLACE = 0, - ADAM7 = 1, -} +export const InterlaceMethod = { + UNKNOWN: -1, + NO_INTERLACE: 0, + ADAM7: 1, +} as const; +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type InterlaceMethod = + (typeof InterlaceMethod)[keyof typeof InterlaceMethod]; diff --git a/src/types.ts b/src/types.ts index d1ca61c..78f520f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -49,7 +49,7 @@ export interface DecodedPng { data: PngDataArray; depth: BitDepth; channels: number; - text: { [key: string]: string }; + text: Record; resolution?: PngResolution; palette?: IndexedColors; transparency?: Uint16Array;