-
Notifications
You must be signed in to change notification settings - Fork 8
Home
Vitaly Tomilov edited this page Jul 13, 2017
·
75 revisions
The URL syntax is compliant with RFC 3986, including support for special symbols -_.+!*'()$
, as well as URL-encoded symbols.
Special considerations are for the format of hostname
and port
:
-
hostname
only supports letters, plus0-9.-
for hyphened names and IPv4 addresses. Whenhostname
starts with[
, it is a special case of an IPv6 address. Example:[2001:0db8::]
. -
port
allows digits only.
The connection-string
protocol is ultimately flexible, and allows everything to be optional.
See the examples below of how various parameters can be passed in, while skipping others.
ends with ://
parse('abc://'); //=> {protocol: 'abc'}
parse('abc://server:12345');
/* => {
protocol: 'abc',
host: 'server:12345',
hostname: 'server',
port: 12345
}*/
parse('server:12345');
/* => {
host: 'server:12345',
hostname: 'server',
port: 12345
}*/
parse('server');
/* => {
host: 'server',
hostname: 'server'
}*/
starts with :
, followed by digits
parse(':12345');
/* => {
host: ':12345',
port: 12345
}*/
ends with @
parse('username@'); //=> {user: 'username'}
starts with :
and ends with @
parse(':pass123@'); //=> {password: 'pass123'}
starts with /
parse('/segment1/segment2'); //=> {segments: ['segment1', 'segment2']}
starts with ?
parse('?param1=value1¶m2=value2');
/* => {
params: {
param1: value1,
param2: value2
}
}*/
parse('abc:///segment1/segment2');
/* => {
protocol: 'abc',
segments: ['segment1', 'segment2']
}*/
parse('abc://?param1=one¶m2=two');
/* => {
protocol: 'abc',
params: {
param1: 'one',
param2: 'two'
}
}*/