Skip to content

Commit dbb1f7d

Browse files
committed
refactor: simplify/inline hex.js Uint8Array check
1 parent 8cab29a commit dbb1f7d

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

fallback/hex.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { assertUint8 } from '../assert.js'
21
import { E_STRING } from './_utils.js'
32
import { nativeDecoder, nativeEncoder, decode2string } from './platform.js'
43
import { encodeAscii, decodeAscii } from './latin1.js'
@@ -12,9 +11,8 @@ const allowed = '0123456789ABCDEFabcdef'
1211

1312
export const E_HEX = 'Input is not a hex string'
1413

14+
// Expects a checked Uint8Array
1515
export function toHex(arr) {
16-
assertUint8(arr)
17-
1816
if (!hexArray) hexArray = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'))
1917
const length = arr.length // this helps Hermes
2018

hex.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { assertUint8 } from './assert.js'
21
import { typedView } from './array.js'
32
import * as js from './fallback/hex.js'
43

54
const { toHex: webHex } = Uint8Array.prototype // Modern engines have this
65

76
export function toHex(arr) {
8-
assertUint8(arr)
7+
if (!(input instanceof Uint8Array)) throw new TypeError('Expected an Uint8Array')
98
if (arr.length === 0) return ''
109
if (webHex && arr.toHex === webHex) return arr.toHex()
1110
return js.toHex(arr)

0 commit comments

Comments
 (0)