Sha256: 86b603933d99068090404683e50946d9bf08f82764fe0e09bd47bc943116e7f6
Contents?: true
Size: 1.24 KB
Versions: 27
Compression:
Stored size: 1.24 KB
Contents
/** * Parse the given `url`. * * @param {String} str * @return {Object} * @api public */ exports.parse = function(url){ var a = document.createElement('a'); a.href = url; return { href: a.href, host: a.host || location.host, port: ('0' === a.port || '' === a.port) ? location.port : a.port, hash: a.hash, hostname: a.hostname || location.hostname, pathname: a.pathname.charAt(0) != '/' ? '/' + a.pathname : a.pathname, protocol: !a.protocol || ':' == a.protocol ? location.protocol : a.protocol, search: a.search, query: a.search.slice(1) }; }; /** * Check if `url` is absolute. * * @param {String} url * @return {Boolean} * @api public */ exports.isAbsolute = function(url){ return 0 == url.indexOf('//') || !!~url.indexOf('://'); }; /** * Check if `url` is relative. * * @param {String} url * @return {Boolean} * @api public */ exports.isRelative = function(url){ return !exports.isAbsolute(url); }; /** * Check if `url` is cross domain. * * @param {String} url * @return {Boolean} * @api public */ exports.isCrossDomain = function(url){ url = exports.parse(url); return url.hostname !== location.hostname || url.port !== location.port || url.protocol !== location.protocol; };
Version data entries
27 entries across 14 versions & 1 rubygems