Skip to content

Commit

Permalink
utils: improve isBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Dec 10, 2023
1 parent c2d7a3e commit 93ade96
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/_assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function bool(b: boolean) {
if (typeof b !== 'boolean') throw new Error(`boolean expected, not ${b}`);
}

// TODO: merge with utils
function isBytes(a: unknown): a is Uint8Array {
return (
a != null &&
Expand Down
5 changes: 2 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ export const u32 = (arr: TypedArray) =>

function isBytes(a: unknown): a is Uint8Array {
return (
a != null &&
typeof a === 'object' &&
(a instanceof Uint8Array || a.constructor.name === 'Uint8Array')
a instanceof Uint8Array ||
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')
);
}

Expand Down

0 comments on commit 93ade96

Please sign in to comment.