Skip to main content

URI helpers

Package: @antithrow/std

Non-throwing wrappers around globalThis.encodeURI, encodeURIComponent, decodeURI, decodeURIComponent.

encodeURI(uri)

function encodeURI(uri: string): Settled<string, URIError>;

decodeURI(encodedURI)

function decodeURI(encodedURI: string): Settled<string, URIError>;

encodeURIComponent(component)

function encodeURIComponent(
uriComponent: string | number | boolean,
): Settled<string, URIError>;

decodeURIComponent(encodedURIComponent)

function decodeURIComponent(encodedURIComponent: string): Settled<string, URIError>;

Each returns Err(URIError) for malformed input (for example, an orphaned % sequence).

Throws

Never.

Example

import { encodeURI, decodeURIComponent } from "@antithrow/std";

encodeURI("https://example.com/hello world");
decodeURIComponent("hello%20world");