npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

is-webp

2.0.0

@sindresorhus

npmHomeRepoSnykSocket
Downloads:2745
$ npm install is-webp
DailyWeeklyMonthlyYearly

is-webp

Check if a Buffer/Uint8Array is a WebP image

Install

npm install is-webp

Usage

Node.js
import {readChunk} from 'read-chunk';
import isWebp from 'is-webp';

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

isWebp(buffer);
//=> true
Browser
const xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.webp');
xhr.responseType = 'arraybuffer';

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

xhr.send();

API

isWebp(buffer)

Accepts a Buffer (Node.js) or Uint8Array.

It only needs the first 12 bytes.

Related

  • file-type - Detect the file type of a Buffer/Uint8Array
  • is-webp-extended - Extended version of this package which supports checking for animated WebP