{"id":22726702,"url":"https://github.com/tom-sherman/immurl","last_synced_at":"2025-07-14T12:38:20.870Z","repository":{"id":40762060,"uuid":"277089603","full_name":"tom-sherman/immurl","owner":"tom-sherman","description":"🔗 A tiny immutable URL library, backed by the native whatwg URL.","archived":false,"fork":false,"pushed_at":"2023-03-05T04:02:21.000Z","size":215,"stargazers_count":31,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T20:47:03.502Z","etag":null,"topics":["javascript","url"],"latest_commit_sha":null,"homepage":"https://immurl.netlify.app/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tom-sherman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-04T10:39:32.000Z","updated_at":"2025-01-31T02:34:08.000Z","dependencies_parsed_at":"2024-06-19T14:33:52.879Z","dependency_job_id":"ba0f084c-a882-444c-ae17-64b283672a6f","html_url":"https://github.com/tom-sherman/immurl","commit_stats":{"total_commits":29,"total_committers":4,"mean_commits":7.25,"dds":"0.24137931034482762","last_synced_commit":"3f06473db0f1831e0014dc6d946e09606a3616e9"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-sherman%2Fimmurl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-sherman%2Fimmurl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-sherman%2Fimmurl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-sherman%2Fimmurl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tom-sherman","download_url":"https://codeload.github.com/tom-sherman/immurl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248782279,"owners_count":21160716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","url"],"created_at":"2024-12-10T16:18:15.149Z","updated_at":"2025-04-13T20:47:09.824Z","avatar_url":"https://github.com/tom-sherman.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# immurl\r\n\r\n🔗 A tiny (\u003c 500B), 0-dependency, immutable URL library, backed by the native whatwg URL. 🎉 Now with immutable `Headers` support!\r\n\r\n## Install\r\n\r\n```\r\nnpm install immurl\r\n```\r\n\r\nBecause immurl uses the native whatwg URL API under the hood you'll need a polyfill to support environments that [don't implement this API](https://developer.mozilla.org/en-US/docs/Web/API/URL#Browser_compatibility) eg. IE11.\r\n\r\n## Usage\r\n\r\n### `ImmutableURL`\r\n\r\n`ImmutableURL` works as you expect, it contains all of the properties of the native [URL API](https://developer.mozilla.org/en-US/docs/Web/API/URL).\r\n\r\n```typescript\r\nimport { ImmutableURL } from 'immurl';\r\n\r\nconst url = new ImmutableURL('https://example.com');\r\n\r\nconsole.log(url.href); // 'https://example.com'\r\n\r\n// Set properties with the .set() method\r\n\r\nlet newUrl = url.set('pathname', '/login');\r\n\r\n// Because the set API is immutable you can chain calls to .set()\r\n\r\nnewUrl = url.set('pathname', '/bar').set('hash', '#heading'); // https://example.com/bar#heading\r\n```\r\n\r\n### `ImmutableURLSearchParams`\r\n\r\nimmurl also contains an immutable version of the [`URLSearchParams` API](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams); `ImmutableURLSearchParams`.\r\n\r\nThe API for `ImmutableURLSearchParams` is exactly the same as the native version except the methods that usually mutate (`.append()`, `.delete()`, `.sort()`) return a new `ImmutableURLSearchParams` instance.\r\n\r\n```typescript\r\nimport { ImmutableURLSearchParams } from 'immurl';\r\n\r\nlet params = new ImmutableURLSearchParams('q=URLUtils.searchParams\u0026topic=api');\r\n\r\nparams = params.append('foo', 'bar').delete('q'); // topic=api\u0026foo=bar\r\n```\r\n\r\nThe `searchParams` property of `ImmutableURL` returns an `ImmutableURLSearchParams`.\r\n\r\n```typescript\r\nconst url = new ImmutableURL('https://example.com?foo=bar');\r\n\r\nconst newParams = url.searchParams\r\n  .append('q', 'search-term')\r\n  .set('foo', 'fuz')\r\n  .sort();\r\n\r\n// url.searchParams is unaffected (thanks to immutability 🎉)\r\n\r\n// We can pass our newParams into url.set() to create a new url with the updated params\r\nconst newUrl = url.set('searchParams', newParams);\r\n\r\n// The following code is equvalent to the above\r\n\r\nconst newUrl2 = url.set(\r\n  'searchParams',\r\n  url.searchParams.append('q', 'search-term').set('foo', 'fuz').sort()\r\n);\r\n```\r\n\r\n### `ImmutableHeaders`\r\n\r\nNot strictly related to whatg URLs, but it's shoehorned in here because it's kinda related and they're usually used together.\r\n\r\n```typescript\r\nimport { ImmutableHeaders } from 'immurl';\r\n\r\nconst headers = new ImmutableHeaders({\r\n  foo: 'bar'\r\n});\r\n\r\nconst newHeaders = headers.set('foo', 'fuz');\r\n\r\nconsole.log(headers.get('foo')); // Logs \"bar\"\r\nconsole.log(newHeaders.get('foo')); // Logs \"fuz\"\r\n```\r\n\r\n## API\r\n\r\nSee the docs at https://immurl.netlify.app/\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftom-sherman%2Fimmurl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftom-sherman%2Fimmurl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftom-sherman%2Fimmurl/lists"}