Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

joezimjs/JZ-Parse-URL

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 

JZ Parse URL

No Longer In Development

This library is no longer supported. It was more of a proof of concept than anything and there are far better libraries for parsing URLs out there. If you are in Node.js, you can use their built-in URL API, or in the browser you can use something like URI.js.

JZ Parse URL Logo

Generally, the fastest way to parse a URL is via a regular expression. Obviously, not everyone is good with regular expressions and would rather use a plugin or library. This script is here for those people, but does not use a regular expression. Instead it uses the DOM to parse the URL and then throws a few extra bits in to make things better and more useable. This jQuery plugin can also be used as a standalone library: if jQuery is not loaded when this script is loaded, then parseUrl is attached to a global object named JZ. If you experience any bugs, please report them as an issue.

Table of Contents

Download

JZ Parse URL is currently on version 1.0. You can view the version history here. You may use Github's built in links to download and view the tests or simply clone the repo.

Documentation

Dependencies

JZ Parse URL is not dependent on any libraries, though it is designed to attach itself to jQuery as a utility function if it's available. No specific version of jQuery is required.

$.parseUrl()

jQuery.parseUrl( [url] ) or JZ.parseUrl( [url] )

  • url: A relative or absolute URL string. If no URL is provided, the current location is used.
  • Returns an object with numerous properties mapping to their respective portions of the URL. You can read more about it in the Properties Section.

The parseUrl method is the bread and butter of this library. Just call it with or without passing a URL in and it will return an object with parsed URL properties:

// To parse a full URL, just pass the entire URL as a string as
// the sole parameter to jQuery.parseUrl (or JZ.parseUrl if
// jQuery was not loaded before this plugin was).
$.parseUrl("http://example.com:3000/pathname/?srch=test#hash");

// To parse a URL relative to this page's URL, pass in a partial
// URL as a string as the sole parameter to jQuery.parseUrl (or
// JZ.parseUrl if jQuery was not loaded before this plugin was).
$.parseUrl("/contact");

// To parse the current URL of the page that you are on, then
// do not pass in any parameters.
$.parseUrl();

Properties

When parseUrl is invoked, it returns an object with several properties. You can see those properties listed below and example of what they would be:

// If I ran the first example above with the full URL, I
// would receive the following object back:
{
    hash:      '#hash',
    host:      'example.com:3000',
    hostname:  'example.com',
    href:      'http://example.com:3000/path/?srch=test#hash',
    path:      '/path/',
    pathname:  '/path/',
    port:      '3000',
    protocol:  'http:',
    query:     { srch: 'test' },
    search:    '?srch=test',
    url:       'http://example.com:3000/path/?srch=test#hash'
}

The path property is an alias for pathname. The url property is an alias for href. The query property is search converted into an object for simple access to each of the parameters.

Version History

About

jQuery Plugin / Standalone Library for parsing URLs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published