lenye_base
Version:
基础方法
32 lines (25 loc) • 916 B
JavaScript
;
require('./ifnodeorbrowser.js');
var windowsimulate = require('./windowsimulate.js');
var http = {
/*获取顶级域名*/
gettopUrl: () => {
var host = windowsimulate.windows.location.hostname;
var ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
if (ip.test(host) === true || host === 'localhost') return host;
var regex = /([^]*).*/;
var match = host.match(regex);
if (typeof match !== "undefined" && null !== match) host = match[1];
if (typeof host !== "undefined" && null !== host) {
var strAry = host.split(".");
if (strAry.length > 1) {
host = strAry[strAry.length - 2] + "." + strAry[strAry.length - 1];
}
}
return host;
},
getUrl: () => {
return windowsimulate.windows.location.hostname;
}
};
module.exports = http;