Hyperlinkv0.8.0-beta.28

SchemaGetter

SchemaGetter.decodeHexStringfunctioneffect/SchemaGetter.ts:1423
<E extends string>(): Getter<string, E>

Decodes a hexadecimal string to a UTF-8 string.

Details

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

Example (Decoding hex to string)

import { SchemaGetter } from "effect"

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