Skip to content

Instantly share code, notes, and snippets.

@Wizek
Created December 25, 2010 01:02
Show Gist options
  • Save Wizek/754604 to your computer and use it in GitHub Desktop.
Save Wizek/754604 to your computer and use it in GitHub Desktop.
// Parses url string and returns the components in an object
function parseURL (href) {
if (typeof href != 'string') return {}
var urlObj = {"href":href}
urlObj.pathString = href.split('?', 1)[0]
urlObj.path = urlObj.pathString.split("/")
if (href.length > 1+urlObj.pathString.length) {
urlObj.queryString = href.replace(urlObj.pathString+'?', "")
urlObj.query = {}
urlObj.queryString.split('&').forEach(function(item) {
var keyValue = item.split("=")
urlObj.query[keyValue[0]] = keyValue[1]
})
}
console.log(sys.inspect(urlObj))
return urlObj
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment