Socket
Socket
Sign inDemoInstall

@jedmao/location

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.3 to 2.0.4

7

CHANGELOG.md

@@ -6,2 +6,9 @@ # Changelog

## [2.0.4](https://github.com/jedmao/location/compare/v2.0.3...v2.0.4) (2019-09-25)
### Bug Fixes
* add docs, tests ([36ad608](https://github.com/jedmao/location/commit/36ad608))
## [2.0.3](https://github.com/jedmao/location/compare/v2.0.2...v2.0.3) (2019-09-25)

@@ -8,0 +15,0 @@

7

package.json
{
"name": "@jedmao/location",
"version": "2.0.3",
"version": "2.0.4",
"description": "A Location class that implements the Location interface of the Web API.",

@@ -71,2 +71,5 @@ "main": "dist/Location.js",

},
"globals": {
"window": {}
},
"watchPlugins": [

@@ -93,3 +96,3 @@ "jest-watch-typeahead/filename",

"@commitlint/config-conventional": "^8.2.0",
"@jedmao/semantic-release-npm-github-config": "^1.0.6",
"@jedmao/semantic-release-npm-github-config": "^1.0.7",
"@jedmao/tsconfig": "^0.3.0",

@@ -96,0 +99,0 @@ "@types/jest": "^24.0.18",

# @jedmao/location
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->

@@ -14,7 +13,6 @@ [![GitHub Actions](https://github.com/jedmao/location/workflows/master/badge.svg)](https://github.com/jedmao/location/actions)

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- markdownlint-disable commands-show-output -->
A `Location` class that implements the [`Location interface of the Web API`](https://developer.mozilla.org/en-US/docs/Web/API/Location).
A `Location` 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!

@@ -37,1 +35,57 @@ ## Installation

```
Because this package extends [`URL`][], many features are provided for free. This means you can do this:
```ts
new Location('http://jed:secret@test:42/foo?bar=baz#qux')
```
Which returns the following object:
```ts
Location {
href: 'http://jed:secret@test:42/foo?bar=baz#qux',
origin: 'http://test:42',
protocol: 'http:',
username: 'jed',
password: 'secret',
host: 'test:42',
hostname: 'test',
port: '42',
pathname: '/foo',
search: '?bar=baz',
searchParams: URLSearchParams { 'bar' => 'baz' },
hash: '#qux' }
```
### Mocking
A common use for this package is to mock the `window.location`, which you can do in [Jest](https://jestjs.io/) like so:
```ts
const { location: savedLocation } = window
beforeAll(() => {
delete window.location
})
beforeEach(() => {
window.location = new Location('http://test/')
})
afterAll(() => {
window.location = savedLocation
})
it('assigns /login', () => {
const assign = jest
.spyOn(window.location, 'assign')
.mockImplementationOnce(() => {})
window.location.assign('/login')
expect(assign).toHaveBeenCalledWith('/login')
})
```
[`url`]: https://developer.mozilla.org/en-US/docs/Web/API/URL
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc