-
-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Organize url helpers in a single file and rename "mergeQueryStringsWi…
…thData" to "mergeQueryStringWithData"
- Loading branch information
Showing
9 changed files
with
37 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
export { default as hrefToUrl } from './hrefToUrl' | ||
export { default as Inertia } from './inertia' | ||
export { default as mergeQueryStringsWithData } from './mergeQueryStringsWithData' | ||
export { default as shouldIntercept } from './shouldIntercept' | ||
export { default as urlWithoutHash } from './urlWithoutHash' | ||
export { hrefToUrl, mergeQueryStringWithData, urlWithoutHash } from './url' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import qs from 'qs' | ||
import deepmerge from 'deepmerge' | ||
|
||
export function hrefToUrl(href) { | ||
try { | ||
if (href.startsWith('#')) { | ||
return new URL(`${urlWithoutHash(window.location)}${href}`) | ||
} else { | ||
return new URL(href) | ||
} | ||
} catch (error) { | ||
return new URL(`${window.location.origin}${href}`) | ||
} | ||
} | ||
|
||
export function mergeQueryStringWithData(method, url, data) { | ||
if (method === 'get' && Object.keys(data).length) { | ||
url.search = qs.stringify(deepmerge(qs.parse(url.search, { ignoreQueryPrefix: true }), data)) | ||
data = {} | ||
} | ||
return [url, data] | ||
} | ||
|
||
export function urlWithoutHash(url) { | ||
url = new URL(url.href) | ||
url.hash = '' | ||
return url | ||
} |
This file was deleted.
Oops, something went wrong.