Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies and workflows #49

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 5 additions & 36 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,9 @@ on:
- main
pull_request:

env:
NODE_VERSION: 16.x

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: npm install
- name: Run ESLint
run: npm run eslint
- name: Run Prettier
run: npm run prettier
- name: Check types
run: npm run check-types
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test-only
- name: Send coverage report to Codecov
uses: codecov/codecov-action@v2
nodejs:
# Documentation: https://github.com/zakodium/workflows#nodejs-ci
uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1
with:
lint-check-types: true
37 changes: 8 additions & 29 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,12 @@ on:
branches:
- main

env:
NODE_VERSION: 16.x

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- name: Get package name
run: echo "PACKAGE_NAME=$(jq .name package.json | tr -d '"')" >> $GITHUB_ENV
- uses: GoogleCloudPlatform/release-please-action@v2
id: release
with:
token: ${{ secrets.BOT_TOKEN }}
release-type: node
package-name: ${{ env.PACKAGE_NAME }}
bump-minor-pre-major: Yes
- uses: actions/checkout@v2
# These if statements ensure that a publication only occurs when a new release is created
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}
- run: npm install
if: ${{ steps.release.outputs.release_created }}
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_BOT_TOKEN }}
if: ${{ steps.release.outputs.release_created }}
release:
# Documentation: https://github.com/zakodium/workflows#release
uses: zakodium/workflows/.github/workflows/release.yml@release-v1
with:
npm: true
secrets:
github-token: ${{ secrets.BOT_TOKEN }}
npm-token: ${{ secrets.NPM_BOT_TOKEN }}
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
"testEnvironment": "node"
},
"dependencies": {
"iobuffer": "^5.0.4",
"pako": "^2.0.4"
"iobuffer": "^5.3.2",
"pako": "^2.1.0"
},
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/node": "^16.11.11",
"@types/pako": "^1.0.2",
"eslint": "^8.3.0",
"eslint-config-cheminfo-typescript": "^10.2.4",
"jest": "^27.4.3",
"prettier": "^2.5.0",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.7",
"typescript": "^4.5.2"
"@types/jest": "^29.5.11",
"@types/node": "^20.10.5",
"@types/pako": "^2.0.3",
"eslint": "^8.56.0",
"eslint-config-cheminfo-typescript": "^12.1.0",
"jest": "^29.7.0",
"prettier": "^3.1.1",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3"
},
"prettier": {
"arrowParens": "always",
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/decode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ test.each(cases)('should decode %s', (name, file, image) => {
expect(components).toBe(file.components);
expect(bitsPerSample).toBe(file.bitsPerSample);
expect(data).toHaveLength(file.width * file.height * file.components);
expect(alpha).toBe(file.alpha ? true : false);
expect(alpha).toBe(Boolean(file.alpha));
});

// prettier-ignore
Expand Down Expand Up @@ -239,7 +239,7 @@ test('should read exif data', () => {
pages: [0],
ignoreImageData: true,
});
// @ts-ignore
// @ts-expect-error We know exif is defined.
expect(result[0].exif.map).toStrictEqual({
ColorSpace: 65535,
PixelXDimension: 30,
Expand Down Expand Up @@ -282,7 +282,7 @@ test('should decode palette', () => {
expect(decoded).toHaveLength(1);
const { palette } = decoded[0];
expect(palette).toHaveLength(256);
// @ts-ignore
// @ts-expect-error We know palette is defined.
expect(palette[0]).toStrictEqual([65535, 0, 0]);
});

Expand Down
2 changes: 1 addition & 1 deletion src/ifd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
export default class IFD {
public kind: IFDKind;
public data: DataArray;
public fields: Map<number, any>;

Check warning on line 15 in src/ifd.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type
public exif: IFD | undefined;
public gps: IFD | undefined;

private _hasMap: boolean;
private _map: any;

Check warning on line 20 in src/ifd.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type

public constructor(kind: IFDKind) {
if (!kind) {
Expand All @@ -30,7 +30,7 @@
this._map = {};
}

public get(tag: number | string): any {

Check warning on line 33 in src/ifd.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type
if (typeof tag === 'number') {
return this.fields.get(tag);
} else if (typeof tag === 'string') {
Expand All @@ -40,10 +40,10 @@
}
}

public get map(): Record<string, any> {

Check warning on line 43 in src/ifd.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type
if (!this._hasMap) {
const taglist = tags[this.kind].tagsById;
for (let key of this.fields.keys()) {
for (const key of this.fields.keys()) {
if (taglist[key]) {
this._map[taglist[key]] = this.fields.get(key);
}
Expand Down
26 changes: 13 additions & 13 deletions src/ifdValue.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import TIFFDecoder from './tiffDecoder';

let types = new Map<
const types = new Map<
number,
[number, (decoder: TIFFDecoder, count: number) => any]

Check warning on line 5 in src/ifdValue.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type
>([
[1, [1, readByte]], // BYTE
[2, [1, readASCII]], // ASCII
Expand All @@ -28,7 +28,7 @@
decoder: TIFFDecoder,
type: number,
count: number,
): any {

Check warning on line 31 in src/ifdValue.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type
const val = types.get(type);
if (!val) throw new Error(`type not found: ${type}`);
return val[1](decoder, count);
Expand All @@ -36,18 +36,18 @@

function readByte(decoder: TIFFDecoder, count: number): number | Uint8Array {
if (count === 1) return decoder.readUint8();
let array = new Uint8Array(count);
const array = new Uint8Array(count);
for (let i = 0; i < count; i++) {
array[i] = decoder.readUint8();
}
return array;
}

function readASCII(decoder: TIFFDecoder, count: number): string | string[] {
let strings = [];
const strings = [];
let currentString = '';
for (let i = 0; i < count; i++) {
let char = String.fromCharCode(decoder.readUint8());
const char = String.fromCharCode(decoder.readUint8());
if (char === '\0') {
strings.push(currentString);
currentString = '';
Expand All @@ -64,7 +64,7 @@

function readShort(decoder: TIFFDecoder, count: number): number | Uint16Array {
if (count === 1) return decoder.readUint16();
let array = new Uint16Array(count);
const array = new Uint16Array(count);
for (let i = 0; i < count; i++) {
array[i] = decoder.readUint16();
}
Expand All @@ -73,7 +73,7 @@

function readLong(decoder: TIFFDecoder, count: number): number | Uint32Array {
if (count === 1) return decoder.readUint32();
let array = new Uint32Array(count);
const array = new Uint32Array(count);
for (let i = 0; i < count; i++) {
array[i] = decoder.readUint32();
}
Expand All @@ -84,7 +84,7 @@
if (count === 1) {
return decoder.readUint32() / decoder.readUint32();
}
let rationals = new Array(count);
const rationals = new Array(count);
for (let i = 0; i < count; i++) {
rationals[i] = decoder.readUint32() / decoder.readUint32();
}
Expand All @@ -93,7 +93,7 @@

function readSByte(decoder: TIFFDecoder, count: number): number | Int8Array {
if (count === 1) return decoder.readInt8();
let array = new Int8Array(count);
const array = new Int8Array(count);

Check warning on line 96 in src/ifdValue.ts

View check run for this annotation

Codecov / codecov/patch

src/ifdValue.ts#L96

Added line #L96 was not covered by tests
for (let i = 0; i < count; i++) {
array[i] = decoder.readInt8();
}
Expand All @@ -102,7 +102,7 @@

function readSShort(decoder: TIFFDecoder, count: number): number | Int16Array {
if (count === 1) return decoder.readInt16();
let array = new Int16Array(count);
const array = new Int16Array(count);

Check warning on line 105 in src/ifdValue.ts

View check run for this annotation

Codecov / codecov/patch

src/ifdValue.ts#L105

Added line #L105 was not covered by tests
for (let i = 0; i < count; i++) {
array[i] = decoder.readInt16();
}
Expand All @@ -111,7 +111,7 @@

function readSLong(decoder: TIFFDecoder, count: number): number | Int32Array {
if (count === 1) return decoder.readInt32();
let array = new Int32Array(count);
const array = new Int32Array(count);

Check warning on line 114 in src/ifdValue.ts

View check run for this annotation

Codecov / codecov/patch

src/ifdValue.ts#L114

Added line #L114 was not covered by tests
for (let i = 0; i < count; i++) {
array[i] = decoder.readInt32();
}
Expand All @@ -122,7 +122,7 @@
if (count === 1) {
return decoder.readInt32() / decoder.readInt32();
}
let rationals = new Array(count);
const rationals = new Array(count);

Check warning on line 125 in src/ifdValue.ts

View check run for this annotation

Codecov / codecov/patch

src/ifdValue.ts#L125

Added line #L125 was not covered by tests
for (let i = 0; i < count; i++) {
rationals[i] = decoder.readInt32() / decoder.readInt32();
}
Expand All @@ -131,7 +131,7 @@

function readFloat(decoder: TIFFDecoder, count: number): number | Float32Array {
if (count === 1) return decoder.readFloat32();
let array = new Float32Array(count);
const array = new Float32Array(count);

Check warning on line 134 in src/ifdValue.ts

View check run for this annotation

Codecov / codecov/patch

src/ifdValue.ts#L134

Added line #L134 was not covered by tests
for (let i = 0; i < count; i++) {
array[i] = decoder.readFloat32();
}
Expand All @@ -143,7 +143,7 @@
count: number,
): number | Float64Array {
if (count === 1) return decoder.readFloat64();
let array = new Float64Array(count);
const array = new Float64Array(count);
for (let i = 0; i < count; i++) {
array[i] = decoder.readFloat64();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tags/exif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const tagsById: Record<number, string> = {
};

const tagsByName: Record<string, number> = {};
for (let i in tagsById) {
for (const i in tagsById) {
tagsByName[tagsById[i]] = Number(i);
}

Expand Down
2 changes: 1 addition & 1 deletion src/tags/gps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const tagsById: Record<number, string> = {
};

const tagsByName: Record<string, number> = {};
for (let i in tagsById) {
for (const i in tagsById) {
tagsByName[tagsById[i]] = Number(i);
}

Expand Down
2 changes: 1 addition & 1 deletion src/tags/standard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const tagsById: Record<number, string> = {
};

const tagsByName: Record<string, number> = {};
for (let i in tagsById) {
for (const i in tagsById) {
tagsByName[tagsById[i]] = Number(i);
}

Expand Down
14 changes: 7 additions & 7 deletions src/tiffDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

const maxIndex = pages ? Math.max(...pages) : Infinity;

options = Object.assign({}, defaultOptions, options);
options = { ...defaultOptions, ...options };
const result = [];
this.decodeHeader();
let index = 0;
Expand Down Expand Up @@ -160,7 +160,7 @@

// Read sub-IFDs
if (tag === 0x8769 || tag === 0x8825) {
let currentOffset = this.offset;
const currentOffset = this.offset;
let kind: IFDKind = 'exif';
if (tag === 0x8769) {
kind = 'exif';
Expand Down Expand Up @@ -203,7 +203,7 @@
if (ifd.type === 0) {
// WhiteIsZero: we invert the values
const bitDepth = ifd.bitsPerSample;
const maxValue = Math.pow(2, bitDepth) - 1;
const maxValue = 2 ** bitDepth - 1;
for (let i = 0; i < ifd.data.length; i++) {
ifd.data[i] = maxValue - ifd.data[i];
}
Expand All @@ -227,14 +227,14 @@
let remainingPixels = size;
let pixel = 0;
for (let i = 0; i < stripOffsets.length; i++) {
let stripData = new DataView(
const stripData = new DataView(
this.buffer,
this.byteOffset + stripOffsets[i],
stripByteCounts[i],
);

// Last strip can be smaller
let length = remainingPixels > maxPixels ? maxPixels : remainingPixels;
const length = remainingPixels > maxPixels ? maxPixels : remainingPixels;
remainingPixels -= length;

let dataToFill = stripData;
Expand Down Expand Up @@ -396,13 +396,13 @@
return index;
}

function unsupported(type: string, value: any): Error {

Check warning on line 399 in src/tiffDecoder.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type
return new Error(`Unsupported ${type}: ${value}`);
}
function checkPages(pages: number[] | undefined) {
if (pages) {
for (let page of pages) {
if (page < 0 || Number.isInteger(page) === false) {
for (const page of pages) {
if (page < 0 || !Number.isInteger(page)) {
throw new RangeError(
`Index ${page} is invalid. Must be a positive integer.`,
);
Expand Down
10 changes: 5 additions & 5 deletions src/tiffIfd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
return this.samplesPerPixel;
}
public get date(): Date {
let date = new Date();
let result = dateTimeRegex.exec(this.dateTime);
const date = new Date();
const result = dateTimeRegex.exec(this.dateTime);

Check warning on line 26 in src/tiffIfd.ts

View check run for this annotation

Codecov / codecov/patch

src/tiffIfd.ts#L25-L26

Added lines #L25 - L26 were not covered by tests
if (result === null) {
throw new Error(`invalid dateTime: ${this.dateTime}`);
}
Expand Down Expand Up @@ -100,7 +100,7 @@
return this.get('MinSampleValue') || 0;
}
public get maxSampleValue(): number {
return this.get('MaxSampleValue') || Math.pow(2, this.bitsPerSample) - 1;
return this.get('MaxSampleValue') || 2 ** this.bitsPerSample - 1;
}
public get xResolution(): number {
return this.get('XResolution');
Expand Down Expand Up @@ -129,14 +129,14 @@
public get sMaxSampleValue(): number {
return this.get('SMaxSampleValue') || this.maxSampleValue;
}
public get palette(): [number, number, number][] | undefined {
public get palette(): Array<[number, number, number]> | undefined {
const totalColors = 2 ** this.bitsPerSample;
const colorMap: number[] = this.get('ColorMap');
if (!colorMap) return undefined;
if (colorMap.length !== 3 * totalColors) {
throw new Error(`ColorMap size must be ${totalColors}`);
}
const palette: [number, number, number][] = [];
const palette: Array<[number, number, number]> = [];
for (let i = 0; i < totalColors; i++) {
palette.push([
colorMap[i],
Expand Down