Skip to content

Commit 4c33f6a

Browse files
author
David Wells
committed
refctor: use pathname
Signed-off-by: David Wells <>
1 parent 7e86cb7 commit 4c33f6a

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

packages/analytics-util-url/src/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ export function parseUrl(url = '') {
4646
protocol: match[1] || '',
4747
hostname: match[2] || '',
4848
port: match[3] || '',
49-
path: match[4] || '',
49+
pathname: match[4] || '',
5050
search: match[5] || '',
5151
hash: match[6] || '',
5252
}
5353
}
5454

55-
5655
/* export qss */
5756
export {
5857
encode,
@@ -61,7 +60,6 @@ export {
6160
decodeUri
6261
}
6362

64-
6563
/******************************************************************************************
6664
* Type checkers utilities
6765
******************************************************************************************/
@@ -154,8 +152,8 @@ export function getHost(url) {
154152
* > https://subdomain.my-site.com/path-to/page/here
155153
*/
156154
export function getUrl(url) {
157-
const { protocol, hostname, path } = getLocation(url)
158-
const page = `${protocol}://${hostname}${path}`
155+
const { protocol, hostname, pathname } = getLocation(url)
156+
const page = `${protocol}://${hostname}${pathname}`
159157
const last = page.charAt(page.length - 1)
160158
return (last === '/') ? page.slice(0, -1) : page
161159
}

packages/analytics-util-url/tests/api.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test('parseUrl', async () => {
3030
protocol: 'https',
3131
hostname: 'www.cool.com',
3232
port: '',
33-
path: '',
33+
pathname: '',
3434
search: '',
3535
hash: '',
3636
href: 'https://www.cool.com'
@@ -40,7 +40,7 @@ test('parseUrl', async () => {
4040
protocol: 'https',
4141
hostname: 'www.cool.com',
4242
port: '',
43-
path: '/my-path',
43+
pathname: '/my-path',
4444
search: '',
4545
hash: '',
4646
href: 'https://www.cool.com/my-path'
@@ -50,7 +50,7 @@ test('parseUrl', async () => {
5050
protocol: 'https',
5151
hostname: 'www.cool.com',
5252
port: '',
53-
path: '/my-path/here',
53+
pathname: '/my-path/here',
5454
search: '',
5555
hash: '',
5656
href: 'https://www.cool.com/my-path/here'
@@ -60,7 +60,7 @@ test('parseUrl', async () => {
6060
protocol: 'https',
6161
hostname: 'www.cool.com',
6262
port: '',
63-
path: '/my-path/here',
63+
pathname: '/my-path/here',
6464
search: 'hello=true',
6565
hash: '',
6666
href: 'https://www.cool.com/my-path/here?hello=true'
@@ -70,7 +70,7 @@ test('parseUrl', async () => {
7070
protocol: 'https',
7171
hostname: 'www.cool.com',
7272
port: '',
73-
path: '/my-path/here',
73+
pathname: '/my-path/here',
7474
search: 'hello=true',
7575
hash: 'my-hash=cool',
7676
href: 'https://www.cool.com/my-path/here?hello=true#my-hash=cool'
@@ -80,7 +80,7 @@ test('parseUrl', async () => {
8080
protocol: 'https',
8181
hostname: 'whatever.funky.cool.com',
8282
port: '',
83-
path: '',
83+
pathname: '',
8484
search: '',
8585
hash: '',
8686
href: 'https://whatever.funky.cool.com'
@@ -92,7 +92,7 @@ test('parseUrl', async () => {
9292
// protocol: 'NA',
9393
// hostname: 'NA',
9494
// port: 'NA',
95-
// path: 'NA',
95+
// pathname: 'NA',
9696
// search: 'NA',
9797
// hash: 'NA',
9898
// href: 'NA'

0 commit comments

Comments
 (0)