is-array-buffer.js 852 B

123456789101112131415161718192021222324252627282930313233
  1. /*!
  2. * isArrayBuffer v1.0.0
  3. * https://github.com/fengyuanchen/is-array-buffer
  4. *
  5. * Copyright (c) 2015-2017 Chen Fengyuan
  6. * Released under the MIT license
  7. *
  8. * Date: 2017-07-26T11:00:44.931Z
  9. */
  10. 'use strict'
  11. // temporary workaround for https://github.com/octokit/rest.js/issues/774
  12. const hasArrayBuffer = typeof ArrayBuffer === 'function'
  13. const toString = Object.prototype.toString
  14. /**
  15. * Check if the given value is an ArrayBuffer.
  16. * @param {*} value - The value to check.
  17. * @returns {boolean} Returns `true` if the given is an ArrayBuffer, else `false`.
  18. * @example
  19. * isArrayBuffer(new ArrayBuffer())
  20. * // => true
  21. * isArrayBuffer(new Array())
  22. * // => false
  23. */
  24. function isArrayBuffer (value) {
  25. return hasArrayBuffer && (value instanceof ArrayBuffer || toString.call(value) === '[object ArrayBuffer]')
  26. }
  27. module.exports = isArrayBuffer