Hyperlinkv0.8.0-beta.28

Config

Config.urlfunctioneffect/Config.ts:1328
(name?: string): Config<URL>

Creates a config for a URL value parsed from a string.

When to use

Use to read configuration values that must be valid URL strings.

Details

This is a shortcut for Config.schema(Schema.URL, name).

Gotchas

Fails if the string cannot be parsed by the URL constructor.

Example (Reading a URL)

import { Config, ConfigProvider, Effect } from "effect"

const program = Effect.gen(function*() {
  const url = yield* Config.url("URL")
  console.log(url)
})

const provider = ConfigProvider.fromEnv({
  env: {
    URL: "https://example.com"
  }
})

Effect.runSync(
  program.pipe(Effect.provideService(ConfigProvider.ConfigProvider, provider))
)
// Output:
// URL {
//   href: 'https://example.com/',
//   origin: 'https://example.com',
//   protocol: 'https:',
//   username: '',
//   password: '',
//   host: 'example.com',
//   hostname: 'example.com',
//   port: '',
//   pathname: '/',
//   search: '',
//   searchParams: URLSearchParams {},
//   hash: ''
// }
constructorsschema
Source effect/Config.ts:13283 lines
export function url(name?: string) {
  return schema(Schema.URL, name)
}