Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Detect the MIME type of a Buffer, Uint8Array, ArrayBuffer, ReadableStream, file path and file name, with sync and async methods.
Detect the MIME type of a Buffer
, Uint8Array
, ArrayBuffer
, ReadableStream
, file path and file name, with sync
and async
methods.
$ npm install mime-kind --save
const { createReadStream } = require('fs');
const { sync: mime, async: mimeAsync } = require('mime-kind');
mime('c:/anonim.jpeg'); // -> { ext: 'jpeg', mime: 'image/jpeg' }
mime('.fakeext'); // -> null
mime(createReadStream('./anonim.jpg')); // -> { ext: 'jpeg', mime: 'image/jpeg' }
await mimeAsync('c:/anonim.jpeg'); // -> { ext: 'jpeg', mime: 'image/jpeg' }
Returns a Promise
with an object (or null
when no match) with:
ext
- file typemime
- the MIME typeThis methods supports all kind of ReadableStreams
.
Buffer
, Uint8Array
, ArrayBuffer
, ReadableStream
, file path or file name.String
or Object
with value which will be returned if no match will be found. If defaultValue
is incorrect returns null
.const mime = require('mime-kind');
await mime('.fakeext', 'application/octet-stream'); // -> { ext: 'bin', mime: 'application/octet-stream' }
await mime.async('.fakeext', { ext: 'mp4', mime: 'video/mp4' }); // -> { ext: 'mp4', mime: 'video/mp4' }
await mime.async('.fakeext', 'ogg'); // -> { ext: 'ogg', mime: 'audio/ogg' }
// but
await mime.async('.fakeext', 'ogg3'); // -> null
await mime('.fakeext', { ext: 'fake', mime: 'fake/fake' }); // -> null
With HTTP(S)
streams:
const mime = require('mime-kind');
const { get } = require('https');
const { PassThrough } = require('stream');
const pass = new PassThrough();
get('https://avatars0.githubusercontent.com/u/2401029', res => res.pipe(pass));
await mime(pass); // -> { ext: 'jpg', mime: 'image/jpeg' }
Returns an object (or null
when no match) with:
ext
- file typemime
- the MIME typeThis methods supports only fs.ReadStream
as ReadableStream
.
Buffer
, Uint8Array
, ArrayBuffer
, ReadableStream
, file path or file name.String
or Object
with value which will be returned if no match will be found. If defaultValue
is incorrect returns null
.const mime = require('mime-kind');
mime.sync('.fakeext', 'application/octet-stream'); // -> { ext: 'bin', mime: 'application/octet-stream' }
mime.sync('.fakeext', { ext: 'mp4', mime: 'video/mp4' }); // -> { ext: 'mp4', mime: 'video/mp4' }
mime.sync('.fakeext', 'ogg'); // -> { ext: 'ogg', mime: 'audio/ogg' }
// but
mime.sync('.fakeext', 'ogg3'); // -> null
mime.sync('.fakeext', { ext: 'fake', mime: 'fake/fake' }); // -> null
The MIT License (MIT)
Copyright (c) 2015-2019 Alexey Bystrov
FAQs
Detect the MIME type of a Buffer, Uint8Array, ArrayBuffer, ReadableStream, file path and file name, with async method.
The npm package mime-kind receives a total of 21,843 weekly downloads. As such, mime-kind popularity was classified as popular.
We found that mime-kind demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.