(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"
}export const const decodeHexString: (
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"
}
decodeHexString = (str: stringstr: string) => import ResultResult.const map: {
<A, A2>(f: (ok: A) => A2): <E>(
self: Result<A, E>
) => Result<A2, E>
<A, E, A2>(
self: Result<A, E>,
f: (ok: A) => A2
): Result<A2, E>
}
map(const decodeHex: (
str: string
) => Result.Result<Uint8Array, EncodingError>
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]
}
decodeHex(str: stringstr), (_: Uint8Array<ArrayBufferLike>_) => const decoder: TextDecoderdecoder.TextDecoder.decode(input?: AllowSharedBufferSource, options?: TextDecodeOptions): stringThe TextDecoder.decode() method returns a string containing text decoded from the buffer passed as a parameter.
decode(_: Uint8Array<ArrayBufferLike>_))