Skip to content

Instantly share code, notes, and snippets.

@NickJosevski
Forked from mrclay/UFCOE.parseUri.js
Created August 23, 2012 06:16
Show Gist options
  • Save NickJosevski/3433308 to your computer and use it in GitHub Desktop.
Save NickJosevski/3433308 to your computer and use it in GitHub Desktop.
Parse a URI using the browser's DOM (CoffeeScript)
class UriHelpers
parseUri: (url) ->
k = window.Common.UrlHelpers.UriParseModes
a || (a = window.document.createElement('a'))
#Let browser do the work
a.href = url
r = {}
r[k[i]] = a[k[i]] for i in [0..8]
r.toString = -> ( a.href )
r.requestUri = r.pathname + r.search
r
window.Common = window.Common || {}
window.Common.UriHelpers = window.Common.UriHelpers|| new UrlHelpers()
window.Common.UriParseModes = window.Common.UriParseModes || 'protocol hostname host pathname port search hash href'.split ' '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment