@hyperfrontend/immutable-api-utils/built-in-copy/urlurl
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
(Safe copy) Creates a new URL using the captured URL constructor. Use this instead of
new URL().Parameters
Returns
URLA 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
| Name | Type | Description |
|---|---|---|
§init? | string | URLSearchParams | Record<string, string> | Iterable<[string, string], any, any> | Optional initialization value (string, object, or iterable). |
Returns
URLSearchParamsA 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
(Safe copy) Returns whether the provided string is a valid URL. Use this instead of
URL.canParse().(Safe copy) Creates an object URL for the given object. Use this instead of
Note: This is a browser-only API. In Node.js environments, this will throw.
URL.createObjectURL(). Note: This is a browser-only API. In Node.js environments, this will throw.
(Safe copy) Parses a URL string and returns a URL object, or null if invalid. Use this instead of
URL.parse().(Safe copy) Revokes an object URL previously created with createObjectURL. Use this instead of
Note: This is a browser-only API. In Node.js environments, this will throw.
URL.revokeObjectURL(). Note: This is a browser-only API. In Node.js environments, this will throw.
(Safe copy) Namespace object containing all URL utilities. Note: Importing this imports all methods in this namespace (no tree-shaking).