Last active
December 12, 2015 01:38
-
-
Save heapwolf/4692867 to your computer and use it in GitHub Desktop.
A function to parse the domain from the host. #tld #domain #parser #parse #javascript #js #nodejs
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
exports.domain = function(str) { | |
var a = str.match(/^(\w+:\/\/)?([\w-.]+)/)[2].split('.'); | |
return (a[a.length-1].length === 2 && a[a.length - 2].length === 2 ? a.splice(-3) : a.splice(-2)).join('.'); | |
}; |
Author
heapwolf
commented
Feb 1, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment