MCPcopy Create free account
hub / github.com/denoland/std / encodeHex

Function encodeHex

encoding/hex.ts:57–68  ·  view source on GitHub ↗
(src: string | Uint8Array | ArrayBuffer)

Source from the content-addressed store, hash-verified

55 * ```
56 */
57export 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

Callers 7

hex_test.tsFile · 0.90
crypto_test.tsFile · 0.90
signCookieFunction · 0.90

Calls 4

detachFunction · 0.90
calcSizeHexFunction · 0.90
encodeFunction · 0.90
sliceMethod · 0.45

Tested by

no test coverage detected