{"id":16349462,"url":"https://github.com/jednano/location","last_synced_at":"2026-03-27T01:56:47.667Z","repository":{"id":34240726,"uuid":"172180779","full_name":"jednano/location","owner":"jednano","description":"A Location class that implements the Location interface of the Web API.","archived":false,"fork":false,"pushed_at":"2023-01-03T16:41:21.000Z","size":1506,"stargazers_count":10,"open_issues_count":12,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-03T04:29:44.837Z","etag":null,"topics":["api","location","typescript","typescript-library","web","web-api"],"latest_commit_sha":null,"homepage":null,"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/jednano.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}},"created_at":"2019-02-23T06:36:25.000Z","updated_at":"2025-06-02T00:30:52.000Z","dependencies_parsed_at":"2023-01-15T05:32:36.169Z","dependency_job_id":null,"html_url":"https://github.com/jednano/location","commit_stats":null,"previous_names":["jedmao/location"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/jednano/location","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jednano%2Flocation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jednano%2Flocation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jednano%2Flocation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jednano%2Flocation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jednano","download_url":"https://codeload.github.com/jednano/location/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jednano%2Flocation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31008495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-27T01:56:05.093Z","status":"ssl_error","status_checked_at":"2026-03-27T01:55:48.776Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["api","location","typescript","typescript-library","web","web-api"],"created_at":"2024-10-11T00:59:50.878Z","updated_at":"2026-03-27T01:56:47.647Z","avatar_url":"https://github.com/jednano.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @jedmao/location\n\n\u003c!-- markdownlint-disable --\u003e\n[![GitHub Actions](https://github.com/jedmao/location/workflows/Node%20CI/badge.svg?event=push)](https://github.com/jedmao/location/actions)\n[![NPM version](http://img.shields.io/npm/v/@jedmao/location.svg)](https://www.npmjs.org/package/@jedmao/location)\n[![npm license](http://img.shields.io/npm/l/@jedmao/location.svg)](https://www.npmjs.org/package/@jedmao/location)\n[![codecov](https://codecov.io/gh/jedmao/location/branch/master/graph/badge.svg)](https://codecov.io/gh/jedmao/location)\n[![BundlePhobia Minified](https://badgen.net/bundlephobia/min/@jedmao/location?label=min)](https://bundlephobia.com/result?p=@jedmao/location)\n[![BundlePhobia Minified + gzip](https://badgen.net/bundlephobia/minzip/@jedmao/location?label=min%2Bgzip\u0026)](https://bundlephobia.com/result?p=@jedmao/location)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![Unicorn Approved](https://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://twitter.com/sindresorhus/status/457989012528316416?ref_src=twsrc%5Etfw\u0026ref_url=https%3A%2F%2Fwww.quora.com%2FWhat-does-the-unicorn-approved-shield-mean-in-GitHub)\n\u003c!-- markdownlint-restore --\u003e\n\n\u003c!-- markdownlint-disable commands-show-output --\u003e\n\nA `LocationMock` class that extends [`URL`][] and implements the [`Location interface of the Web API`](https://developer.mozilla.org/en-US/docs/Web/API/Location). As always, with first-class TypeScript support!\n\n## Installation\n\n```bash\nnpm i --save-dev @jedmao/location\n```\n\n## Usage\n\n```ts\nimport { LocationMock } from '@jedmao/location'\n\nconst loc = new LocationMock('http://foo.com/')\nloc.assign('http://bar.com/')\nloc.replace('http://baz.com/')\nloc.reload()\n```\n\nBecause this package extends [`URL`][], many features are provided for free. This means you can do this:\n\n```ts\nnew LocationMock('http://jed:secret@test:42/foo?bar=baz#qux')\n```\n\nWhich returns the following object:\n\n```ts\nLocationMock {\n  href: 'http://jed:secret@test:42/foo?bar=baz#qux',\n  origin: 'http://test:42',\n  protocol: 'http:',\n  username: 'jed',\n  password: 'secret',\n  host: 'test:42',\n  hostname: 'test',\n  port: '42',\n  pathname: '/foo',\n  search: '?bar=baz',\n  searchParams: URLSearchParams { 'bar' =\u003e 'baz' },\n  hash: '#qux' }\n```\n\n### Mocking\n\nA common use for this package is to mock the `window.location`, which you can do in [Jest](https://jestjs.io/) like so:\n\n```ts\nconst { location: savedLocation } = window\n\nbeforeAll(() =\u003e {\n  delete window.location\n})\n\nbeforeEach(() =\u003e {\n  window.location = new LocationMock('http://test/')\n})\n\nafterAll(() =\u003e {\n  window.location = savedLocation\n})\n\nit('assigns /login', () =\u003e {\n  const assign = jest\n    .spyOn(window.location, 'assign')\n    .mockImplementationOnce(() =\u003e {})\n\n  window.location.assign('/login')\n\n  expect(assign).toHaveBeenCalledWith('/login')\n})\n```\n\n[`url`]: https://developer.mozilla.org/en-US/docs/Web/API/URL\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjednano%2Flocation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjednano%2Flocation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjednano%2Flocation/lists"}