Skip to content

Instantly share code, notes, and snippets.

@emrahoruc
Created February 13, 2017 07:38
Show Gist options
  • Save emrahoruc/d950e61fff04af41b69ab4a6dbbe6fff to your computer and use it in GitHub Desktop.
Save emrahoruc/d950e61fff04af41b69ab4a6dbbe6fff to your computer and use it in GitHub Desktop.
URL Object
function loc(url) {
return {
search : function() {
return url.match(/\?(.+)/i)[1];
},
hash : function() {
return url.match(/#(.+)/i)[1];
},
protocol : function() {
return url.match(/(ht|f)tps?:/)[0];
},
href : function() {
return url.match(/(.+\.[a-z]{2,4})/ig);
}
}
}
var l = loc('http://www.net.tutsplus.edu?key=value#hash');
alert(l.href()); // http://www.net.tutsplus.com
alert(l.protocol()); // http:
alert(l.protocol()); // http:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment