UNPKG

is-empty-array-buffer

Version:
47 lines (39 loc) 1.39 kB
/*! * isEmptyArrayBuffer v1.0.0 * https://github.com/fengyuanchen/is-empty-array-buffer * * Copyright 2018-present Chen Fengyuan * Released under the MIT license * * Date: 2018-05-23T12:31:03.669Z */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.isEmptyArrayBuffer = factory()); }(this, (function () { 'use strict'; 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; } return isEmptyArrayBuffer; })));