@hyperfrontend/immutable-api-utils/built-in-copy/url

url

Locked, prototype-pollution-resistant copies of the global URL and URLSearchParams constructors.

Factory wrappers for URL and URLSearchParams are captured at module-load time and frozen into a tamper-proof namespace, so URL parsing and query-string handling continue to behave correctly even if the globals are later patched. Effective only when imported before any untrusted code has had a chance to mutate the prototype chain.

API Reference

ƒ Functions

§function

createURL(url: string | URL, base?: string | URL): URL

(Safe copy) Creates a new URL using the captured URL constructor. Use this instead of new URL().

Parameters

NameTypeDescription
§url
string | URL
The URL string to parse.
§base?
string | URL
Optional base URL for relative URLs.

Returns

URL
A new URL instance.

Example

Creating URL instances

const absolute = createURL('https://example.com/path?query=1')
const relative = createURL('/api/users', 'https://example.com')
// => URL { href: 'https://example.com/api/users' }
§function

createURLSearchParams(init?: string | URLSearchParams | Record<string, string> | Iterable<[string, string], any, any>): URLSearchParams

(Safe copy) Creates a new URLSearchParams using the captured URLSearchParams constructor. Use this instead of new URLSearchParams().

Parameters

NameTypeDescription
§init?
string | URLSearchParams | Record<string, string> | Iterable<[string, string], any, any>
Optional initialization value (string, object, or iterable).

Returns

URLSearchParams
A new URLSearchParams instance.

Example

Creating URLSearchParams

const fromString = createURLSearchParams('page=1&limit=10')
const fromObject = createURLSearchParams({ page: '1', limit: '10' })
fromObject.get('page') // => '1'

Variables

§type

canParse

(Safe copy) Returns whether the provided string is a valid URL. Use this instead of URL.canParse().
§type

createObjectURL

(Safe copy) Creates an object URL for the given object. Use this instead of URL.createObjectURL().
Note: This is a browser-only API. In Node.js environments, this will throw.
§type

parseURL

(Safe copy) Parses a URL string and returns a URL object, or null if invalid. Use this instead of URL.parse().
§type

revokeObjectURL

(Safe copy) Revokes an object URL previously created with createObjectURL. Use this instead of URL.revokeObjectURL().
Note: This is a browser-only API. In Node.js environments, this will throw.
§type

URL

(Safe copy) Namespace object containing all URL utilities. Note: Importing this imports all methods in this namespace (no tree-shaking).