defaultEndianness.js 606 B

123456789101112131415161718192021
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $Uint8Array = GetIntrinsic('%Uint8Array%', true);
  4. var $Uint32Array = GetIntrinsic('%Uint32Array%', true);
  5. var typedArrayBuffer = require('typed-array-buffer');
  6. var uInt32 = $Uint32Array && new $Uint32Array([0x12345678]);
  7. var uInt8 = uInt32 && new $Uint8Array(typedArrayBuffer(uInt32));
  8. module.exports = uInt8
  9. ? uInt8[0] === 0x78
  10. ? 'little'
  11. : uInt8[0] === 0x12
  12. ? 'big'
  13. : uInt8[0] === 0x34
  14. ? 'mixed' // https://developer.mozilla.org/en-US/docs/Glossary/Endianness
  15. : 'unknown' // ???
  16. : 'indeterminate'; // no way to know