Comparing version 2.0.2 to 3.0.0
{ | ||
"name": "mime-kind", | ||
"author": "Alexey Bystrov <strikeentco@gmail.com>", | ||
"version": "2.0.2", | ||
"description": "Detect the mime type of a Buffer, ReadStream, file path and file name.", | ||
"version": "3.0.0", | ||
"description": "Detect the MIME type of a Buffer, Uint8Array, ArrayBuffer, ReadableStream, file path and file name, with sync and async methods.", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
"node": ">=8.3.0" | ||
}, | ||
@@ -17,14 +17,18 @@ "keywords": [ | ||
"read stream", | ||
"detect" | ||
"readable stream", | ||
"detect", | ||
"sync", | ||
"async" | ||
], | ||
"main": "./main.js", | ||
"main": "./index.js", | ||
"files": [ | ||
"main.js" | ||
"index.js", | ||
"utils.js" | ||
], | ||
"scripts": { | ||
"test": "mocha test", | ||
"lint": "eslint main.js", | ||
"lint": "eslint index.js utils.js", | ||
"check": "npm run lint && npm run test", | ||
"cover": "istanbul cover ./node_modules/mocha/bin/_mocha", | ||
"test-on-travis": "istanbul cover --report lcovonly ./node_modules/mocha/bin/_mocha" | ||
"cover": "nyc ./node_modules/mocha/bin/_mocha && nyc report --reporter=html", | ||
"test-on-travis": "nyc ./node_modules/mocha/bin/_mocha && nyc report --reporter=lcovonly" | ||
}, | ||
@@ -39,15 +43,16 @@ "repository": { | ||
"dependencies": { | ||
"file-type": "^4.3.0", | ||
"mime-types": "^2.1.15" | ||
"file-type": "^12.1.0", | ||
"mime-types": "^2.1.24" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^3.19.0", | ||
"eslint-config-airbnb": "^15.0.1", | ||
"eslint-plugin-import": "^2.3.0", | ||
"eslint-plugin-jsx-a11y": "^5.0.3", | ||
"eslint-plugin-react": "^7.0.1", | ||
"mocha": "^3.4.2", | ||
"should": "^11.2.1" | ||
"eslint": "^5.16.0", | ||
"eslint-config-airbnb": "^17.1.1", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-jsx-a11y": "^6.2.3", | ||
"eslint-plugin-react": "^7.14.3", | ||
"mocha": "^6.2.0", | ||
"nyc": "^14.1.1", | ||
"should": "^13.2.3" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -1,6 +0,6 @@ | ||
mime-kind [![License](https://img.shields.io/npm/l/mime-kind.svg)](https://github.com/strikeentco/mime-kind/blob/master/LICENSE) [![npm](https://img.shields.io/npm/v/mime-kind.svg)](https://www.npmjs.com/package/mime-kind) | ||
mime-kind [![License](https://img.shields.io/npm/l/mime-kind.svg)](https://github.com/strikeentco/mime-kind/blob/master/LICENSE) [![npm](https://img.shields.io/npm/v/mime-kind.svg)](https://www.npmjs.com/package/mime-kind) | ||
========== | ||
[![Build Status](https://travis-ci.org/strikeentco/mime-kind.svg)](https://travis-ci.org/strikeentco/mime-kind) [![node](https://img.shields.io/node/v/mime-kind.svg)](https://www.npmjs.com/package/mime-kind) [![Test Coverage](https://codeclimate.com/github/strikeentco/mime-kind/badges/coverage.svg)](https://codeclimate.com/github/strikeentco/mime-kind/coverage) [![bitHound Score](https://www.bithound.io/github/strikeentco/mime-kind/badges/score.svg)](https://www.bithound.io/github/strikeentco/mime-kind) | ||
[![Build Status](https://travis-ci.org/strikeentco/mime-kind.svg)](https://travis-ci.org/strikeentco/mime-kind) [![node](https://img.shields.io/node/v/mime-kind.svg)](https://www.npmjs.com/package/mime-kind) [![Test Coverage](https://api.codeclimate.com/v1/badges/5c3c2bdb323d9132a2f4/test_coverage)](https://codeclimate.com/github/strikeentco/mime-kind/test_coverage) | ||
Detect the mime type of a `Buffer`, `ReadStream`, file path and file name. | ||
Detect the MIME type of a `Buffer`, `Uint8Array`, `ArrayBuffer`, `ReadableStream`, file path and file name, with `sync` and `async` methods. | ||
@@ -15,8 +15,9 @@ ## Install | ||
```js | ||
const fs = require('fs'); | ||
const mime = require('mime-kind'); | ||
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(fs.createReadStream('./anonim.jpg')); // -> { ext: 'jpeg', mime: 'image/jpeg' } | ||
mime(createReadStream('./anonim.jpg')); // -> { ext: 'jpeg', mime: 'image/jpeg' } | ||
await mimeAsync('c:/anonim.jpeg'); // -> { ext: 'jpeg', mime: 'image/jpeg' } | ||
``` | ||
@@ -26,4 +27,41 @@ | ||
### mime(data, [defaultValue]) | ||
### mime(input, [defaultValue]) | ||
### mime.async(input, [defaultValue]) | ||
Returns a `Promise` with an object (or `null` when no match) with: | ||
* `ext` - file type | ||
* `mime` - the [MIME type](http://en.wikipedia.org/wiki/Internet_media_type) | ||
This methods supports all kind of `ReadableStreams`. | ||
### Params: | ||
* **input** (*String|Buffer|Uint8Array|ArrayBuffer|ReadableStream*) - `Buffer`, `Uint8Array`, `ArrayBuffer`, `ReadableStream`, file path or file name. | ||
* **[defaultValue]** (*String|Object*) - `String` or `Object` with value which will be returned if no match will be found. If `defaultValue` is incorrect returns `null`. | ||
```js | ||
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: | ||
```js | ||
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' } | ||
``` | ||
### mime.sync(input, [defaultValue]) | ||
Returns an object (or `null` when no match) with: | ||
@@ -34,5 +72,7 @@ | ||
This methods supports only `fs.ReadStream` as `ReadableStream`. | ||
### Params: | ||
* **data** (*Buffer|ReadStream|String*) - `Buffer`, `ReadStream`, file path or file name. | ||
* **input** (*String|Buffer|Uint8Array|ArrayBuffer|ReadableStream*) - `Buffer`, `Uint8Array`, `ArrayBuffer`, `ReadableStream`, file path or file name. | ||
* **[defaultValue]** (*String|Object*) - `String` or `Object` with value which will be returned if no match will be found. If `defaultValue` is incorrect returns `null`. | ||
@@ -43,8 +83,8 @@ | ||
mime('.fakeext', 'application/octet-stream'); // -> { ext: 'bin', mime: 'application/octet-stream' } | ||
mime('.fakeext', { ext: 'mp4', mime: 'video/mp4' }); // -> { ext: 'mp4', mime: 'video/mp4' } | ||
mime('.fakeext', 'ogg'); // -> { ext: 'ogg', mime: 'audio/ogg' } | ||
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('.fakeext', 'ogg3'); // -> null | ||
mime('.fakeext', { ext: 'fake', mime: 'fake/fake' }); // -> { ext: 'fake', mime: 'fake/fake' } | ||
mime.sync('.fakeext', 'ogg3'); // -> null | ||
mime.sync('.fakeext', { ext: 'fake', mime: 'fake/fake' }); // -> null | ||
``` | ||
@@ -55,2 +95,2 @@ | ||
The MIT License (MIT)<br/> | ||
Copyright (c) 2015-2017 Alexey Bystrov | ||
Copyright (c) 2015-2019 Alexey Bystrov |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13022
5
269
92
8
1
+ Addedfile-type@12.4.2(transitive)
- Removedfile-type@4.4.0(transitive)
Updatedfile-type@^12.1.0
Updatedmime-types@^2.1.24