Skip to content

url

const url: TypedPrimitive<string>

URL primitive. Validates using the WHATWG URL constructor and returns the normalized href (trailing slash, lowercased scheme + host).

Only http: and https: schemes are accepted by default.

Example:

url("https://example.com") // "https://example.com/"
url("https://example.com/path") // "https://example.com/path"
url("ftp://example.com") // throws (scheme not allowed)
url("not a url") // throws

Throws:

When the raw value fails this primitive’s validation.

Learn: Primitives and builders

Last updated: