
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
is-array-buffer
Advanced tools
The is-array-buffer npm package is a simple utility that allows you to check if a given value is an ArrayBuffer. It is useful when dealing with binary data in JavaScript, as it helps ensure that the data being processed is in the expected format.
Check if a value is an ArrayBuffer
This feature allows you to verify whether a given value is an instance of ArrayBuffer. It is particularly useful when working with APIs that expect binary data and you need to validate the input.
const isArrayBuffer = require('is-array-buffer');
const buffer = new ArrayBuffer(8);
const result = isArrayBuffer(buffer); // result will be true
The is-typedarray package is similar to is-array-buffer in that it checks if a value is a TypedArray, which is closely related to ArrayBuffer. It differs in that it specifically checks for TypedArray instances rather than ArrayBuffers.
The buffer package includes a method called Buffer.isBuffer which checks if an object is a Node.js Buffer, which is a way to handle binary data in Node.js. This is similar to is-array-buffer but is specific to Node.js Buffers rather than ArrayBuffers.
Similar to the buffer package, is-buffer provides a function to check if an object is a Buffer. It is designed to work in both Node.js and browser environments, making it a bit more versatile than the buffer package's Buffer.isBuffer method.
Is this value a JS ArrayBuffer? This module works cross-realm/iframe, does not depend on instanceof
or mutable properties, and despite ES6 Symbol.toStringTag.
var assert = require('assert');
var isArrayBuffer = require('is-array-buffer');
assert(!isArrayBuffer(function () {}));
assert(!isArrayBuffer(null));
assert(!isArrayBuffer(function* () { yield 42; return Infinity; });
assert(!isArrayBuffer(Symbol('foo')));
assert(!isArrayBuffer(1n));
assert(!isArrayBuffer(Object(1n)));
assert(!isArrayBuffer(new Set()));
assert(!isArrayBuffer(new WeakSet()));
assert(!isArrayBuffer(new Map()));
assert(!isArrayBuffer(new WeakMap()));
assert(!isArrayBuffer(new WeakRef({})));
assert(!isArrayBuffer(new FinalizationRegistry(() => {})));
assert(!isArrayBuffer(new SharedArrayBuffer()));
assert(isArrayBuffer(new ArrayBuffer()));
class MyArrayBuffer extends ArrayBuffer {}
assert(isArrayBuffer(new MyArrayBuffer()));
Simply clone the repo, npm install
, and run npm test
FAQs
Is this value a JS ArrayBuffer?
The npm package is-array-buffer receives a total of 0 weekly downloads. As such, is-array-buffer popularity was classified as not popular.
We found that is-array-buffer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.