Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

image-type

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-type - npm Package Compare versions

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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc