parse-domain
Advanced tools
Comparing version 6.0.1 to 7.0.0
const urlPattern = /^[a-z][*+.a-z-]+:\/\//i; | ||
const invalidIpv6Pattern = /^([a-z][*+.a-z-]+:\/\/)([^[].*:[^/?]*:[^/?]*)(.*)/i; | ||
export const NO_HOSTNAME = Symbol("NO_HOSTNAME"); | ||
@@ -13,3 +14,3 @@ export const fromUrl = (urlLike) => { | ||
// URLs that start with // are protocol relative | ||
const url = urlLike.startsWith("//") | ||
let url = urlLike.startsWith("//") | ||
? `http:${urlLike}` | ||
@@ -22,2 +23,3 @@ : // URLs that start with / do not have a hostname section | ||
: `http://${urlLike}`; | ||
url = url.replace(invalidIpv6Pattern, "$1[$2]$3"); | ||
try { | ||
@@ -24,0 +26,0 @@ return new URL(url).hostname; |
@@ -100,7 +100,6 @@ import { ipVersion } from "is-ip"; | ||
} | ||
const inputTrimmed = input.trim(); | ||
if (inputTrimmed === "") { | ||
if (input === "") { | ||
return { | ||
type: SanitizationResultType.ValidDomain, | ||
domain: inputTrimmed, | ||
domain: input, | ||
labels: [], | ||
@@ -111,3 +110,3 @@ }; | ||
// See https://tools.ietf.org/html/rfc3986#section-3.2.2 | ||
const inputTrimmedAsIp = inputTrimmed.replace(/^\[|]$/g, ""); | ||
const inputTrimmedAsIp = input.replace(/^\[|]$/g, ""); | ||
const ipVersionOfInput = ipVersion(inputTrimmedAsIp); | ||
@@ -121,4 +120,4 @@ if (ipVersionOfInput !== undefined) { | ||
} | ||
const lastChar = inputTrimmed.charAt(inputTrimmed.length - 1); | ||
const canonicalInput = lastChar === LABEL_SEPARATOR ? inputTrimmed.slice(0, -1) : inputTrimmed; | ||
const lastChar = input.charAt(input.length - 1); | ||
const canonicalInput = lastChar === LABEL_SEPARATOR ? input.slice(0, -1) : input; | ||
const octets = new TextEncoder().encode(canonicalInput); | ||
@@ -128,3 +127,3 @@ if (octets.length > DOMAIN_LENGTH_MAX) { | ||
type: SanitizationResultType.Error, | ||
errors: [createDomainMaxLengthError(inputTrimmed, octets.length)], | ||
errors: [createDomainMaxLengthError(input, octets.length)], | ||
}; | ||
@@ -143,3 +142,3 @@ } | ||
type: SanitizationResultType.ValidDomain, | ||
domain: inputTrimmed, | ||
domain: input, | ||
labels, | ||
@@ -146,0 +145,0 @@ }; |
{ | ||
"name": "parse-domain", | ||
"version": "6.0.1", | ||
"version": "7.0.0", | ||
"description": "Splits a hostname into subdomains, domain and (effective) top-level domains", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -35,5 +35,5 @@ # parse-domain | ||
This package has been designed for modern Node and browser environments, supporting both CommonJS and ECMAScript modules. It assumes an ES2015 environment with [`Symbol()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), [`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL) and [`TextDecoder()](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder) globally available. You need to transpile it down to ES5 (e.g. by using [Babel](https://babeljs.io/)) if you need to support older environments. | ||
This package has been designed for modern Node and browser environments with ECMAScript modules support. It assumes an ES2015 environment with [`Symbol()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), [`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL) and [`TextDecoder()`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder) globally available. You need to transpile it down to ES5 (e.g. by using [Babel](https://babeljs.io/)) if you need to support older environments. | ||
The list of top-level domains is stored in a [trie](https://en.wikipedia.org/wiki/Trie) data structure and serialization format to ensure the fastest lookup and the smallest possible library size. The library is side-effect free (this is important for proper [tree-shaking](https://webpack.js.org/guides/tree-shaking/)). | ||
The list of top-level domains is stored in a [trie](https://en.wikipedia.org/wiki/Trie) data structure and serialization format to ensure the fastest lookup and the smallest possible library size. | ||
@@ -40,0 +40,0 @@ <br /> |
@@ -1,1 +0,1 @@ | ||
{"updatedAt":"2022-01-23T19:15:47.692Z"} | ||
{"updatedAt":"2022-01-23T19:59:38.023Z"} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
878
153539