(src: string | Uint8Array | ArrayBuffer)
| 55 | * ``` |
| 56 | */ |
| 57 | export function encodeHex(src: string | Uint8Array | ArrayBuffer): string { |
| 58 | if (typeof src === "string") { |
| 59 | src = new TextEncoder().encode(src) as Uint8Array_; |
| 60 | } else if (src instanceof ArrayBuffer) src = new Uint8Array(src).slice(); |
| 61 | else src = src.slice(); |
| 62 | const [output, i] = detach( |
| 63 | src as Uint8Array_, |
| 64 | calcSizeHex((src as Uint8Array_).length), |
| 65 | ); |
| 66 | encode(output, i, 0, alphabet); |
| 67 | return new TextDecoder().decode(output); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Decodes the given hex-encoded string. If the input is malformed, an error is |
no test coverage detected