tldts-core 7.5.5 → 7.6.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.
Files changed (39) hide show
  1. package/dist/cjs/index.js +579 -141
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/src/extract-hostname.js +222 -92
  4. package/dist/cjs/src/extract-hostname.js.map +1 -1
  5. package/dist/cjs/src/factory.js +25 -1
  6. package/dist/cjs/src/factory.js.map +1 -1
  7. package/dist/cjs/src/ip-mapping.js +19 -0
  8. package/dist/cjs/src/ip-mapping.js.map +1 -0
  9. package/dist/cjs/src/is-ip.js +305 -44
  10. package/dist/cjs/src/is-ip.js.map +1 -1
  11. package/dist/cjs/src/is-valid.js +11 -4
  12. package/dist/cjs/src/is-valid.js.map +1 -1
  13. package/dist/cjs/src/options.js +2 -1
  14. package/dist/cjs/src/options.js.map +1 -1
  15. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  16. package/dist/es6/src/extract-hostname.js +221 -91
  17. package/dist/es6/src/extract-hostname.js.map +1 -1
  18. package/dist/es6/src/factory.js +26 -2
  19. package/dist/es6/src/factory.js.map +1 -1
  20. package/dist/es6/src/ip-mapping.js +16 -0
  21. package/dist/es6/src/ip-mapping.js.map +1 -0
  22. package/dist/es6/src/is-ip.js +305 -44
  23. package/dist/es6/src/is-ip.js.map +1 -1
  24. package/dist/es6/src/is-valid.js +11 -4
  25. package/dist/es6/src/is-valid.js.map +1 -1
  26. package/dist/es6/src/options.js +2 -1
  27. package/dist/es6/src/options.js.map +1 -1
  28. package/dist/es6/tsconfig.bundle.tsbuildinfo +1 -1
  29. package/dist/types/src/extract-hostname.d.ts +1 -0
  30. package/dist/types/src/ip-mapping.d.ts +4 -0
  31. package/dist/types/src/is-ip.d.ts +13 -4
  32. package/dist/types/src/options.d.ts +1 -1
  33. package/package.json +2 -2
  34. package/src/extract-hostname.ts +253 -91
  35. package/src/factory.ts +36 -4
  36. package/src/ip-mapping.ts +15 -0
  37. package/src/is-ip.ts +336 -48
  38. package/src/is-valid.ts +12 -4
  39. package/src/options.ts +3 -2
