-
Notifications
You must be signed in to change notification settings - Fork 958
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #93
- Loading branch information
Showing
6 changed files
with
108 additions
and
55 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 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,45 @@ | ||
import warning from 'warning' | ||
|
||
function extractPath(string) { | ||
const match = string.match(/https?:\/\/[^\/]*/) | ||
|
||
if (match == null) | ||
return string | ||
|
||
warning( | ||
false, | ||
'A path must be pathname + search + hash only, not a fully qualified URL like "%s"', | ||
string | ||
) | ||
|
||
return string.substring(match[0].length) | ||
} | ||
|
||
function parsePath(path) { | ||
let pathname = extractPath(path) | ||
let search = '' | ||
let hash = '' | ||
|
||
let hashIndex = pathname.indexOf('#') | ||
if (hashIndex !== -1) { | ||
hash = pathname.substring(hashIndex) | ||
pathname = pathname.substring(0, hashIndex) | ||
} | ||
|
||
let searchIndex = pathname.indexOf('?') | ||
if (searchIndex !== -1) { | ||
search = pathname.substring(searchIndex) | ||
pathname = pathname.substring(0, searchIndex) | ||
} | ||
|
||
if (pathname === '') | ||
pathname = '/' | ||
|
||
return { | ||
pathname, | ||
search, | ||
hash | ||
} | ||
} | ||
|
||
export default parsePath |
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