Skip to content

Latest commit

 

History

History
 
 

parseUri

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

parseUri

This utility parses a URI and returns an object that provides various parts of the URI. It is an adaptation of code published on blog.stevenlevithan.com.

Usage

var parseUri = require('bv-ui-core/lib/parseUri');
var url = 'http://some.example.com';

var parsedUri = parseUri(url);

The resulting parsedUri object in the above example has properties that represent the various parts of the provided URI.

Given the following URL:

https://bob:[email protected]:8080/path/to/file.html?foo=bar&baz=3#hash

The resulting object will be equivalent to this:

{
  anchor: 'hash',
  query: 'foo=bar&baz=3',
  file: 'file.html',
  directory: '/path/to/'
  path: '/path/to/file.html',
  relative: '/path/to/file.html?foo=bar&baz=3#hash',
  port: '8080',
  host: 'subdomain.example.com',
  password: 'smith',
  user: 'bob',
  userInfo: 'bob:smith',
  authority: 'bob:[email protected]:8080',
  protocol: 'https',
  source: 'https://bob:[email protected]:8080/path/to/file.html?foo=bar&baz=3#hash',
  queryKey: {
    foo: 'bar',
    baz: '3'
  }
}

Of special note is the queryKey property; it provides a simple key/value representation of the query string parameters.