url / Intro / Examples

Usage

If using the node version a url will always need to be suplied otherwise it will default to the current url.

var url = 'http://rob:[email protected]/path/index.html?query1=test&silly=willy&field[0]=zero&field[2]=two#test=hash&chucky=cheese';

url(url); // http://rob:[email protected]/path/index.html?query1=test&silly=willy&field[0]=zero&field[2]=two#test=hash&chucky=cheese

Domain Parts

url('tld',      url); // co.uk
url('domain',   url); // example.co.uk
url('hostname', url); // www.example.co.uk
url('sub',      url); // www
url('.0',       url); // undefined
url('.1',       url); // www
url('.2',       url); // example
url('.-1',      url); // uk

Username / Password

url('auth',     url)  // rob:abcd1234
url('user',     url)  // rob
url('pass',     url)  // abcd1234

Protocol / Port

url('port',     url); // 80
url('protocol', url); // http

Path

url('path',     url); // /path/index.html
url('file',     url); // index.html
url('filename', url); // index
url('fileext',  url); // html
url('1',        url); // path
url('2',        url); // index.html
url('3',        url); // undefined
url('-1',       url); // index.html
url(1,          url); // path
url(2,          url); // index.html
url(-1,         url); // index.html

Query

url('query', url);    // query1=test&silly=willy
url('?', url);        // {query1: 'test', silly: 'willy', field: ['zero', undefined, 'two']}
url('?silly', url);   // willy
url('?poo', url);     // undefined
url('field[0]', url); // zero
url('field', url);    // ['zero', undefined, 'two']

Hash

url('hash', url);     // test=hash&chucky=cheese
url('#', url);        // {test: 'hash', chucky: 'cheese'}
url('#chucky', url);  // cheese
url('#poo', url);     // undefined

Mail To

url('protocol', 'mailto:[email protected]'); // mailto
url('email',    'mailto:[email protected]'); // [email protected]