@@ -0,0 +1,15 @@
1
+ // Auto-generated by packages/tldts-utils/bin/ip-mapping.js (Node.js v26.13.1, Unicode 18.0). Do not edit.
2
+ //
3
+ // Non-ASCII code points that the host parser of browsers deletes, or maps to
4
+ // '.', or to digits, 'a'-'f' and 'x' only, as ranges: code points
5
+ // `ipMappingFirst[k]` to `ipMappingLast[k]` map, with `value = ipMappingValue[k]`
6
+ // and `offset` the position in the range: to nothing if `value` is 0, to the
7
+ // character `value + offset` if `value` is below 128, to the decimal number
8
+ // `value - 1000 + offset` if `value` is below 2000, and else to the two
9
+ // characters `value >> 8` and `value & 255`.
10
+ export const ipMappingFirst = /*#__PURE__*/ new Uint32Array([170,173,178,185,739,847,4447,6068,6155,7468,7470,7472,7491,7495,7496,7580,7584,8203,8288,8298,8304,8308,8320,8336,8337,8339,8450,8492,8495,8496,8517,8518,8553,8557,8569,8573,9312,9321,9398,9421,9424,9447,9450,12290,12644,12881,12977,13170,13252,13253,13256,42994,42995,64256,65024,65279,65294,65296,65313,65336,65345,65368,65377,65440,113824,117974,117997,118000,119155,119808,119831,119834,119857,119860,119883,119886,119909,119912,119935,119938,119961,119964,119966,119987,119990,119995,120013,120016,120039,120042,120065,120068,120071,120091,120094,120117,120120,120123,120143,120146,120169,120172,120195,120198,120221,120224,120247,120250,120273,120276,120299,120302,120325,120328,120351,120354,120377,120380,120403,120406,120429,120432,120455,120458,120481,120782,120792,120802,120812,120822,127275,127277,127280,127303,130032,917760]);
11
+ export const ipMappingLast = /*#__PURE__*/ new Uint32Array([170,173,179,185,739,847,4448,6069,6159,7468,7470,7473,7491,7495,7497,7580,7584,8203,8292,8303,8304,8313,8329,8336,8337,8339,8450,8493,8495,8497,8517,8519,8553,8558,8569,8574,9320,9331,9403,9421,9429,9447,9450,12290,12644,12895,12991,13170,13252,13253,13256,42994,42995,64256,65039,65279,65294,65305,65318,65336,65350,65368,65377,65440,113827,117979,117997,118009,119162,119813,119831,119839,119857,119865,119883,119891,119909,119917,119935,119943,119961,119964,119967,119987,119993,119995,120013,120021,120039,120047,120065,120069,120073,120091,120099,120117,120121,120125,120143,120151,120169,120177,120195,120203,120221,120229,120247,120255,120273,120281,120299,120307,120325,120333,120351,120359,120377,120385,120403,120411,120429,120437,120455,120463,120481,120791,120801,120811,120821,120831,127275,127277,127285,127303,130041,917999]);
12
+ export const ipMappingValue = /*#__PURE__*/ new Uint16Array([97,0,50,49,120,0,0,0,0,97,98,100,97,98,100,99,102,0,0,0,48,52,48,97,101,120,99,98,101,101,100,100,120,99,120,99,49,1010,97,120,97,120,48,46,0,1021,1036,25697,25443,25444,25698,99,102,26214,0,0,46,48,97,120,97,120,46,0,0,97,120,48,0,97,120,97,120,97,120,97,120,97,120,97,120,97,99,120,97,102,120,97,120,97,120,97,100,120,97,120,97,100,120,97,120,97,120,97,120,97,120,97,120,97,120,97,120,97,120,97,120,97,120,97,120,97,120,97,120,48,48,48,48,48,99,25444,97,120,48,0]);
13
+ // Bit `(cp >> 8) & 31` of `ipMappingBlocks[cp >> 13]` is set when the block of
14
+ // 256 code points holding `cp` (below U+10000) holds any of them.
15
+ export const ipMappingBlocks = /*#__PURE__*/ new Uint32Array([562167821,983059,0,0,0,128,0,3355443200]);
package/src/is-ip.ts CHANGED
@@ -1,83 +1,371 @@
1
1
  /**
2
- * Check if a hostname is an IP. You should be aware that this only works
3
- * because `hostname` is already garanteed to be a valid hostname!
2
+ * Detection of IP addresses, as defined by the host parser of the WHATWG URL
3
+ * standard (https://url.spec.whatwg.org/#host-parsing), which browsers follow.
4
+ * Addresses are recognized, never rewritten: `0x7f.1` is 127.0.0.1 for a
5
+ * browser, hence an IP here, but stays `0x7f.1`.
4
6
  */
