is-little-endian.ts 430 B

1234567891011121314
  1. /**
  2. * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. export function isLittleEndian() {
  7. const arrayBuffer = new ArrayBuffer(2);
  8. const uint8Array = new Uint8Array(arrayBuffer);
  9. const uint16array = new Uint16Array(arrayBuffer);
  10. uint8Array[0] = 0xAA;
  11. uint8Array[1] = 0xBB;
  12. return uint16array[0] === 0xBBAA;
  13. }