index.js 591 B

12345678910111213141516171819
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var callBound = require('call-bound');
  4. /** @type {undefined | ((thisArg: import('.').TypedArray) => Buffer<ArrayBufferLike>)} */
  5. var $typedArrayBuffer = callBound('TypedArray.prototype.buffer', true);
  6. var isTypedArray = require('is-typed-array');
  7. /** @type {import('.')} */
  8. // node <= 0.10, < 0.11.4 has a nonconfigurable own property instead of a prototype getter
  9. module.exports = $typedArrayBuffer || function typedArrayBuffer(x) {
  10. if (!isTypedArray(x)) {
  11. throw new $TypeError('Not a Typed Array');
  12. }
  13. return x.buffer;
  14. };