1. is-jpg
Check if a Buffer/Uint8Array is a JPEG image
is-jpg
Package: is-jpg
Created by: sindresorhus
Last modified: Sun, 19 Jun 2022 02:44:11 GMT
Version: 3.0.0
License: MIT
Downloads: 2,582,876
Repository: https://github.com/sindresorhus/is-jpg

Install

npm install is-jpg
yarn add is-jpg

is-jpg

Check if a Buffer/Uint8Array is a JPEG image

Install

 npm install is-jpg

Usage

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

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

isJpg(buffer);
//=> true
Browser
 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.

  • file-type - Detect the file type of a Buffer/Uint8Array

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin