What is is-buffer?
The is-buffer npm package is a simple utility module used to determine if an object is a Node.js Buffer. This package is particularly useful when working with modules that are designed to work both in the browser and Node.js, where the Buffer class is not available in the global scope in the browser.
What are is-buffer's main functionalities?
Buffer Detection
This feature allows you to check if a given object is an instance of a Buffer. The function returns true if the object is a Buffer, and false otherwise.
var isBuffer = require('is-buffer');
var buffer = new Buffer('This is a buffer');
var notBuffer = {};
console.log(isBuffer(buffer)); // true
console.log(isBuffer(notBuffer)); // false
Other packages similar to is-buffer
buffer
The 'buffer' package is a Node.js Buffer implementation for the browser. It's more complex than is-buffer as it aims to provide the entire Buffer API in environments that do not have it natively. Unlike is-buffer, which only checks if an object is a Buffer, the 'buffer' package allows you to create and manipulate Buffer objects in the browser.
is-buffer
Why not use Buffer.isBuffer
?
This module lets you check if an object is a Buffer
without using Buffer.isBuffer
(which includes the whole buffer module in browserify).
It's future-proof and works in node too!
install
npm install is-buffer
usage
var isBuffer = require('is-buffer')
isBuffer(new Buffer(4))
isBuffer(Buffer.alloc(4))
isBuffer(undefined)
isBuffer(null)
isBuffer('')
isBuffer(true)
isBuffer(false)
isBuffer(0)
isBuffer(1)
isBuffer(1.0)
isBuffer('string')
isBuffer({})
isBuffer(function foo () {})
license
MIT. Copyright (C) Feross Aboukhadijeh.