Hyperlinkv0.8.0-beta.28

SchemaGetter

SchemaGetter.decodeHexfunctioneffect/SchemaGetter.ts:1392
<E extends string>(): Getter<Uint8Array, E>

Decodes a hexadecimal string to a Uint8Array.

Details

  • Fails with SchemaIssue.InvalidValue if the input is not valid hex.

Example (Decoding hex to bytes)

import { SchemaGetter } from "effect"

const decode = SchemaGetter.decodeHex<string>()
// Getter<Uint8Array, string>
export function decodeHex<E extends string>(): Getter<Uint8Array, E> {
  return transformOrFail((input) =>
    Result.match(Encoding.decodeHex(input), {
      onFailure: (e) => Effect.fail(new SchemaIssue.InvalidValue(Option.some(input), { message: e.message })),
      onSuccess: Effect.succeed
    })
  )
}
Referenced by 1 symbols