Working with URLs

URL and ParsedURL

Functions for working with URLs.

Building URLs

Constructing URLs dynamically is a key requirement of most web applications but JavaScript offers little help out of the box but Combine, hashToQuery and formURLEncode make simple work of it. hashToQuery makes the querystring, calling formURLEncode to processes any special characters in the querystring, and combine puts the path parts, file name and querystring together into a usable whole.

Unpeeling URLs

Of course the reverse is just as true, that web apps need to take information from the URLs, which is where queryToHash, formURLDecode and parseURL do the lifting. When more sophisticated tasks come up, you can call parseURLComponents to get an object containing all the pieces of a URL.

ParsedURL contains properties for each part of a URL including the entire URL, the protocol, the domain and subdomain, the base (protocol, host and port), the path as string or array of parts, the file, the path and file, the fragment and the querystring as string or object with a property for each name/value pair.

File URLs

This namespace also has two functions that deal with the file protocol specifically: ensureFileProtocol and isFile. The latter tells you if a URL is using the file protocol and the former forces a URL to use it.

Building a URL

Examining a URL

XPCOM Network utility functions

  • fixupUri: invokes the XPCOM nsIURIFixup method and return a 'fixed' URI
  • onStartRequest: a stub function to be overridden
  • onStopRequest: invokes the callback function for completed requests
  • QueryInterface: returns a QueryInterface for the provided XPCOM Interface ID
  • validateURI: validates the provided URI using XPCOM and returns JSLib.Ok if successful