Skip to content

Commit

Permalink
fix: ArrayBuffer.isView may not be available everywhere (#33)
Browse files Browse the repository at this point in the history
Fixes #1134
  • Loading branch information
gkatsev authored Mar 16, 2022
1 parent b7f2765 commit bff9147
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/byte-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ export const countBits = (x) => x.toString(2).length;
// count the number of whole bytes it would take to represent a number
export const countBytes = (x) => Math.ceil(countBits(x) / 8);
export const padStart = (b, len, str = ' ') => (repeat(str, len) + b.toString()).slice(-len);
export const isTypedArray = (obj) => ArrayBuffer.isView(obj);
export const isArrayBufferView = (obj) => {
if (ArrayBuffer.isView === 'function') {
return ArrayBuffer.isView(obj);
}

return obj && obj.buffer instanceof ArrayBuffer;
};
export const isTypedArray = (obj) => isArrayBufferView(obj);

export const toUint8 = function(bytes) {
if (bytes instanceof Uint8Array) {
Expand Down

0 comments on commit bff9147

Please sign in to comment.