Created
February 1, 2013 22:57
-
-
Save potch/4694758 to your computer and use it in GitHub Desktop.
Hey everyone we solved URL parsing in JavaScript!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var urlparse = (function() { | |
var a = document.createElement('a'); | |
// urlparse('https://example.com:8080/bar.html?baz#yay') | |
return function(url) { | |
a.href = url; | |
return { | |
hash: a.hash, // '#yay' | |
host: a.host, // 'example.com:8080' | |
hostname: a.hostname, // 'example.com' | |
href: a.href, // 'https://example.com:8080/' | |
pathname: a.pathname, // '/bar.html' | |
port: a.port, // '8080' | |
protocol: a.protocol, // 'https:' | |
search: a.search // '?baz' | |
}; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Monkey-patch it onto
String
!