tldts-core 5.7.111 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +33 -24
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/src/domain-without-suffix.js.map +1 -1
- package/dist/cjs/src/domain.js +10 -4
- package/dist/cjs/src/domain.js.map +1 -1
- package/dist/cjs/src/extract-hostname.js +5 -5
- package/dist/cjs/src/extract-hostname.js.map +1 -1
- package/dist/cjs/src/factory.js +7 -7
- package/dist/cjs/src/factory.js.map +1 -1
- package/dist/cjs/src/is-ip.js +4 -4
- package/dist/cjs/src/is-ip.js.map +1 -1
- package/dist/cjs/src/is-valid.js +6 -3
- package/dist/cjs/src/is-valid.js.map +1 -1
- package/dist/cjs/src/lookup/fast-path.js +1 -1
- package/dist/cjs/src/lookup/fast-path.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/es6/index.js +1 -1
- package/dist/es6/index.js.map +1 -1
- package/dist/es6/src/domain-without-suffix.js.map +1 -1
- package/dist/es6/src/domain.js +10 -4
- package/dist/es6/src/domain.js.map +1 -1
- package/dist/es6/src/extract-hostname.js +5 -5
- package/dist/es6/src/extract-hostname.js.map +1 -1
- package/dist/es6/src/factory.js +7 -7
- package/dist/es6/src/factory.js.map +1 -1
- package/dist/es6/src/is-ip.js +4 -4
- package/dist/es6/src/is-ip.js.map +1 -1
- package/dist/es6/src/is-valid.js +6 -3
- package/dist/es6/src/is-valid.js.map +1 -1
- package/dist/es6/src/lookup/fast-path.js +1 -1
- package/dist/es6/src/lookup/fast-path.js.map +1 -1
- package/dist/es6/tsconfig.bundle.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -1
- package/index.ts +7 -1
- package/package.json +6 -9
- package/src/domain-without-suffix.ts +4 -2
- package/src/domain.ts +13 -4
- package/src/extract-hostname.ts +16 -12
- package/src/factory.ts +7 -7
- package/src/is-ip.ts +6 -5
- package/src/is-valid.ts +8 -5
- package/src/lookup/fast-path.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tldts-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "tldts core primitives (internal module)",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Rémi Berson"
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
],
|
|
46
46
|
"scripts": {
|
|
47
47
|
"clean": "rimraf dist",
|
|
48
|
-
"lint": "tslint --config ../../tslint.json --project ./tsconfig.json",
|
|
49
48
|
"build": "tsc --build ./tsconfig.json",
|
|
50
49
|
"bundle": "tsc --build ./tsconfig.bundle.json && rollup --config ./rollup.config.ts --configPlugin typescript",
|
|
51
50
|
"prepack": "yarn run bundle",
|
|
@@ -56,16 +55,14 @@
|
|
|
56
55
|
"@rollup/plugin-typescript": "^11.0.0",
|
|
57
56
|
"@types/chai": "^4.2.18",
|
|
58
57
|
"@types/mocha": "^10.0.0",
|
|
59
|
-
"@types/node": "^18.
|
|
58
|
+
"@types/node": "^18.15.11",
|
|
60
59
|
"chai": "^4.2.0",
|
|
61
60
|
"mocha": "^10.1.0",
|
|
62
61
|
"nyc": "^15.0.1",
|
|
63
|
-
"rimraf": "^4.1
|
|
64
|
-
"rollup": "^3.
|
|
62
|
+
"rimraf": "^4.4.1",
|
|
63
|
+
"rollup": "^3.20.2",
|
|
65
64
|
"rollup-plugin-sourcemaps": "^0.6.1",
|
|
66
|
-
"
|
|
67
|
-
"tslint-config-prettier": "^1.18.0",
|
|
68
|
-
"typescript": "^4.3.2"
|
|
65
|
+
"typescript": "^5.0.3"
|
|
69
66
|
},
|
|
70
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "bc3d5270b8e60787816fa821680f175547c1008f"
|
|
71
68
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* Return the part of domain without suffix.
|
|
4
3
|
*
|
|
5
4
|
* Example: for domain 'foo.com', the result would be 'foo'.
|
|
6
5
|
*/
|
|
7
|
-
export default function getDomainWithoutSuffix(
|
|
6
|
+
export default function getDomainWithoutSuffix(
|
|
7
|
+
domain: string,
|
|
8
|
+
suffix: string,
|
|
9
|
+
): string {
|
|
8
10
|
// Note: here `domain` and `suffix` cannot have the same length because in
|
|
9
11
|
// this case we set `domain` to `null` instead. It is thus safe to assume
|
|
10
12
|
// that `suffix` is shorter than `domain`.
|
package/src/domain.ts
CHANGED
|
@@ -66,19 +66,28 @@ export default function getDomain(
|
|
|
66
66
|
// Check if `hostname` ends with a member of `validHosts`.
|
|
67
67
|
if (options.validHosts !== null) {
|
|
68
68
|
const validHosts = options.validHosts;
|
|
69
|
-
for (
|
|
70
|
-
|
|
71
|
-
if (/*@__INLINE__*/ shareSameDomainSuffix(hostname, vhost) === true) {
|
|
69
|
+
for (const vhost of validHosts) {
|
|
70
|
+
if (/*@__INLINE__*/ shareSameDomainSuffix(hostname, vhost)) {
|
|
72
71
|
return vhost;
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
|
|
76
|
+
let numberOfLeadingDots = 0;
|
|
77
|
+
if (hostname.startsWith('.')) {
|
|
78
|
+
while (
|
|
79
|
+
numberOfLeadingDots < hostname.length &&
|
|
80
|
+
hostname[numberOfLeadingDots] === '.'
|
|
81
|
+
) {
|
|
82
|
+
numberOfLeadingDots += 1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
77
86
|
// If `hostname` is a valid public suffix, then there is no domain to return.
|
|
78
87
|
// Since we already know that `getPublicSuffix` returns a suffix of `hostname`
|
|
79
88
|
// there is no need to perform a string comparison and we only compare the
|
|
80
89
|
// size.
|
|
81
|
-
if (suffix.length === hostname.length) {
|
|
90
|
+
if (suffix.length === hostname.length - numberOfLeadingDots) {
|
|
82
91
|
return null;
|
|
83
92
|
}
|
|
84
93
|
|
package/src/extract-hostname.ts
CHANGED
|
@@ -6,14 +6,14 @@ export default function extractHostname(
|
|
|
6
6
|
url: string,
|
|
7
7
|
urlIsValidHostname: boolean,
|
|
8
8
|
): string | null {
|
|
9
|
-
let start
|
|
9
|
+
let start = 0;
|
|
10
10
|
let end: number = url.length;
|
|
11
|
-
let hasUpper
|
|
11
|
+
let hasUpper = false;
|
|
12
12
|
|
|
13
13
|
// If url is not already a valid hostname, then try to extract hostname.
|
|
14
|
-
if (urlIsValidHostname
|
|
14
|
+
if (!urlIsValidHostname) {
|
|
15
15
|
// Special handling of data URLs
|
|
16
|
-
if (url.startsWith('data:')
|
|
16
|
+
if (url.startsWith('data:')) {
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -81,11 +81,15 @@ export default function extractHostname(
|
|
|
81
81
|
for (let i = start; i < indexOfProtocol; i += 1) {
|
|
82
82
|
const lowerCaseCode = url.charCodeAt(i) | 32;
|
|
83
83
|
if (
|
|
84
|
-
(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
!(
|
|
85
|
+
(
|
|
86
|
+
(lowerCaseCode >= 97 && lowerCaseCode <= 122) || // [a, z]
|
|
87
|
+
(lowerCaseCode >= 48 && lowerCaseCode <= 57) || // [0, 9]
|
|
88
|
+
lowerCaseCode === 46 || // '.'
|
|
89
|
+
lowerCaseCode === 45 || // '-'
|
|
90
|
+
lowerCaseCode === 43 // '+'
|
|
91
|
+
)
|
|
92
|
+
)
|
|
89
93
|
) {
|
|
90
94
|
return null;
|
|
91
95
|
}
|
|
@@ -103,9 +107,9 @@ export default function extractHostname(
|
|
|
103
107
|
// Detect first occurrence of '/', '?' or '#'. We also keep track of the
|
|
104
108
|
// last occurrence of '@', ']' or ':' to speed-up subsequent parsing of
|
|
105
109
|
// (respectively), identifier, ipv6 or port.
|
|
106
|
-
let indexOfIdentifier
|
|
107
|
-
let indexOfClosingBracket
|
|
108
|
-
let indexOfPort
|
|
110
|
+
let indexOfIdentifier = -1;
|
|
111
|
+
let indexOfClosingBracket = -1;
|
|
112
|
+
let indexOfPort = -1;
|
|
109
113
|
for (let i = start; i < end; i += 1) {
|
|
110
114
|
const code: number = url.charCodeAt(i);
|
|
111
115
|
if (
|
package/src/factory.ts
CHANGED
|
@@ -101,9 +101,9 @@ export function parseImpl(
|
|
|
101
101
|
// set to `false` to speed-up parsing. If only URLs are expected then
|
|
102
102
|
// `mixedInputs` can be set to `false`. The `mixedInputs` is only a hint
|
|
103
103
|
// and will not change the behavior of the library.
|
|
104
|
-
if (options.extractHostname
|
|
104
|
+
if (!options.extractHostname) {
|
|
105
105
|
result.hostname = url;
|
|
106
|
-
} else if (options.mixedInputs
|
|
106
|
+
} else if (options.mixedInputs) {
|
|
107
107
|
result.hostname = extractHostname(url, isValidHostname(url));
|
|
108
108
|
} else {
|
|
109
109
|
result.hostname = extractHostname(url, false);
|
|
@@ -114,9 +114,9 @@ export function parseImpl(
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
// Check if `hostname` is a valid ip address
|
|
117
|
-
if (options.detectIp
|
|
117
|
+
if (options.detectIp) {
|
|
118
118
|
result.isIp = isIp(result.hostname);
|
|
119
|
-
if (result.isIp
|
|
119
|
+
if (result.isIp) {
|
|
120
120
|
return result;
|
|
121
121
|
}
|
|
122
122
|
}
|
|
@@ -124,9 +124,9 @@ export function parseImpl(
|
|
|
124
124
|
// Perform optional hostname validation. If hostname is not valid, no need to
|
|
125
125
|
// go further as there will be no valid domain or sub-domain.
|
|
126
126
|
if (
|
|
127
|
-
options.validateHostname
|
|
128
|
-
options.extractHostname
|
|
129
|
-
isValidHostname(result.hostname)
|
|
127
|
+
options.validateHostname &&
|
|
128
|
+
options.extractHostname &&
|
|
129
|
+
!isValidHostname(result.hostname)
|
|
130
130
|
) {
|
|
131
131
|
result.hostname = null;
|
|
132
132
|
return result;
|
package/src/is-ip.ts
CHANGED
|
@@ -40,7 +40,7 @@ function isProbablyIpv6(hostname: string): boolean {
|
|
|
40
40
|
return false;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
let start = hostname
|
|
43
|
+
let start = hostname.startsWith('[') ? 1 : 0;
|
|
44
44
|
let end = hostname.length;
|
|
45
45
|
|
|
46
46
|
if (hostname[end - 1] === ']') {
|
|
@@ -54,7 +54,7 @@ function isProbablyIpv6(hostname: string): boolean {
|
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
let hasColon
|
|
57
|
+
let hasColon = false;
|
|
58
58
|
|
|
59
59
|
for (; start < end; start += 1) {
|
|
60
60
|
const code = hostname.charCodeAt(start);
|
|
@@ -62,10 +62,11 @@ function isProbablyIpv6(hostname: string): boolean {
|
|
|
62
62
|
if (code === 58 /* ':' */) {
|
|
63
63
|
hasColon = true;
|
|
64
64
|
} else if (
|
|
65
|
-
(
|
|
65
|
+
!(
|
|
66
|
+
(code >= 48 && code <= 57) || // 0-9
|
|
66
67
|
(code >= 97 && code <= 102) || // a-f
|
|
67
|
-
(code >= 65 && code <= 90)
|
|
68
|
-
|
|
68
|
+
(code >= 65 && code <= 90) // A-F
|
|
69
|
+
)
|
|
69
70
|
) {
|
|
70
71
|
return false;
|
|
71
72
|
}
|
package/src/is-valid.ts
CHANGED
|
@@ -28,13 +28,17 @@ export default function (hostname: string): boolean {
|
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
if (
|
|
31
|
+
if (
|
|
32
|
+
/*@__INLINE__*/ !isValidAscii(hostname.charCodeAt(0)) &&
|
|
33
|
+
hostname.charCodeAt(0) !== 46 && // '.' (dot)
|
|
34
|
+
hostname.charCodeAt(0) !== 95 // '_' (underscore)
|
|
35
|
+
) {
|
|
32
36
|
return false;
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
// Validate hostname according to RFC
|
|
36
|
-
let lastDotIndex
|
|
37
|
-
let lastCharCode
|
|
40
|
+
let lastDotIndex = -1;
|
|
41
|
+
let lastCharCode = -1;
|
|
38
42
|
const len = hostname.length;
|
|
39
43
|
|
|
40
44
|
for (let i = 0; i < len; i += 1) {
|
|
@@ -55,8 +59,7 @@ export default function (hostname: string): boolean {
|
|
|
55
59
|
|
|
56
60
|
lastDotIndex = i;
|
|
57
61
|
} else if (
|
|
58
|
-
(/*@__INLINE__*/ isValidAscii(code) || code === 45 || code === 95)
|
|
59
|
-
false
|
|
62
|
+
!(/*@__INLINE__*/ (isValidAscii(code) || code === 45 || code === 95))
|
|
60
63
|
) {
|
|
61
64
|
// Check if there is a forbidden character in the label
|
|
62
65
|
return false;
|
package/src/lookup/fast-path.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IPublicSuffix, ISuffixLookupOptions } from './interface';
|
|
2
2
|
|
|
3
|
-
export default function(
|
|
3
|
+
export default function (
|
|
4
4
|
hostname: string,
|
|
5
5
|
options: ISuffixLookupOptions,
|
|
6
6
|
out: IPublicSuffix,
|
|
7
7
|
): boolean {
|
|
8
8
|
// Fast path for very popular suffixes; this allows to by-pass lookup
|
|
9
9
|
// completely as well as any extra allocation or string manipulation.
|
|
10
|
-
if (options.allowPrivateDomains
|
|
10
|
+
if (!options.allowPrivateDomains && hostname.length > 3) {
|
|
11
11
|
const last: number = hostname.length - 1;
|
|
12
12
|
const c3: number = hostname.charCodeAt(last);
|
|
13
13
|
const c2: number = hostname.charCodeAt(last - 1);
|