Hyperlinkv0.8.0-beta.28

SchemaGetter

SchemaGetter.decodeUriComponentfunctioneffect/SchemaGetter.ts:1479
<E extends string>(): Getter<string, E>

Decodes a URI component encoded string using decodeURIComponent.

Details

  • Fails with SchemaIssue.InvalidValue if the input contains malformed percent-encoding sequences.

Example (Decoding a URI component)

import { SchemaGetter } from "effect"

const decode = SchemaGetter.decodeUriComponent<string>()
// Getter<string, string>
export function decodeUriComponent<E extends string>(): Getter<string, E> {
  return transformOrFail((input) => {
    try {
      return Effect.succeed(globalThis.decodeURIComponent(input))
    } catch (e) {
      return Effect.fail(
        new SchemaIssue.InvalidValue(Option.some(input), {
          message: e instanceof URIError ? e.message : "Invalid URI component"
        })
      )
    }
  })
}
Referenced by 1 symbols