is-empty-array-buffer
Version:
Check if the given value is an empty array buffer.
29 lines (24 loc) • 861 B
JavaScript
var hasArrayBuffer = typeof ArrayBuffer === 'function';
var toString = Object.prototype.toString;
/**
* Check if the given value is an ArrayBuffer.
* @param {*} value - The value to check.
* @returns {boolean} Returns `true` if the given value is an ArrayBuffer, else `false`.
* @example
* isArrayBuffer(new ArrayBuffer())
* // => true
* isArrayBuffer([])
* // => false
*/
function isArrayBuffer(value) {
return hasArrayBuffer && (value instanceof ArrayBuffer || toString.call(value) === '[object ArrayBuffer]');
}
/**
* Check if the given value is an empty array buffer.
* @param {*} value - The value to check.
* @returns {boolean} Returns `true` if the given value is an empty array buffer, else `false`.
*/
function isEmptyArrayBuffer(value) {
return isArrayBuffer(value) && value.byteLength === 0;
}
export default isEmptyArrayBuffer;