5
- function isProbablyIpv4(hostname: string): boolean {
6
- // Cannot be shorted than 1.1.1.1
7
- if (hostname.length < 7) {
8
- return false;
9
- }
10
7
 
11
- // Cannot be longer than: 255.255.255.255
12
- if (hostname.length > 15) {
13
- return false;
8
+ import {
9
+ ipMappingBlocks,
10
+ ipMappingFirst,
11
+ ipMappingLast,
12
+ ipMappingValue,
13
+ } from './ip-mapping';
14
+
15
+ /**
16
+ * Value of the hexadecimal digit `code` (0 to 15), or 16 if it is not one.
17
+ */
18
+ function hexValue(code: number): number {
19
+ if (code >= 48 && code <= 57) {
20
+ return code - 48; // 0-9
14
21
  }
22
+ const letter = code | 32; // lower-case
23
+ return letter >= 97 && letter <= 102 ? letter - 87 : 16; // a-f
24
+ }
15
25
 
16
- let numberOfDots = 0;
26
+ /**
27
+ * Check if `hostname` is an IPv4 address: one to four numbers separated by
28
+ * dots, each one decimal, octal (leading `0`) or hexadecimal (leading `0x`).
29
+ * The last number fills the bytes the others leave, so `127.1` and
30
+ * `2130706433` are both 127.0.0.1.
31
+ * https://url.spec.whatwg.org/#concept-ipv4-parser
32
+ */
33
+ function isIpv4(hostname: string): boolean {
34
+ const end = hostname.length;
35
+ let i = 0;
17
36
 
18
- for (let i = 0; i < hostname.length; i += 1) {
19
- const code = hostname.charCodeAt(i);
37
+ for (let numbers = 1; numbers <= 4; numbers += 1) {
38
+ let radix = 10;
39
+ if (i + 1 < end && hostname.charCodeAt(i) === 48 /* '0' */) {
40
+ radix = 8;
41
+ if ((hostname.charCodeAt(i + 1) | 32) === 120 /* 'x' */) {
42
+ radix = 16;
43
+ i += 2;
44
+ }
45
+ }
46
+
47
+ const start = i;
48
+ let value = 0;
49
+ for (; i < end; i += 1) {
50
+ const code = hostname.charCodeAt(i);
51
+ if (code === 46 /* '.' */) {
52
+ break;
53
+ }
54
+ const digit = hexValue(code);
55
+ if (digit >= radix) {
56
+ return false;
57
+ }
58
+ value = value * radix + digit;
59
+ }
20
60
 
21
- if (code === 46 /* '.' */) {
22
- numberOfDots += 1;
23
- } else if (code < 48 /* '0' */ || code > 57 /* '9' */) {
61
+ // A number has digits, except "0x" which is 0.
62
+ if (i === start && radix !== 16) {
24
63
  return false;
25
64
  }
65
+
66
+ if (i === end) {
67
+ return value <= 0xffffffff >>> (8 * (numbers - 1));
68
+ }
69
+ if (value > 255) {
70
+ return false;
71
+ }
72
+ i += 1; // '.'
26
73
  }
27
74
 
28
- return (
29
- numberOfDots === 3 &&
30
- hostname.charCodeAt(0) !== 46 /* '.' */ &&
31
- hostname.charCodeAt(hostname.length - 1) !== 46 /* '.' */
32
- );
75
+ return false;
33
76
  }
34
77
 
35
78
  /**
36
- * Similar to isProbablyIpv4.
79
+ * Check if `hostname[i, end)` is made of four decimal numbers separated by
80
+ * dots, each one between 0 and 255 and without leading zero.
37
81
  */
38
- function isProbablyIpv6(hostname: string): boolean {
39
- if (hostname.length < 3) {
40
- return hostname === '::';
82
+ function isDottedDecimal(hostname: string, i: number, end: number): boolean {
83
+ for (let numbers = 1; numbers <= 4; numbers += 1) {
84
+ const start = i;
85
+ let value = 0;
86
+ for (; i < end; i += 1) {
87
+ const digit = hostname.charCodeAt(i) - 48;
88
+ if (digit < 0 || digit > 9) {
89
+ break;
90
+ }
91
+ value = value * 10 + digit;
92
+ // Only a leading zero keeps a number of several digits below 10.
93
+ if (value > 255 || (value < 10 && i !== start)) {
94
+ return false;
95
+ }
96
+ }
97
+
98
+ if (i === start) {
99
+ return false;
100
+ }
101
+ if (numbers < 4) {
102
+ if (hostname.charCodeAt(i) !== 46 /* '.' */) {
103
+ return false;
104
+ }
105
+ i += 1;
106
+ }
41
107
  }
42
108
 
43
- let start = hostname.startsWith('[') ? 1 : 0;
109
+ return i === end;
110
+ }
111
+
112
+ /**
113
+ * Check if `hostname` is an IPv6 address, with or without its brackets: eight
114
+ * groups of one to four hexadecimal digits separated by colons, where a `::`
115
+ * may stand once for one or more missing groups, and a dotted-decimal IPv4
116
+ * address may stand for the last two.
117
+ * https://url.spec.whatwg.org/#concept-ipv6-parser
118
+ */
119
+ function isIpv6(hostname: string): boolean {
120
+ let i = 0;
44
121
  let end = hostname.length;
45
122
 
46
- if (hostname[end - 1] === ']') {
123
+ if (hostname.charCodeAt(0) === 91 /* '[' */) {
124
+ if (hostname.charCodeAt(end - 1) !== 93 /* ']' */) {
125
+ return false;
126
+ }
127
+ i = 1;
47
128
  end -= 1;
48
129
  }
49
130
 
50
- // We only consider the maximum size of a normal IPV6. Note that this will
51
- // fail on so-called "IPv4 mapped IPv6 addresses" but this is a corner-case
52
- // and a proper validation library should be used for these.
53
- if (end - start > 39) {
54
- return false;
131
+ // An address only starts with a ':' if it starts with "::".
132
+ if (i < end && hostname.charCodeAt(i) === 58 /* ':' */) {
133
+ if (i + 1 === end || hostname.charCodeAt(i + 1) !== 58 /* ':' */) {
134
+ return false;
135
+ }
136
+ i += 1;
55
137
  }
56
138
 
57
- let hasColon = false;
139
+ let groups = 0;
140
+ let compressed = false; // "::" was seen, and counted as one group
58
141
 
59
- for (; start < end; start += 1) {
60
- const code = hostname.charCodeAt(start);
142
+ // Here `i` is where a group starts: a ':' can only be the second of a "::".
143
+ while (i < end && groups < 8) {
144
+ if (hostname.charCodeAt(i) === 58 /* ':' */) {
145
+ if (compressed) {
146
+ return false;
147
+ }
148
+ compressed = true;
149
+ groups += 1;
150
+ i += 1;
151
+ continue;
152
+ }
61
153
 
62
- if (code === 58 /* ':' */) {
63
- hasColon = true;
64
- } else if (!(
65
- (code >= 48 && code <= 57) || // 0-9
66
- (code >= 97 && code <= 102) || // a-f
67
- (code >= 65 && code <= 70) // A-F (RFC 4291 §2.2: an IPv6 hextet is hex digits only)
68
- )) {
154
+ const start = i;
155
+ while (
156
+ i < end &&
157
+ i - start < 4 &&
158
+ hexValue(hostname.charCodeAt(i)) !== 16
159
+ ) {
160
+ i += 1;
161
+ }
162
+ if (i === start) {
163
+ return false;
164
+ }
165
+ if (i === end) {
166
+ return compressed || groups === 7;
167
+ }
168
+
169
+ if (hostname.charCodeAt(i) === 46 /* '.' */) {
170
+ return (
171
+ (compressed ? groups <= 6 : groups === 6) &&
172
+ isDottedDecimal(hostname, start, end)
173
+ );
174
+ }
175
+
176
+ // Anything else is a ':' followed by another group, or by a ':'.
177
+ if (hostname.charCodeAt(i) !== 58 /* ':' */ || i + 1 === end) {
69
178
  return false;
70
179
  }
180
+ groups += 1;
181
+ i += 1;
71
182
  }
72
183
 
73
- return hasColon;
184
+ return compressed && i === end;
74
185
  }
75
186
 
76
187
  /**
77
- * Check if `hostname` is *probably* a valid ip addr (either ipv6 or ipv4).
78
- * This *will not* work on any string. We need `hostname` to be a valid
79
- * hostname.
188
+ * What the host parser of browsers maps the non-ASCII code point `cp` to, as
189
+ * far as IP detection goes: nothing (deleted), '.', digits, 'a'-'f' or 'x', or
190
+ * else 'g', standing for any character that keeps a label from being a number.
191
+ * https://www.unicode.org/reports/tr46/#Processing
80
192
  */
81
- export default function isIp(hostname: string): boolean {
82
- return isProbablyIpv6(hostname) || isProbablyIpv4(hostname);
193
+ function mapCodePoint(cp: number): string {
194
+ // Most letters, as in internationalized domain names, are in blocks of the
195
+ // table without any entry.
196
+ if (
197
+ cp < 0x10000 &&
198
+ ((ipMappingBlocks[cp >> 13]! >>> ((cp >> 8) & 31)) & 1) === 0
199
+ ) {
200
+ return 'g';
201
+ }
202
+ let low = 0;
203
+ let high = ipMappingFirst.length - 1;
204
+ while (low <= high) {
205
+ const mid = (low + high) >>> 1;
206
+ if (cp < ipMappingFirst[mid]!) {
207
+ high = mid - 1;
208
+ } else if (cp > ipMappingLast[mid]!) {
209
+ low = mid + 1;
210
+ } else {
211
+ const value = ipMappingValue[mid]!;
212
+ const offset = cp - ipMappingFirst[mid]!;
213
+ if (value === 0) {
214
+ return '';
215
+ }
216
+ if (value < 128) {
217
+ return String.fromCharCode(value + offset);
218
+ }
219
+ if (value < 2000) {
220
+ return String(value - 1000 + offset);
221
+ }
222
+ return String.fromCharCode(value >> 8, value & 255);
223
+ }
224
+ }
225
+ return 'g';
226
+ }
227
+
228
+ /**
229
+ * `isIp` for a host holding non-ASCII characters, read as browsers read it:
230
+ * they first map some characters to digits or dots and delete others, so that
231
+ * `127.0.0.1`, or `127.0.0.1` followed by a zero-width space, is 127.0.0.1
232
+ * for them. The host is mapped the same way, as far as IP detection goes, and
233
+ * checked again.
234
+ */
235
+ function isMappedIp(hostname: string): boolean | null {
236
+ // Most such hosts are internationalized domain names, with a character that
237
+ // keeps their last label from being a number: find it first.
238
+ for (let i = hostname.length - 1; i >= 0; i -= 1) {
239
+ let cp = hostname.charCodeAt(i);
240
+ if (cp === 46 /* '.' */) {
241
+ break;
242
+ }
243
+ if (cp < 128) {
244
+ if (hexValue(cp) === 16 && (cp | 32) !== 120 /* 'x' */) {
245
+ return false;
246
+ }
247
+ continue;
248
+ }
249
+ // Most letters are in blocks of 256 code points without any entry.
250
+ if (
251
+ cp < 0xd800 &&
252
+ ((ipMappingBlocks[cp >> 13]! >>> ((cp >> 8) & 31)) & 1) === 0
253
+ ) {
254
+ return false;
255
+ }
256
+ if (cp >= 0xdc00 && cp <= 0xdfff && i > 0) {
257
+ const high = hostname.charCodeAt(i - 1);
258
+ if (high >= 0xd800 && high <= 0xdbff) {
259
+ cp = (high - 0xd800) * 0x400 + (cp - 0xdc00) + 0x10000;
260
+ i -= 1;
261
+ }
262
+ }
263
+ const mapped = mapCodePoint(cp);
264
+ if (mapped === 'g') {
265
+ return false;
266
+ }
267
+ if (mapped === '.') {
268
+ break;
269
+ }
270
+ }
271
+
272
+ // Browsers read an IPv6 address, between brackets, as written: a host
273
+ // holding non-ASCII characters is never one.
274
+ if (hostname.includes(':')) {
275
+ return false;
276
+ }
277
+
278
+ let ascii = '';
279
+ for (let i = 0; i < hostname.length; i += 1) {
280
+ const code = hostname.charCodeAt(i);
281
+ if (code < 128) {
282
+ ascii += hostname.charAt(i);
283
+ } else {
284
+ let cp = code;
285
+ if (code >= 0xd800 && code <= 0xdbff) {
286
+ const low = hostname.charCodeAt(i + 1);
287
+ if (low >= 0xdc00 && low <= 0xdfff) {
288
+ cp = (code - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;
289
+ i += 1;
290
+ }
291
+ }
292
+ ascii += mapCodePoint(cp);
293
+ }
294
+ }
295
+
296
+ // Trailing dots go, as callers remove them from `hostname`.
297
+ let end = ascii.length;
298
+ while (end > 1 && ascii.charCodeAt(end - 1) === 46 /* '.' */) {
299
+ end -= 1;
300
+ }
301
+ return isIp(ascii.slice(0, end));
302
+ }
303
+
304
+ /**
305
+ * For a host ending in a number without being an IP address in ASCII: `null`,
306
+ * unless it holds non-ASCII characters, which browsers may map (see
307
+ * `isMappedIp`).
308
+ */
309
+ function isNonAsciiIp(hostname: string): boolean | null {
310
+ for (let i = 0; i < hostname.length; i += 1) {
311
+ if (hostname.charCodeAt(i) >= 128) {
312
+ return isMappedIp(hostname);
313
+ }
314
+ }
315
+ return null;
316
+ }
317
+
318
+ /**
319
+ * Check if `hostname` is an IP address (either IPv4 or IPv6).
320
+ *
321
+ * The answer is `null` for a host ending in a number without being an IPv4
322
+ * address (`1.2.3.4.5`, `example.123`): browsers read such a host as an
323
+ * address and nothing else, so it is not a valid host, and never a domain.
324
+ * `hostname` has no trailing dot: callers strip them.
325
+ */
326
+ export default function isIp(hostname: string): boolean | null {
327
+ // Go backward over the digits ending `hostname`, decimal ones first, then
328
+ // hexadecimal ones, down to `code`, the character before them (NaN before
329
+ // the start of `hostname`). It tells what `hostname` may be, and most often
330
+ // that it is not an address.
331
+ const last = hostname.length - 1;
332
+ let i = last;
333
+ let code = hostname.charCodeAt(i);
334
+ while (code >= 48 && code <= 57 /* 0-9 */) {
335
+ i -= 1;
336
+ code = hostname.charCodeAt(i);
337
+ }
338
+ const decimal = i;
339
+ while (hexValue(code) !== 16) {
340
+ i -= 1;
341
+ code = hostname.charCodeAt(i);
342
+ }
343
+
344
+ // An IPv6 address ends with a group, which follows a ':', with "::" or
345
+ // with a ']'. Its last label is not a number then.
346
+ if (code === 58 /* ':' */ || code === 93 /* ']' */) {
347
+ return isIpv6(hostname);
348
+ }
349
+
350
+ // An IPv4 address ends with a number: a last label only made of decimal
351
+ // digits, or of "0x" followed by hexadecimal digits. An IPv6 address ending
352
+ // with an IPv4 one ends with a number too.
353
+ // https://url.spec.whatwg.org/#ends-in-a-number-checker
354
+ if (
355
+ (i === decimal && i !== last && (code === 46 /* '.' */ || i === -1)) ||
356
+ ((code | 32) === 120 /* 'x' */ &&
357
+ hostname.charCodeAt(i - 1) === 48 /* '0' */ &&
358
+ (i === 1 || hostname.charCodeAt(i - 2) === 46)) /* '.' */
359
+ ) {
360
+ return isIpv4(hostname) || isIpv6(hostname) ? true : isNonAsciiIp(hostname);
361
+ }
362
+
363
+ // A non-ASCII character right before the digits ending `hostname`, or one
364
+ // or two characters before their "x", may be one that browsers map to a
365
+ // digit or a dot, or delete: `hostname` may end in a number for them.
366
+ return code >= 128 ||
367
+ ((code | 32) === 120 /* 'x' */ &&
368
+ (hostname.charCodeAt(i - 1) >= 128 || hostname.charCodeAt(i - 2) >= 128))
369
+ ? isMappedIp(hostname)
370
+ : false;
83
371
  }
package/src/is-valid.ts CHANGED
@@ -7,6 +7,14 @@
7
7
  * If you need stricter validation, consider using an external library.
8
8
  */
9
9
 
10
+ // `charCodeAt.call(s, i)`, not `s.charCodeAt(i)`: V8 specializes a
11
+ // `s.charCodeAt` call site for at most four kinds of strings (flat, sliced,
12
+ // concatenated, internalized, of one or two bytes per character...). Past
13
+ // that, it finds the method through a generic cache and no longer inlines it,
14
+ // on every call. Hostnames come here from callers and from URLs, of any kind.
15
+ // eslint-disable-next-line @typescript-eslint/unbound-method
16
+ const charCodeAt = String.prototype.charCodeAt;
17
+
10
18
  // KEEP IN SYNC with `extract-hostname.ts` `isValidHostnameChar` + its inline
11
19
  // scan/verdict, which duplicate these structural rules to validate during
12
20
  // extraction (a perf fusion). That copy additionally accepts A-Z (the host is
@@ -34,9 +42,9 @@ export default function (hostname: string): boolean {
34
42
  }
35
43
 
36
44
  if (
37
- /*@__INLINE__*/ !isValidAscii(hostname.charCodeAt(0)) &&
38
- hostname.charCodeAt(0) !== 46 && // '.' (dot)
39
- hostname.charCodeAt(0) !== 95 // '_' (underscore)
45
+ /*@__INLINE__*/ !isValidAscii(charCodeAt.call(hostname, 0)) &&
46
+ charCodeAt.call(hostname, 0) !== 46 && // '.' (dot)
47
+ charCodeAt.call(hostname, 0) !== 95 // '_' (underscore)
40
48
  ) {
41
49
  return false;
42
50
  }
@@ -47,7 +55,7 @@ export default function (hostname: string): boolean {
47
55
  const len = hostname.length;
48
56
 
49
57
  for (let i = 0; i < len; i += 1) {
50
- const code = hostname.charCodeAt(i);
58
+ const code = charCodeAt.call(hostname, i);
51
59
  if (code === 46 /* '.' */) {
52
60
  if (
53
61
  // Check that previous label is < 63 bytes long (64 = 63 + '.')
package/src/options.ts CHANGED
@@ -43,8 +43,9 @@ function setDefaultsImpl({
43
43
 
44
44
  const DEFAULT_OPTIONS = /*@__INLINE__*/ setDefaultsImpl({});
45
45
 
46
- export function setDefaults(options?: Partial<IOptions>): IOptions {
47
- if (options === undefined) {
46
+ export function setDefaults(options?: Partial<IOptions> | null): IOptions {
47
+ // `null` as well: untyped callers pass it to mean "no options".
48
+ if (options === undefined || options === null) {
48
49
  return DEFAULT_OPTIONS;
49
50
  }
50
51