MCPcopy Index your code
hub / github.com/Effect-TS/effect / decode

Function decode

packages/effect/src/internal/encoding/hex.ts:16–35  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

14
15/** @internal */
16export const decode = (str: string): Either.Either<Uint8Array, Encoding.DecodeException> => {
17 const bytes = new TextEncoder().encode(str)
18 if (bytes.length % 2 !== 0) {
19 return Either.left(DecodeException(str, `Length must be a multiple of 2, but is ${bytes.length}`))
20 }
21
22 try {
23 const length = bytes.length / 2
24 const result = new Uint8Array(length)
25 for (let i = 0; i < length; i++) {
26 const a = fromHexChar(bytes[i * 2])
27 const b = fromHexChar(bytes[i * 2 + 1])
28 result[i] = (a << 4) | b
29 }
30
31 return Either.right(result)
32 } catch (e) {
33 return Either.left(DecodeException(str, e instanceof Error ? e.message : "Invalid input"))
34 }
35}
36
37/** @internal */
38const bytesToHex = [

Callers

nothing calls this directly

Calls 3

fromHexCharFunction · 0.85
encodeMethod · 0.80
DecodeExceptionFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…