# is-jpg

> Check if a Buffer/Uint8Array is a JPEG image

Latest version **3.0.0** (published 2021-09-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-jpg
pnpm add is-jpg
yarn add is-jpg
bun add is-jpg
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2021-09-19 |
| First published | 2014-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 2.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 27 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | jpg, jpeg, image, picture, photo, type, detect, check, is, exif, binary, buffer, uint8array |

## Links

- npm: https://www.npmjs.com/package/is-jpg
- Repository: https://github.com/sindresorhus/is-jpg
- Homepage: https://github.com/sindresorhus/is-jpg#readme
- Issues: https://github.com/sindresorhus/is-jpg/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/is-jpg

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2021-09-19
- 2.0.0 — 2018-03-22
- 1.0.1 — 2018-03-22
- 1.0.0 — 2014-08-14
- 0.1.2 — 2014-04-29
- 0.1.1 — 2014-04-25
- 0.1.0 — 2014-04-21

## README

# is-jpg

> Check if a Buffer/Uint8Array is a [JPEG](https://en.wikipedia.org/wiki/JPEG) image

## Install

```sh
npm install is-jpg
```

## Usage

##### Node.js

```js
import {readChunk} from 'read-chunk';
import isJpg from 'is-jpg';

const buffer = await readChunk('unicorn.jpg', {length: 3});

isJpg(buffer);
//=> true
```

##### Browser

```js
const xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.jpg');
xhr.responseType = 'arraybuffer';

xhr.onload = () => {
	isJpg(new Uint8Array(this.response));
	//=> true
};

xhr.send();
```

## API

### isJpg(buffer)

Accepts a `Buffer` (Node.js) or `Uint8Array`.

It only needs the first 3 bytes.

## Related

- [file-type](https://github.com/sindresorhus/file-type) - Detect the file type of a Buffer/Uint8Array

---
_Source: https://npm.io/package/is-jpg · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
