Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ddd89e
commit 069afcc
Showing
24 changed files
with
2,069 additions
and
2,284 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
coverage/ | ||
lib-es5/ | ||
node_modules/ | ||
.nyc_output/ | ||
package-lock.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- "4" | ||
- "6" | ||
script: npm test | ||
- 10 | ||
- 12 | ||
- node | ||
script: npm run ci |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,43 @@ | ||
"use strict"; | ||
var broquire = require("broquire")(require); | ||
var isString = require("is-string"); | ||
var parseDomain = broquire("parse-domain", function(){ return null }); | ||
var URL = broquire("whatwg-url", "window").URL; | ||
import parseDomain from "parse-domain"; | ||
|
||
|
||
|
||
function getHostKey(url, options) | ||
export default (url, options, optionOverrides) => | ||
{ | ||
var key,port,protocol,urlDomain; | ||
|
||
if (url == null) | ||
{ | ||
return false; | ||
} | ||
else if (isString(url) === true) | ||
{ | ||
try | ||
{ | ||
url = new URL(url); | ||
} | ||
catch (error) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
protocol = url.protocol; | ||
|
||
// TODO :: remove support for node-js url.parse objects | ||
if (isEmptyString(protocol)===true || isEmptyString(url.hostname)===true) | ||
{ | ||
return false; | ||
} | ||
|
||
// Remove ":" suffix | ||
if (protocol.indexOf(":") === protocol.length-1) | ||
{ | ||
protocol = protocol.substr(0, protocol.length-1); | ||
} | ||
|
||
port = url.port; | ||
|
||
// Get default port | ||
// TODO :: remove support for node-js url.parse objects | ||
if (isEmptyStringOrNumber(port)===true && options.defaultPorts[protocol]!==undefined) | ||
{ | ||
port = options.defaultPorts[protocol]; | ||
} | ||
|
||
key = ""; | ||
|
||
if (options.ignoreSchemes === false) | ||
const ignorePorts = optionOverrides?.ignorePorts ?? options.ignorePorts; | ||
const ignoreProtocols = optionOverrides?.ignoreProtocols ?? options.ignoreProtocols; | ||
const ignoreSubdomains = optionOverrides?.ignoreSubdomains ?? options.ignoreSubdomains; | ||
|
||
let key = ""; | ||
|
||
if (!ignoreProtocols) | ||
{ | ||
key += protocol + "://"; | ||
key += `${url.protocol}//`; | ||
} | ||
if (options.ignoreSubdomains === false) | ||
|
||
if (!ignoreSubdomains) | ||
{ | ||
key += url.hostname; | ||
} | ||
else | ||
{ | ||
urlDomain = parseDomain(url.hostname); | ||
|
||
// If unknown top-level-domain (.com, etc) | ||
// Or, if running in a browser | ||
if (urlDomain === null) | ||
const hostname = parseDomain(url.hostname); | ||
|
||
// If unknown top-level domain or running in a browser | ||
if (hostname === null) | ||
{ | ||
key += url.hostname; | ||
} | ||
else | ||
{ | ||
key += urlDomain.domain + "." + urlDomain.tld; | ||
key += `${hostname.domain}.${hostname.tld}`; | ||
} | ||
} | ||
if (options.ignorePorts===false && port!=null) | ||
|
||
if (!ignorePorts && url.port!=="") | ||
{ | ||
key += ":" + port; | ||
key += `:${url.port}`; | ||
} | ||
|
||
key += "/"; | ||
|
||
return key; | ||
} | ||
|
||
|
||
|
||
function isEmptyString(value) | ||
{ | ||
return value==="" || value==null || isString(value)===false; | ||
} | ||
|
||
|
||
|
||
function isEmptyStringOrNumber(value) | ||
{ | ||
return value==="" || value==null || isNaN(value)===true; | ||
} | ||
|
||
|
||
|
||
module.exports = getHostKey; | ||
return key; | ||
}; |
Oops, something went wrong.