Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ImmutableURL

Identical to the native URL interface except that all mutable properties are readonly. To change any of these properties instead you should call the .set() method which will return a new ImmutableURL object.

All properties are identical to their native counterparts except searchParams which instead is a ImmutableURLSearchParams whose methods are all fully immutable.

let url = new ImmutableURL('http://example.com');
url = url.set('path', '/foo'); // = ImmutableURL { http://example.com/foo }

To modify the search params you can call the immutable methods on searchParams to return a new ImmutableURLSearchParams which can then be passed to .set()

const newSearchParams = url.searchParams.append('foo', 'bar');

url = url.set('searchParams', newSearchParams);

// Or a shorthand

url = url.set('searchParams', url.searchParams.append('foo', 'bar'));

Hierarchy

  • ImmutableURL

Implements

  • {}

Index

Constructors

constructor

  • Parameters

    • url: URL

    Returns ImmutableURL

  • Parameters

    • url: string
    • Optional base: string | URL

    Returns ImmutableURL

Properties

Readonly hash

hash: string

Readonly host

host: string

Readonly hostname

hostname: string

Readonly href

href: string

Readonly origin

origin: string

Readonly password

password: string

Readonly pathname

pathname: string

Readonly port

port: string

Readonly protocol

protocol: string

Readonly search

search: string

Readonly searchParams

Readonly username

username: string

Methods

set

  • Type parameters

    • P: Exclude<keyof URL, "toJSON" | "origin">

    Parameters

    • property: P

      The property of the URL to set

    • newValue: URL[P]

      The new value

    Returns ImmutableURL

toJSON

  • toJSON(): string
  • Returns string

toString

  • toString(): string
  • Returns string

Generated using TypeDoc