1 | url = require 'url'
|
2 |
|
3 | module.exports = (u) ->
|
4 |
|
5 | p = url.parse(u)
|
6 |
|
7 | s = []
|
8 | s.push p.protocol
|
9 | s.push '//'
|
10 | if p.auth
|
11 | [user, pass] = p.auth.split ':'
|
12 | s.push encodeURIComponent(user)
|
13 | if pass
|
14 | s.push ':'
|
15 | s.push encodeURIComponent(pass)
|
16 | s.push '@'
|
17 | s.push p.hostname
|
18 | if p.port
|
19 | s.push ':'
|
20 | s.push p.port
|
21 |
|
22 | server = s.join('')
|
23 |
|
24 | [_, index, type] = (p.pathname ? '').split '/'
|
25 |
|
26 | query = p.query
|
27 |
|
28 | {
|
29 | server
|
30 | index: if index then index else null
|
31 | type: if type then type else null
|
32 | query: query ? ''
|
33 | }
|