image-type
Advanced tools
Comparing version 2.1.0 to 3.0.0
29
index.js
'use strict'; | ||
var fileType = require('file-type'); | ||
const fileType = require('file-type'); | ||
module.exports = function (buf) { | ||
var imageExts = [ | ||
'jpg', | ||
'png', | ||
'gif', | ||
'webp', | ||
'tif', | ||
'bmp', | ||
'jxr', | ||
'psd' | ||
]; | ||
const imageExts = new Set([ | ||
'jpg', | ||
'png', | ||
'gif', | ||
'webp', | ||
'tif', | ||
'bmp', | ||
'jxr', | ||
'psd' | ||
]); | ||
var ret = fileType(buf); | ||
return imageExts.indexOf(ret && ret.ext) !== -1 ? ret : null; | ||
module.exports = input => { | ||
const ret = fileType(input); | ||
return imageExts.has(ret && ret.ext) ? ret : null; | ||
}; |
{ | ||
"name": "image-type", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Detect the image type of a Buffer/Uint8Array", | ||
@@ -12,17 +12,12 @@ "license": "MIT", | ||
}, | ||
"bin": "cli.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"cli.js" | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"cli-app", | ||
"cli", | ||
"bin", | ||
"image", | ||
@@ -53,9 +48,9 @@ "img", | ||
"dependencies": { | ||
"file-type": "^3.0.0", | ||
"meow": "^3.3.0" | ||
"file-type": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"read-chunk": "^1.0.0" | ||
"ava": "*", | ||
"read-chunk": "^2.0.0", | ||
"xo": "*" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # image-type [![Build Status](https://travis-ci.org/sindresorhus/image-type.svg?branch=master)](https://travis-ci.org/sindresorhus/image-type) | ||
See the [file-type](https://github.com/sindresorhus/file-type) module for more file types. | ||
See the [`file-type`](https://github.com/sindresorhus/file-type) module for more file types and a CLI. | ||
@@ -11,3 +11,3 @@ | ||
```sh | ||
``` | ||
$ npm install --save image-type | ||
@@ -22,5 +22,5 @@ ``` | ||
```js | ||
var readChunk = require('read-chunk'); // npm install read-chunk | ||
var imageType = require('image-type'); | ||
var buffer = readChunk.sync('unicorn.png', 0, 12); | ||
const readChunk = require('read-chunk'); // npm install read-chunk | ||
const imageType = require('image-type'); | ||
const buffer = readChunk.sync('unicorn.png', 0, 12); | ||
@@ -31,11 +31,11 @@ imageType(buffer); | ||
or from a remote location: | ||
Or from a remote location: | ||
```js | ||
var http = require('http'); | ||
var imageType = require('image-type'); | ||
var url = 'http://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif'; | ||
const http = require('http'); | ||
const imageType = require('image-type'); | ||
const url = 'http://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif'; | ||
http.get(url, function (res) { | ||
res.once('data', function (chunk) { | ||
http.get(url, res => { | ||
res.once('data', chunk => { | ||
res.destroy(); | ||
@@ -51,7 +51,7 @@ console.log(imageType(chunk)); | ||
```js | ||
var xhr = new XMLHttpRequest(); | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('GET', 'unicorn.png'); | ||
xhr.responseType = 'arraybuffer'; | ||
xhr.onload = function () { | ||
xhr.onload = () => { | ||
imageType(new Uint8Array(this.response)); | ||
@@ -67,35 +67,18 @@ //=> {ext: 'png', mime: 'image/png'} | ||
### imageType(buffer) | ||
### imageType(input) | ||
Returns an object (or `null` when no match) with: | ||
Returns an `Object` with: | ||
- `ext` - one of the [supported file types](#supported-file-types) | ||
- `mime` - the [MIME type](http://en.wikipedia.org/wiki/Internet_media_type) | ||
- `ext` - One of the [supported file types](#supported-file-types) | ||
- `mime` - The [MIME type](http://en.wikipedia.org/wiki/Internet_media_type) | ||
#### buffer | ||
Or `null` when no match. | ||
Type: `buffer` *(Node.js)*, `uint8array` | ||
#### input | ||
Type: `Buffer` `Uint8Array` | ||
It only needs the first 12 bytes. | ||
## CLI | ||
```sh | ||
$ npm install --global image-type | ||
``` | ||
```sh | ||
$ image-type --help | ||
Usage | ||
image-type <filename> | ||
cat <filename> | image-type | ||
Example | ||
cat unicorn.png | image-type | ||
png | ||
``` | ||
## Supported file types | ||
@@ -117,2 +100,2 @@ | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
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
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
1
4016
3
4
16
95
+ Addedfile-type@4.4.0(transitive)
- Removedmeow@^3.3.0
- Removedarray-find-index@1.0.2(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedcamelcase-keys@2.1.0(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedfile-type@3.9.0(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedindent-string@2.1.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedmap-obj@1.0.1(transitive)
- Removedmeow@3.7.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedredent@1.0.0(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-indent@1.0.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtrim-newlines@1.0.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
Updatedfile-type@^4.1.0