Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 12.20 and move to ESM (#472)
- Loading branch information
1 parent
dcd7c80
commit 826b4ad
Showing
14 changed files
with
1,198 additions
and
1,257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,44 @@ | ||
/// <reference lib="dom"/> | ||
import * as core from './core'; | ||
|
||
export type FileTypeResult = core.FileTypeResult; | ||
export type FileExtension = core.FileExtension; | ||
export type MimeType = core.MimeType; | ||
import {FileTypeResult} from './core.js'; | ||
|
||
/** | ||
Determine file type from a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream). | ||
``` | ||
import FileType = require('file-type/browser'); | ||
import {fileTypeFromStream} from 'file-type/browser'; | ||
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg'; | ||
(async () => { | ||
const response = await fetch(url); | ||
const fileType = await FileType.fromStream(response.body); | ||
const response = await fetch(url); | ||
const fileType = await fileTypeFromStream(response.body); | ||
console.log(fileType); | ||
//=> {ext: 'jpg', mime: 'image/jpeg'} | ||
})(); | ||
console.log(fileType); | ||
//=> {ext: 'jpg', mime: 'image/jpeg'} | ||
``` | ||
*/ | ||
export declare function fromStream(stream: ReadableStream): Promise<core.FileTypeResult | undefined>; | ||
export declare function fileTypeFromStream(stream: ReadableStream): Promise<FileTypeResult | undefined>; | ||
|
||
/** | ||
Determine file type from a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob). | ||
``` | ||
import FileType = require('file-type/browser'); | ||
import {fileTypeFromBlob} from 'file-type/browser'; | ||
(async () => { | ||
const blob = new Blob(['<?xml version="1.0" encoding="ISO-8859-1" ?>'], { | ||
type: 'plain/text', | ||
endings: 'native' | ||
}); | ||
const blob = new Blob(['<?xml version="1.0" encoding="ISO-8859-1" ?>'], { | ||
type: 'plain/text', | ||
endings: 'native' | ||
}); | ||
console.log(await FileType.fromBlob(blob)); | ||
//=> {ext: 'txt', mime: 'plain/text'} | ||
})(); | ||
console.log(await fileTypeFromBlob(blob)); | ||
//=> {ext: 'txt', mime: 'plain/text'} | ||
``` | ||
*/ | ||
export declare function fromBlob(blob: Blob): Promise<core.FileTypeResult | undefined>; | ||
export declare function fileTypeFromBlob(blob: Blob): Promise<FileTypeResult | undefined>; | ||
|
||
export { | ||
fromBuffer, | ||
extensions, | ||
mimeTypes | ||
} from './core'; | ||
fileTypeFromBuffer, | ||
supportedExtensions, | ||
supportedMimeTypes, | ||
FileTypeResult, | ||
FileExtension, | ||
MimeType, | ||
} from './core.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.