Package: effect
Module: Encoding
Decodes a hexadecimal string into bytes safely.
When to use
Use to decode hexadecimal text into bytes without throwing on invalid input.
Details
Returns Result.succeed with a Uint8Array when decoding succeeds, or
Result.fail with an EncodingError when the input has an odd length or
contains invalid hex characters.
Example (Decoding hex bytes)
import { Encoding, Result } from "effect"
const result = Encoding.decodeHex("48656c6c6f")
if (Result.isSuccess(result)) {
console.log(Array.from(result.success)) // [72, 101, 108, 108, 111]
}
Signature
declare const decodeHex: (str: string) => Result.Result<Uint8Array, EncodingError>
Since v2.0.0