effect-io-ai

Package: effect
Module: SchemaTransformation

SchemaTransformation.urlFromString

Decodes a string into a URL and encodes a URL back to its href string.

When to use

Use when you need a schema transformation to parse URL strings from user input or API responses.

Details

Decoding checks URL.canParse(s) and fails with InvalidValue if the string is not a valid URL. Encoding returns url.href.

Example (Converting a string to a URL)

import { Schema, SchemaTransformation } from "effect"

const schema = Schema.String.pipe(
  Schema.decodeTo(Schema.URL, SchemaTransformation.urlFromString)
)

See

Signature

declare const urlFromString: Transformation<URL, string, never, never>

Source

Since v4.0.0