1 | module.exports = function parseUrl (url) {
|
2 | const scheme = /^\w+:\/\//.exec(url)
|
3 | let i = 0
|
4 | if (scheme) {
|
5 | i = scheme[0].length + 1
|
6 | }
|
7 | const slashIndex = url.indexOf('/', i)
|
8 | if (slashIndex === -1) {
|
9 | return {
|
10 | origin: url,
|
11 | pathname: '/'
|
12 | }
|
13 | }
|
14 |
|
15 | return {
|
16 | origin: url.slice(0, slashIndex),
|
17 | pathname: url.slice(slashIndex)
|
18 | }
|
19 | }
|