Skip to content

Commit 9f48213

Browse files
committed
update dependencies, and reformat code with eslint 9
1 parent 64dda84 commit 9f48213

22 files changed

Lines changed: 362 additions & 318 deletions

.eslintrc

Lines changed: 0 additions & 41 deletions
This file was deleted.

.prettierrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.prettierrc.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tabWidth: 2
2+
semi: false
3+
singleQuote: true

bin/image-size.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
/* eslint-disable @typescript-eslint/no-var-requires */
23
'use strict'
34

45
const fs = require('fs')
@@ -28,18 +29,22 @@ files.forEach(function (image) {
2829
const greyImage = colorize(image, grey)
2930
const size = imageSize(image)
3031
const sizes = size.images || [size]
31-
sizes.forEach(size => {
32+
sizes.forEach((size) => {
3233
let greyType = ''
3334
if (size.type) {
3435
greyType = colorize(' (' + size.type + ')', grey)
3536
}
3637
console.info(
37-
colorize(size.width, green) + greyX + colorize(size.height, green)
38-
+ ' - ' + greyImage + greyType
38+
colorize(size.width, green) +
39+
greyX +
40+
colorize(size.height, green) +
41+
' - ' +
42+
greyImage +
43+
greyType,
3944
)
4045
})
4146
} else {
42-
console.error('file doesn\'t exist - ', image)
47+
console.error("file doesn't exist - ", image)
4348
}
4449
} catch (e) {
4550
// console.error(e.stack)

eslint.config.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @ts-check
2+
import globals from 'globals'
3+
import eslint from '@eslint/js'
4+
import ts_eslint from 'typescript-eslint'
5+
import prettierRecommended from 'eslint-plugin-prettier/recommended';
6+
7+
export default ts_eslint.config(
8+
eslint.configs.recommended,
9+
...ts_eslint.configs.strict,
10+
...ts_eslint.configs.stylistic,
11+
{
12+
languageOptions: {
13+
globals: {
14+
...globals.node,
15+
...globals.browser,
16+
},
17+
},
18+
},
19+
prettierRecommended,
20+
)

lib/detector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { typeHandlers } from './types/index'
44
const keys = Object.keys(typeHandlers) as imageType[]
55

66
// This map helps avoid validating for every single image type
7-
const firstBytes: { [byte: number]: imageType } = {
7+
const firstBytes: Record<number, imageType> = {
88
0x38: 'psd',
99
0x42: 'bmp',
1010
0x44: 'dds',

lib/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const MaxInputSize = 512 * 1024
1515
// This queue is for async `fs` operations, to avoid reaching file-descriptor limits
1616
const queue = new Queue({ concurrency: 100, autostart: true })
1717

18-
type Options = {
18+
interface Options {
1919
disabledFS: boolean
2020
disabledTypes: imageType[]
2121
}
@@ -53,7 +53,7 @@ function lookup(input: Uint8Array, filepath?: string): ISizeCalculationResult {
5353

5454
// throw up, if we don't understand the file
5555
throw new TypeError(
56-
'unsupported file type: ' + type + ' (file: ' + filepath + ')'
56+
'unsupported file type: ' + type + ' (file: ' + filepath + ')',
5757
)
5858
}
5959

@@ -114,8 +114,8 @@ export function imageSize(input: string, callback: CallbackFn): void
114114
*/
115115
export function imageSize(
116116
input: Uint8Array | string,
117-
callback?: CallbackFn
118-
): ISizeCalculationResult | void {
117+
callback?: CallbackFn,
118+
): ISizeCalculationResult | undefined {
119119
// Handle Uint8Array input
120120
if (input instanceof Uint8Array) {
121121
return lookup(input)
@@ -132,9 +132,9 @@ export function imageSize(
132132
queue.push(() =>
133133
readFileAsync(filepath)
134134
.then((input) =>
135-
process.nextTick(callback, null, lookup(input, filepath))
135+
process.nextTick(callback, null, lookup(input, filepath)),
136136
)
137-
.catch(callback)
137+
.catch(callback),
138138
)
139139
} else {
140140
const input = readFileSync(filepath)

lib/types/heif.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ export const HEIF: IImage = {
3737
}
3838
}
3939
throw new TypeError('Invalid HEIF, no size found')
40-
}
40+
},
4141
}

lib/types/icns.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const FILE_LENGTH_OFFSET = 4 // MSB => BIG ENDIAN
2222
*/
2323
const ENTRY_LENGTH_OFFSET = 4 // MSB => BIG ENDIAN
2424

25-
const ICON_TYPE_SIZE: { [key: string]: number } = {
25+
const ICON_TYPE_SIZE: Record<string, number> = {
2626
ICON: 32,
2727
'ICN#': 32,
2828
// m => 16 x 16
@@ -67,7 +67,7 @@ const ICON_TYPE_SIZE: { [key: string]: number } = {
6767

6868
function readImageHeader(
6969
input: Uint8Array,
70-
imageOffset: number
70+
imageOffset: number,
7171
): [string, number] {
7272
const imageLengthOffset = imageOffset + ENTRY_LENGTH_OFFSET
7373
return [

lib/types/interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type ISize = {
1+
export interface ISize {
22
width: number | undefined
33
height: number | undefined
44
orientation?: number
@@ -9,7 +9,7 @@ export type ISizeCalculationResult = {
99
images?: ISize[]
1010
} & ISize
1111

12-
export type IImage = {
12+
export interface IImage {
1313
validate: (input: Uint8Array) => boolean
1414
calculate: (input: Uint8Array, filepath?: string) => ISizeCalculationResult
1515
}

0 commit comments

Comments
 (0)