-
Notifications
You must be signed in to change notification settings - Fork 4
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 67a8013
Showing
23 changed files
with
1,960 additions
and
2,196 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,3 @@ | ||
coverage/ | ||
node_modules/ | ||
.nyc_output/ |
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,5 @@ | ||
language: node_js | ||
node_js: | ||
- "4" | ||
- "6" | ||
script: npm test | ||
- 6 | ||
- 7 | ||
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,49 @@ | ||
"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; | ||
const defined = require("defined"); | ||
const parseDomain = require("parse-domain"); | ||
|
||
|
||
|
||
function getHostKey(url, options) | ||
function getHostKey(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 = ""; | ||
const ignorePorts = defined(optionOverrides.ignorePorts, options.ignorePorts); | ||
const ignoreProtocols = defined(optionOverrides.ignoreProtocols, options.ignoreProtocols); | ||
const ignoreSubdomains = defined(optionOverrides.ignoreSubdomains, options.ignoreSubdomains); | ||
|
||
let key = ""; | ||
|
||
if (options.ignoreSchemes === false) | ||
if (ignoreProtocols === false) | ||
{ | ||
key += protocol + "://"; | ||
key += `${url.protocol}//`; | ||
} | ||
|
||
if (options.ignoreSubdomains === false) | ||
if (ignoreSubdomains === false) | ||
{ | ||
key += url.hostname; | ||
} | ||
else | ||
{ | ||
urlDomain = parseDomain(url.hostname); | ||
const hostname = parseDomain(url.hostname); | ||
|
||
// If unknown top-level-domain (.com, etc) | ||
// Or, if running in a browser | ||
if (urlDomain === null) | ||
// 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===false && 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; |
Oops, something went wrong.