file-type 18.0.0 → 18.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/browser.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {FileTypeResult} from './core.js';
1
+ import type {FileTypeResult} from './core.js';
2
2
 
3
3
  /**
4
4
  Detect the file type of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).
@@ -42,7 +42,7 @@ export {
42
42
  fileTypeFromBuffer,
43
43
  supportedExtensions,
44
44
  supportedMimeTypes,
45
- FileTypeResult,
46
- FileExtension,
47
- MimeType,
45
+ type FileTypeResult,
46
+ type FileExtension,
47
+ type MimeType,
48
48
  } from './core.js';
package/core.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import {Readable as ReadableStream} from 'node:stream';
2
- import {ITokenizer} from 'strtok3';
1
+ import type {Readable as ReadableStream} from 'node:stream';
2
+ import type {ITokenizer} from 'strtok3';
3
3
 
4
4
  export type FileExtension =
5
5
  | 'jpg'
@@ -140,7 +140,11 @@ export type FileExtension =
140
140
  | '3mf'
141
141
  | 'zst'
142
142
  | 'jxl'
143
- | 'vcf';
143
+ | 'vcf'
144
+ | 'jls'
145
+ | 'pst'
146
+ | 'dwg'
147
+ | 'parquet';
144
148
 
145
149
  export type MimeType =
146
150
  | 'image/jpeg'
@@ -276,9 +280,13 @@ export type MimeType =
276
280
  | 'application/vnd.ms-htmlhelp'
277
281
  | 'model/3mf'
278
282
  | 'image/jxl'
279
- | 'application/zstd';
283
+ | 'application/zstd'
284
+ | 'image/jls'
285
+ | 'application/vnd.ms-outlook'
286
+ | 'image/vnd.dwg'
287
+ | 'application/x-parquet';
280
288
 
281
- export interface FileTypeResult {
289
+ export type FileTypeResult = {
282
290
  /**
283
291
  One of the supported [file types](https://github.com/sindresorhus/file-type#supported-file-types).
284
292
  */
@@ -288,7 +296,7 @@ export interface FileTypeResult {
288
296
  The detected [MIME type](https://en.wikipedia.org/wiki/Internet_media_type).
289
297
  */
290
298
  readonly mime: MimeType;
291
- }
299
+ };
292
300
 
