Socket
Socket
Sign inDemoInstall

is-jpg

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 2.0.0

10

index.js
'use strict';
module.exports = function (buf) {
if (!buf || buf.length < 3) {
module.exports = buffer => {
if (!buffer || buffer.length < 3) {
return false;
}
return buf[0] === 255 &&
buf[1] === 216 &&
buf[2] === 255;
return buffer[0] === 255 &&
buffer[1] === 216 &&
buffer[2] === 255;
};
{
"name": "is-jpg",
"version": "1.0.1",
"version": "2.0.0",
"description": "Check if a Buffer/Uint8Array is a JPEG image",

@@ -10,9 +10,9 @@ "license": "MIT",

"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
"node": ">=6"
},
"scripts": {
"test": "mocha"
"test": "xo && ava"
},

@@ -42,5 +42,6 @@ "files": [

"devDependencies": {
"mocha": "*",
"read-chunk": "^1.0.0"
"ava": "*",
"read-chunk": "^2.1.0",
"xo": "*"
}
}
# is-jpg [![Build Status](https://travis-ci.org/sindresorhus/is-jpg.svg?branch=master)](https://travis-ci.org/sindresorhus/is-jpg)
> Check if a Buffer/Uint8Array is a [JPEG](http://en.wikipedia.org/wiki/JPEG) image
> Check if a Buffer/Uint8Array is a [JPEG](https://en.wikipedia.org/wiki/JPEG) image
Used by [image-type](https://github.com/sindresorhus/image-type).
## Install
```sh
$ npm install --save is-jpg
```
$ npm install is-jpg
```

@@ -20,5 +18,5 @@

```js
var readChunk = require('read-chunk'); // npm install read-chunk
var isJpg = require('is-jpg');
var buffer = readChunk.sync('unicorn.jpg', 0, 3);
const readChunk = require('read-chunk');
const isJpg = require('is-jpg');
const buffer = readChunk.sync('unicorn.jpg', 0, 3);

@@ -32,7 +30,7 @@ isJpg(buffer);

```js
var xhr = new XMLHttpRequest();
const xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.jpg');
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
xhr.onload = () => {
isJpg(new Uint8Array(this.response));

@@ -55,4 +53,9 @@ //=> true

## Related
- [file-type](https://github.com/sindresorhus/file-type) - Detect the file type of a Buffer/Uint8Array
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc