[简体中文](readme.zh-cn.md)
npm install magic-typesGet the MIME of the data by parsing the Magic Number) in the file header, supporting most common file types.
MIME directly from url/Base64/ArrayBuffer datashell
npm i magic-types
`
`typescript
import { fetchMime, base64Mime, arraybufferMime } from 'magic-types'// use fetch request to read header data speculation -> image/png
console.log(await fetchMime("https://en.wikipedia.org/static/images/icons/wikipedia.png")) // -> image/png
// using base64 header data speculation -> image/png
console.log(base64Mime("iVBORw0KGgoAAAANSUhEUgAAAMgAAAC3CAMAAABg8uG4AAACNFBMVEVMaXGHh4jc3N6bm5yNjo6Vlpjh4eOnqKuysrPW19mwsbOtra5vb2 /Fxsd4eHiBg4SY"))
// use ArrayBuffer header data speculation -> image/png
const res = await fetch("https://en.wikipedia.org/static/images/icons/wikipedia.png")
const buffer = await res.arrayBuffer()
console.log(arraybufferMime(buffer))
`
$3
`html
`Document
$3
Use base64 headers to infer the document MIME type$3
For fetch requests, it is recommended to use Content-Type as the MIME` type in preference to using this method blindly.