293
301
  export type ReadableStreamWithFileType = ReadableStream & {
294
302
  readonly fileType?: FileTypeResult;
@@ -354,14 +362,14 @@ Supported MIME types.
354
362
  */
355
363
  export const supportedMimeTypes: ReadonlySet<MimeType>;
356
364
 
357
- export interface StreamOptions {
365
+ export type StreamOptions = {
358
366
  /**
359
367
  The default sample size in bytes.
360
368
 
361
369
  @default 4100
362
370
  */
363
371
  readonly sampleSize?: number;
364
- }
372
+ };
365
373
 
366
374
  /**
367
375
  Returns a `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `fileTypeFromFile()`.
package/core.js CHANGED
@@ -159,13 +159,6 @@ class FileTypeParser {
159
159
  };
160
160
  }
161
161
 
162
- if (this.check([0xFF, 0xD8, 0xFF])) {
163
- return {
164
- ext: 'jpg',
165
- mime: 'image/jpeg',
166
- };
167
- }
168
-
169
162
  if (this.check([0x49, 0x49, 0xBC])) {
170
163
  return {
171
164
  ext: 'jxr',
@@ -222,6 +215,21 @@ class FileTypeParser {
222
215
 
223
216
  // -- 4-byte signatures --
224
217
 
218
+ // Requires a sample size of 4 bytes
219
+ if (this.check([0xFF, 0xD8, 0xFF])) {
220
+ if (this.check([0xF7], {offset: 3})) { // JPG7/SOF55, indicating a ISO/IEC 14495 / JPEG-LS file
221
+ return {
222
+ ext: 'jls',
223
+ mime: 'image/jls',
224
+ };
225
+ }
226
+
227
+ return {
228
+ ext: 'jpg',
229
+ mime: 'image/jpeg',
230
+ };
231
+ }
232
+
225
233
  if (this.checkString('FLIF')) {
226
234
  return {
227
235
  ext: 'flif',
@@ -800,6 +808,20 @@ class FileTypeParser {
800
808
  };
801
809
  }
802
810
 
811
+ if (this.check([0x21, 0x42, 0x44, 0x4E])) {
812
+ return {
813
+ ext: 'pst',
814
+ mime: 'application/vnd.ms-outlook',
815
+ };
816
+ }
817
+
818
+ if (this.checkString('PAR1')) {
819
+ return {
820
+ ext: 'parquet',
821
+ mime: 'application/x-parquet',
822
+ };
823
+ }
824
+
803
825
  // -- 5-byte signatures --
804
826
 
805
827
  if (this.check([0x4F, 0x54, 0x54, 0x4F, 0x00])) {
@@ -923,6 +945,16 @@ class FileTypeParser {
923
945
  };
924
946
  }
925
947
 
948
+ if (this.checkString('AC')) {
949
+ const version = this.buffer.toString('binary', 2, 6);
950
+ if (version.match('^d*') && version >= 1000 && version <= 1050) {
951
+ return {
952
+ ext: 'dwg',
953
+ mime: 'image/vnd.dwg',
954
+ };
955
+ }
956
+ }
957
+
926
958
  // -- 7-byte signatures --
927
959
 
928
960
  if (this.checkString('BLENDER')) {
@@ -1483,8 +1515,8 @@ class FileTypeParser {
1483
1515
  }
1484
1516
 
1485
1517
  await this.tokenizer.ignore(ifdOffset);
1486
- const fileType = await this.readTiffIFD(false);
1487
- return fileType ? fileType : {
1518
+ const fileType = await this.readTiffIFD(bigEndian);
1519
+ return fileType ?? {
1488
1520
  ext: 'tif',
1489
1521
  mime: 'image/tiff',
1490
1522
  };
package/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import {Readable as ReadableStream} from 'node:stream';
2
- import {FileTypeResult} from './core.js';
1
+ import type {FileTypeResult} from './core.js';
3
2
 
4
3
  /**
5
4
  Detect the file type of a file path.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "file-type",
3
- "version": "18.0.0",
3
+ "version": "18.2.0",
4
4
  "description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/file-type",
@@ -193,7 +193,11 @@
193
193
  "3mf",
194
194
  "zst",
195
195
  "jxl",
196
- "vcf"
196
+ "vcf",
197
+ "jls",
198
+ "pst",
199
+ "dwg",
200
+ "parquet"
197
201
  ],
198
202
  "dependencies": {
199
203
  "readable-web-to-node-stream": "^3.0.2",
@@ -203,11 +207,11 @@
203
207
  "devDependencies": {
204
208
  "@tokenizer/token": "^0.3.0",
205
209
  "@types/node": "^18.7.13",
206
- "ava": "^4.3.1",
210
+ "ava": "^5.1.0",
207
211
  "commonmark": "^0.30.0",
208
212
  "noop-stream": "^1.0.0",
209
- "tsd": "^0.22.0",
210
- "xo": "^0.51.0"
213
+ "tsd": "^0.25.0",
214
+ "xo": "^0.53.1"
211
215
  },
212
216
  "xo": {
213
217
  "envs": [
@@ -219,7 +223,9 @@
219
223
  "no-await-in-loop": "warn",
220
224
  "no-bitwise": "off",
221
225
  "@typescript-eslint/no-unsafe-assignment": "off",
222
- "unicorn/text-encoding-identifier-case": "off"
226
+ "unicorn/text-encoding-identifier-case": "off",
227
+ "unicorn/switch-case-braces": "off",
228
+ "unicorn/prefer-top-level-await": "off"
223
229
  }
224
230
  },
225
231
  "ava": {
package/readme.md CHANGED
@@ -376,6 +376,7 @@ Returns a `Set<string>` of supported MIME types.
376
376
  - [`dng`](https://en.wikipedia.org/wiki/Digital_Negative) - Adobe Digital Negative image file
377
377
  - [`docx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Word
378
378
  - [`dsf`](https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf) - Sony DSD Stream File (DSF)
379
+ - [`dwg`](https://en.wikipedia.org/wiki/.dwg) - Autodesk CAD file
379
380
  - [`elf`](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) - Unix Executable and Linkable Format
380
381
  - [`eot`](https://en.wikipedia.org/wiki/Embedded_OpenType) - Embedded OpenType font
381
382
  - [`eps`](https://en.wikipedia.org/wiki/Encapsulated_PostScript) - Encapsulated PostScript
@@ -397,6 +398,7 @@ Returns a `Set<string>` of supported MIME types.
397
398
  - [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - iCalendar
398
399
  - [`indd`](https://en.wikipedia.org/wiki/Adobe_InDesign#File_format) - Adobe InDesign document
399
400
  - [`it`](https://wiki.openmpt.org/Manual:_Module_formats#The_Impulse_Tracker_format_.28.it.29) - Audio module format: Impulse Tracker
401
+ - [`jls`](https://en.wikipedia.org/wiki/Lossless_JPEG#JPEG-LS) - Lossless/near-lossless compression standard for continuous-tone images
400
402
  - [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
401
403
  - [`jpg`](https://en.wikipedia.org/wiki/JPEG) - Joint Photographic Experts Group image
402
404
  - [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
@@ -410,7 +412,7 @@ Returns a `Set<string>` of supported MIME types.
410
412
  - [`m4a`](https://en.wikipedia.org/wiki/M4A) - Audio-only MPEG-4 files
411
413
  - [`m4b`](https://en.wikipedia.org/wiki/M4B) - Audiobook and podcast MPEG-4 files, which also contain metadata including chapter markers, images, and hyperlinks
412
414
  - [`m4p`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions) - MPEG-4 files with audio streams encrypted by FairPlay Digital Rights Management as were sold through the iTunes Store
413
- - [`m4v`](https://en.wikipedia.org/wiki/M4V) - MPEG-4 Visual bitstreams
415
+ - [`m4v`](https://en.wikipedia.org/wiki/M4V) - Video container format developed by Apple, which is very similar to the MP4 format
414
416
  - [`mid`](https://en.wikipedia.org/wiki/MIDI) - Musical Instrument Digital Interface file
415
417
  - [`mie`](https://en.wikipedia.org/wiki/Sidecar_file) - Dedicated meta information format which supports storage of binary as well as textual meta information
416
418
  - [`mj2`](https://en.wikipedia.org/wiki/Motion_JPEG_2000) - Motion JPEG 2000
@@ -438,6 +440,7 @@ Returns a `Set<string>` of supported MIME types.
438
440
  - [`opus`](https://en.wikipedia.org/wiki/Opus_(audio_format)) - Audio file
439
441
  - [`orf`](https://en.wikipedia.org/wiki/ORF_format) - Olympus Raw image file
440
442
  - [`otf`](https://en.wikipedia.org/wiki/OpenType) - OpenType font
443
+ - [`parquet`](https://en.wikipedia.org/wiki/Apache_Parquet) - Apache Parquet
441
444
  - [`pcap`](https://wiki.wireshark.org/Development/LibpcapFileFormat) - Libpcap File Format
442
445
  - [`pdf`](https://en.wikipedia.org/wiki/Portable_Document_Format) - Portable Document Format
443
446
  - [`pgp`](https://en.wikipedia.org/wiki/Pretty_Good_Privacy) - Pretty Good Privacy
@@ -445,6 +448,7 @@ Returns a `Set<string>` of supported MIME types.
445
448
  - [`pptx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Powerpoint
446
449
  - [`ps`](https://en.wikipedia.org/wiki/Postscript) - Postscript
447
450
  - [`psd`](https://en.wikipedia.org/wiki/Adobe_Photoshop#File_format) - Adobe Photoshop document
451
+ - [`pst`](https://en.wikipedia.org/wiki/Personal_Storage_Table) - Personal Storage Table file
448
452
  - [`qcp`](https://en.wikipedia.org/wiki/QCP) - Tagged and chunked data
449
453
  - [`raf`](https://en.wikipedia.org/wiki/Raw_image_format) - Fujifilm RAW image file
450
454
  - [`rar`](https://en.wikipedia.org/wiki/RAR_(file_format)) - Archive file
@@ -490,12 +494,6 @@ The following file types will not be accepted:
490
494
  - `.csv` - [Reason.](https://github.com/sindresorhus/file-type/issues/264#issuecomment-568439196)
491
495
  - `.svg` - Detecting it requires a full-blown parser. Check out [`is-svg`](https://github.com/sindresorhus/is-svg) for something that mostly works.
492
496
 
493
- ## file-type for enterprise
494
-
495
- Available as part of the Tidelift Subscription.
496
-
497
- The maintainers of file-type and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-file-type?utm_source=npm-file-type&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
498
-
499
497
  ## Related
500
498
 
501
499
  - [file-type-cli](https://github.com/sindresorhus/file-type-cli) - CLI for this module
@@ -503,6 +501,9 @@ The maintainers of file-type and thousands of other packages are working with Ti
503
501
  ## Maintainers
504
502
 
505
503
  - [Sindre Sorhus](https://github.com/sindresorhus)
504
+ - [Borewit](https://github.com/Borewit)
505
+
506
+ **Former**
507
+
506
508
  - [Mikael Finstad](https://github.com/mifi)
507
509
  - [Ben Brook](https://github.com/bencmbrook)
508
- - [Borewit](https://github.com/Borewit)
package/supported.js CHANGED
@@ -138,6 +138,10 @@ export const extensions = [
138
138
  'zst',
139
139
  'jxl',
140
140
  'vcf',
141
+ 'jls',
142
+ 'pst',
143
+ 'dwg',
144
+ 'parquet',
141
145
  ];
142
146
 
143
147
  export const mimeTypes = [
@@ -275,4 +279,8 @@ export const mimeTypes = [
275
279
  'model/3mf',
276
280
  'image/jxl',
277
281
  'application/zstd',
282
+ 'image/jls',
283
+ 'application/vnd.ms-outlook',
284
+ 'image/vnd.dwg',
285
+ 'application/x-parquet',
278
286
  ];