function dataToUint8Array(data) {
  let uint8array
  if (data instanceof ArrayBuffer || Array.isArray(data)) {
    uint8array = new Uint8Array(data)
  } else if (ArrayBuffer.isView(data)) { // DataView or TypedArray
    uint8array = new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
  } else if (data instanceof Buffer) { // Node.js Buffer
    uint8array = new Uint8Array(data.buffer, data.byteOffset, data.length)
  } else {
    throw Error('Data is not an ArrayBuffer, TypedArray, DataView or a Node.js Buffer.')
  }
  return uint8array
}
/** It will not copy underlying buffers, instead it will create a view into them. */
It will not copy underlying buffers, instead it will create a view into them.
It will not copy underlying buffers instead it will create a view into them .
function dataToUint8Array(data) {
  let uint8array
  if (data instanceof ArrayBuffer || Array.isArray(data)) {
    uint8array = new Uint8Array(data)
  } else if (ArrayBuffer.isView(data)) { 
    uint8array = new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
  } else if (data instanceof Buffer) { 
    uint8array = new Uint8Array(data.buffer, data.byteOffset, data.length)
  } else {
    throw Error('Data is not an ArrayBuffer, TypedArray, DataView or a Node.js Buffer.')
  }
  return uint8array
}
function dataToUint8Array ( data ) { let uint8array if ( data instanceof ArrayBuffer || Array . isArray ( data ) ) { uint8array = new Uint8Array ( data ) } else if ( ArrayBuffer . isView ( data ) ) { uint8array = new Uint8Array ( data . buffer , data . byteOffset , data . byteLength ) } else if ( data instanceof Buffer ) { uint8array = new Uint8Array ( data . buffer , data . byteOffset , data . length ) } else { throw Error ( 'Data is not an ArrayBuffer, TypedArray, DataView or a Node.js Buffer.' ) } return uint8array }
It will not copy underlying buffers, instead it will create a view into them.
It will not copy underlying buffers instead it will create a view into them .
// DataView or TypedArray // Node.js Buffer