@@ -30,7 +30,7 @@ const missingTests = new Set([
30
30
const [ nodeMajorVersion ] = process . versions . node . split ( '.' ) . map ( Number ) ;
31
31
const nodeVersionSupportingByteBlobStream = 20 ;
32
32
33
- const types = [ ...supportedExtensions ] . filter ( ext => ! missingTests . has ( ext ) ) ;
33
+ const types = [ ...supportedExtensions ] . filter ( extension => ! missingTests . has ( extension ) ) ;
34
34
35
35
// Define an entry here only if the fixture has a different
36
36
// name than `fixture` or if you want multiple fixtures
@@ -307,31 +307,31 @@ async function checkFile(t, type, filePath) {
307
307
t . is ( typeof mime , 'string' ) ;
308
308
}
309
309
310
- async function testFromFile ( t , ext , name ) {
311
- const file = path . join ( __dirname , 'fixture' , `${ ( name ?? 'fixture' ) } .${ ext } ` ) ;
312
- return checkFile ( t , ext , file ) ;
310
+ async function testFromFile ( t , extension , name ) {
311
+ const file = path . join ( __dirname , 'fixture' , `${ ( name ?? 'fixture' ) } .${ extension } ` ) ;
312
+ return checkFile ( t , extension , file ) ;
313
313
}
314
314
315
- async function testFromBuffer ( t , ext , name ) {
316
- const fixtureName = `${ ( name ?? 'fixture' ) } .${ ext } ` ;
315
+ async function testFromBuffer ( t , extension , name ) {
316
+ const fixtureName = `${ ( name ?? 'fixture' ) } .${ extension } ` ;
317
317
318
318
const file = path . join ( __dirname , 'fixture' , fixtureName ) ;
319
319
const chunk = fs . readFileSync ( file ) ;
320
- await checkBufferLike ( t , ext , chunk ) ;
321
- await checkBufferLike ( t , ext , new Uint8Array ( chunk ) ) ;
322
- await checkBufferLike ( t , ext , chunk . buffer . slice ( chunk . byteOffset , chunk . byteOffset + chunk . byteLength ) ) ;
320
+ await checkBufferLike ( t , extension , chunk ) ;
321
+ await checkBufferLike ( t , extension , new Uint8Array ( chunk ) ) ;
322
+ await checkBufferLike ( t , extension , chunk . buffer . slice ( chunk . byteOffset , chunk . byteOffset + chunk . byteLength ) ) ;
323
323
}
324
324
325
- async function testFromBlob ( t , ext , name ) {
326
- const fixtureName = `${ ( name ?? 'fixture' ) } .${ ext } ` ;
325
+ async function testFromBlob ( t , extension , name ) {
326
+ const fixtureName = `${ ( name ?? 'fixture' ) } .${ extension } ` ;
327
327
328
328
const file = path . join ( __dirname , 'fixture' , fixtureName ) ;
329
329
const chunk = fs . readFileSync ( file ) ;
330
- await checkBlobLike ( t , ext , chunk ) ;
330
+ await checkBlobLike ( t , extension , chunk ) ;
331
331
}
332
332
333
- async function testFalsePositive ( t , ext , name ) {
334
- const file = path . join ( __dirname , 'fixture' , `${ name } .${ ext } ` ) ;
333
+ async function testFalsePositive ( t , extension , name ) {
334
+ const file = path . join ( __dirname , 'fixture' , `${ name } .${ extension } ` ) ;
335
335
336
336
await t . is ( await fileTypeFromFile ( file ) , undefined ) ;
337
337
@@ -341,22 +341,22 @@ async function testFalsePositive(t, ext, name) {
341
341
t . is ( await fileTypeFromBuffer ( chunk . buffer ) , undefined ) ;
342
342
}
343
343
344
- async function testFileNodeFromStream ( t , ext , name ) {
345
- const filename = `${ ( name ?? 'fixture' ) } .${ ext } ` ;
344
+ async function testFileNodeFromStream ( t , extension , name ) {
345
+ const filename = `${ ( name ?? 'fixture' ) } .${ extension } ` ;
346
346
const file = path . join ( __dirname , 'fixture' , filename ) ;
347
347
const fileType = await fileTypeNodeFromStream ( fs . createReadStream ( file ) ) ;
348
348
349
349
t . truthy ( fileType , `identify ${ filename } ` ) ;
350
- t . is ( fileType . ext , ext , 'fileType.ext' ) ;
350
+ t . is ( fileType . ext , extension , 'fileType.ext' ) ;
351
351
t . is ( typeof fileType . mime , 'string' , 'fileType.mime' ) ;
352
352
}
353
353
354
354
async function getStreamAsUint8Array ( stream ) {
355
355
return new Uint8Array ( await getStreamAsArrayBuffer ( stream ) ) ;
356
356
}
357
357
358
- async function testStreamWithNodeStream ( t , ext , name ) {
359
- const fixtureName = `${ ( name ?? 'fixture' ) } .${ ext } ` ;
358
+ async function testStreamWithNodeStream ( t , extension , name ) {
359
+ const fixtureName = `${ ( name ?? 'fixture' ) } .${ extension } ` ;
360
360
const file = path . join ( __dirname , 'fixture' , fixtureName ) ;
361
361
362
362
const readableStream = await fileTypeStream ( fs . createReadStream ( file ) ) ;
@@ -367,8 +367,8 @@ async function testStreamWithNodeStream(t, ext, name) {
367
367
t . true ( areUint8ArraysEqual ( bufferA , bufferB ) ) ;
368
368
}
369
369
370
- async function testStreamWithWebStream ( t , ext , name ) {
371
- const fixtureName = `${ ( name ?? 'fixture' ) } .${ ext } ` ;
370
+ async function testStreamWithWebStream ( t , extension , name ) {
371
+ const fixtureName = `${ ( name ?? 'fixture' ) } .${ extension } ` ;
372
372
const file = path . join ( __dirname , 'fixture' , fixtureName ) ;
373
373
// Read the file into a buffer
374
374
const fileBuffer = await readFile ( file ) ;
@@ -387,7 +387,7 @@ test('Test suite must be able to detect Node.js major version', t => {
387
387
388
388
let i = 0 ;
389
389
for ( const type of types ) {
390
- if ( Object . prototype . hasOwnProperty . call ( names , type ) ) {
390
+ if ( Object . hasOwn ( names , type ) ) {
391
391
for ( const name of names [ type ] ) {
392
392
const fixtureName = `${ name } .${ type } ` ;
393
393
const _test = failingFixture . has ( fixtureName ) ? test . failing : test ;
@@ -413,7 +413,7 @@ for (const type of types) {
413
413
test ( `${ type } ${ i ++ } .fileTypeStream() - identical streams` , testStreamWithNodeStream , type ) ;
414
414
}
415
415
416
- if ( Object . prototype . hasOwnProperty . call ( falsePositives , type ) ) {
416
+ if ( Object . hasOwn ( falsePositives , type ) ) {
417
417
for ( const falsePositiveFile of falsePositives [ type ] ) {
418
418
test ( `false positive - ${ type } ${ i ++ } ` , testFalsePositive , type , falsePositiveFile ) ;
419
419
}
@@ -518,13 +518,13 @@ test('validate the repo has all extensions and mimes in sync', t => {
518
518
// File: core.js (base truth)
519
519
function readIndexJS ( ) {
520
520
const core = fs . readFileSync ( 'core.js' , { encoding : 'utf8' } ) ;
521
- const extArray = core . match ( / (?< = e x t : \s ' ) ( .* ) (? = ' , ) / g) ;
521
+ const extensionArray = core . match ( / (?< = e x t : \s ' ) ( .* ) (? = ' , ) / g) ;
522
522
const mimeArray = core . match ( / (?< = m i m e : \s ' ) ( .* ) (? = ' ) / g) ;
523
- const exts = new Set ( extArray ) ;
523
+ const extensions = new Set ( extensionArray ) ;
524
524
const mimes = new Set ( mimeArray ) ;
525
525
526
526
return {
527
- exts,
527
+ exts : extensions ,
528
528
mimes,
529
529
} ;
530
530
}
@@ -557,15 +557,15 @@ test('validate the repo has all extensions and mimes in sync', t => {
557
557
'webassembly' ,
558
558
] ) ;
559
559
560
- const extArray = keywords . filter ( keyword => ! allowedExtras . has ( keyword ) ) ;
561
- return extArray ;
560
+ const extensionArray = keywords . filter ( keyword => ! allowedExtras . has ( keyword ) ) ;
561
+ return extensionArray ;
562
562
}
563
563
564
564
// File: readme.md
565
565
function readReadmeMD ( ) {
566
566
const index = fs . readFileSync ( 'readme.md' , { encoding : 'utf8' } ) ;
567
- const extArray = index . match ( / (?< = - \s \[ ` ) ( .* ) (? = ` ) / g) ;
568
- return extArray ;
567
+ const extensionArray = index . match ( / (?< = - \s \[ ` ) ( .* ) (? = ` ) / g) ;
568
+ return extensionArray ;
569
569
}
570
570
571
571
// Helpers
@@ -601,13 +601,13 @@ test('validate the repo has all extensions and mimes in sync', t => {
601
601
}
602
602
603
603
// Test runner
604
- function validate ( found , baseTruth , fileName , extOrMime ) {
604
+ function validate ( found , baseTruth , fileName , extensionOrMime ) {
605
605
const duplicates = findDuplicates ( found ) ;
606
606
const extras = findExtras ( found , baseTruth ) ;
607
607
const missing = findMissing ( found , baseTruth ) ;
608
- t . is ( duplicates . length , 0 , `Found duplicate ${ extOrMime } : ${ duplicates } in ${ fileName } .` ) ;
609
- t . is ( extras . length , 0 , `Extra ${ extOrMime } : ${ extras } in ${ fileName } .` ) ;
610
- t . is ( missing . length , 0 , `Missing ${ extOrMime } : ${ missing } in ${ fileName } .` ) ;
608
+ t . is ( duplicates . length , 0 , `Found duplicate ${ extensionOrMime } : ${ duplicates } in ${ fileName } .` ) ;
609
+ t . is ( extras . length , 0 , `Extra ${ extensionOrMime } : ${ extras } in ${ fileName } .` ) ;
610
+ t . is ( missing . length , 0 , `Missing ${ extensionOrMime } : ${ missing } in ${ fileName } .` ) ;
611
611
}
612
612
613
613
// Get the base truth of extensions and mimes supported from core.js
0 commit comments