function getDomain(url){
var hasProtocol = url.indexOf('://') > -1;
var resourceDelimiterIndex = hasProtocol ? 2 : 0;
var completeDomainNameWithPort = url.split('/')[resourceDelimiterIndex];
var completeDomain = completeDomainNameWithPort.split(':')[0]
var domainLevels = completeDomain.split('.');
var domain = domainLevels.slice(domainLevels.length - 2, domainLevels.length).join('.');
return domain;
}
let test = "https://secure.safe.boulanger.com:2356/test.aspx?webapp/wcs/stores/servlet/OrderItemDisplay?langId=-2&storeId=10001&catalogId=10001&orderId=81564155";
console.log(getDomain(test));
test = "ssh://secure.safe.boulanger.com:2356/test.aspx?webapp/wcs/stores/servlet/OrderItemDisplay?langId=-2&storeId=10001&catalogId=10001&orderId=81564155";
console.log(getDomain(test));
test = "http://www.boulanger.com/test.aspx?webapp/wcs/stores/servlet/OrderItemDisplay?langId=-2&storeId=10001&catalogId=10001&orderId=81564155";
console.log(getDomain(test));
test = "www.boulanger.com/test.aspx?webapp/wcs/stores/servlet/OrderItemDisplay?langId=-2&storeId=10001&catalogId=10001&orderId=81564155";
console.log(getDomain(test));