Hyperlinkv0.8.0-beta.28

Encoding

Encoding.decodeHexStringconsteffect/Encoding.ts:509
(str: string): Result.Result<string, EncodingError>

Decodes a hexadecimal string into a UTF-8 string safely.

When to use

Use to decode hexadecimal text into UTF-8 text without throwing on invalid input.

Details

Returns Result.succeed with the decoded text when decoding succeeds, or Result.fail with an EncodingError when the input is not valid hex.

Example (Decoding hex strings)

import { Encoding, Result } from "effect"

const result = Encoding.decodeHexString("68656c6c6f")
if (Result.isSuccess(result)) {
  console.log(result.success) // "hello"
}
decoding
export const decodeHexString = (str: string) => Result.map(decodeHex(str), (_) => decoder.decode(_))
Referenced by 1 symbols