m06_task3.js 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.idea/.name +1 -0
- package/.idea/inspectionProfiles/Project_Default.xml +10 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/node_lab_6.iml +12 -0
- package/06_task2.html +73 -0
- package/06_task2.js +52 -0
- package/06_task3.js +3 -0
- package/06_task4.js +3 -0
- package/m06_task3.js +28 -0
- package/package/index.js +28 -0
- package/package/node_modules/.package-lock.json +31 -0
- package/package/node_modules/@types/node/LICENSE +21 -0
- package/package/node_modules/@types/node/README.md +16 -0
- package/package/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/package/node_modules/@types/node/assert.d.ts +961 -0
- package/package/node_modules/@types/node/async_hooks.d.ts +501 -0
- package/package/node_modules/@types/node/buffer.d.ts +2258 -0
- package/package/node_modules/@types/node/child_process.d.ts +1369 -0
- package/package/node_modules/@types/node/cluster.d.ts +410 -0
- package/package/node_modules/@types/node/console.d.ts +412 -0
- package/package/node_modules/@types/node/constants.d.ts +18 -0
- package/package/node_modules/@types/node/crypto.d.ts +3964 -0
- package/package/node_modules/@types/node/dgram.d.ts +545 -0
- package/package/node_modules/@types/node/diagnostics_channel.d.ts +153 -0
- package/package/node_modules/@types/node/dns/promises.d.ts +370 -0
- package/package/node_modules/@types/node/dns.d.ts +659 -0
- package/package/node_modules/@types/node/dom-events.d.ts +126 -0
- package/package/node_modules/@types/node/domain.d.ts +170 -0
- package/package/node_modules/@types/node/events.d.ts +678 -0
- package/package/node_modules/@types/node/fs/promises.d.ts +1138 -0
- package/package/node_modules/@types/node/fs.d.ts +3872 -0
- package/package/node_modules/@types/node/globals.d.ts +300 -0
- package/package/node_modules/@types/node/globals.global.d.ts +1 -0
- package/package/node_modules/@types/node/http.d.ts +1614 -0
- package/package/node_modules/@types/node/http2.d.ts +2134 -0
- package/package/node_modules/@types/node/https.d.ts +541 -0
- package/package/node_modules/@types/node/index.d.ts +133 -0
- package/package/node_modules/@types/node/inspector.d.ts +2741 -0
- package/package/node_modules/@types/node/module.d.ts +114 -0
- package/package/node_modules/@types/node/net.d.ts +869 -0
- package/package/node_modules/@types/node/os.d.ts +466 -0
- package/package/node_modules/@types/node/package.json +232 -0
- package/package/node_modules/@types/node/path.d.ts +191 -0
- package/package/node_modules/@types/node/perf_hooks.d.ts +625 -0
- package/package/node_modules/@types/node/process.d.ts +1482 -0
- package/package/node_modules/@types/node/punycode.d.ts +117 -0
- package/package/node_modules/@types/node/querystring.d.ts +131 -0
- package/package/node_modules/@types/node/readline/promises.d.ts +143 -0
- package/package/node_modules/@types/node/readline.d.ts +653 -0
- package/package/node_modules/@types/node/repl.d.ts +424 -0
- package/package/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/package/node_modules/@types/node/stream/promises.d.ts +42 -0
- package/package/node_modules/@types/node/stream/web.d.ts +330 -0
- package/package/node_modules/@types/node/stream.d.ts +1340 -0
- package/package/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/package/node_modules/@types/node/test.d.ts +314 -0
- package/package/node_modules/@types/node/timers/promises.d.ts +68 -0
- package/package/node_modules/@types/node/timers.d.ts +94 -0
- package/package/node_modules/@types/node/tls.d.ts +1028 -0
- package/package/node_modules/@types/node/trace_events.d.ts +171 -0
- package/package/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
- package/package/node_modules/@types/node/ts4.8/assert.d.ts +961 -0
- package/package/node_modules/@types/node/ts4.8/async_hooks.d.ts +501 -0
- package/package/node_modules/@types/node/ts4.8/buffer.d.ts +2259 -0
- package/package/node_modules/@types/node/ts4.8/child_process.d.ts +1369 -0
- package/package/node_modules/@types/node/ts4.8/cluster.d.ts +410 -0
- package/package/node_modules/@types/node/ts4.8/console.d.ts +412 -0
- package/package/node_modules/@types/node/ts4.8/constants.d.ts +18 -0
- package/package/node_modules/@types/node/ts4.8/crypto.d.ts +3964 -0
- package/package/node_modules/@types/node/ts4.8/dgram.d.ts +545 -0
- package/package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +153 -0
- package/package/node_modules/@types/node/ts4.8/dns/promises.d.ts +370 -0
- package/package/node_modules/@types/node/ts4.8/dns.d.ts +659 -0
- package/package/node_modules/@types/node/ts4.8/dom-events.d.ts +126 -0
- package/package/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
- package/package/node_modules/@types/node/ts4.8/events.d.ts +678 -0
- package/package/node_modules/@types/node/ts4.8/fs/promises.d.ts +1138 -0
- package/package/node_modules/@types/node/ts4.8/fs.d.ts +3872 -0
- package/package/node_modules/@types/node/ts4.8/globals.d.ts +294 -0
- package/package/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
- package/package/node_modules/@types/node/ts4.8/http.d.ts +1614 -0
- package/package/node_modules/@types/node/ts4.8/http2.d.ts +2134 -0
- package/package/node_modules/@types/node/ts4.8/https.d.ts +541 -0
- package/package/node_modules/@types/node/ts4.8/index.d.ts +88 -0
- package/package/node_modules/@types/node/ts4.8/inspector.d.ts +2741 -0
- package/package/node_modules/@types/node/ts4.8/module.d.ts +114 -0
- package/package/node_modules/@types/node/ts4.8/net.d.ts +869 -0
- package/package/node_modules/@types/node/ts4.8/os.d.ts +466 -0
- package/package/node_modules/@types/node/ts4.8/path.d.ts +191 -0
- package/package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +625 -0
- package/package/node_modules/@types/node/ts4.8/process.d.ts +1482 -0
- package/package/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
- package/package/node_modules/@types/node/ts4.8/querystring.d.ts +131 -0
- package/package/node_modules/@types/node/ts4.8/readline/promises.d.ts +143 -0
- package/package/node_modules/@types/node/ts4.8/readline.d.ts +653 -0
- package/package/node_modules/@types/node/ts4.8/repl.d.ts +424 -0
- package/package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
- package/package/node_modules/@types/node/ts4.8/stream/promises.d.ts +42 -0
- package/package/node_modules/@types/node/ts4.8/stream/web.d.ts +330 -0
- package/package/node_modules/@types/node/ts4.8/stream.d.ts +1340 -0
- package/package/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
- package/package/node_modules/@types/node/ts4.8/test.d.ts +314 -0
- package/package/node_modules/@types/node/ts4.8/timers/promises.d.ts +68 -0
- package/package/node_modules/@types/node/ts4.8/timers.d.ts +94 -0
- package/package/node_modules/@types/node/ts4.8/tls.d.ts +1028 -0
- package/package/node_modules/@types/node/ts4.8/trace_events.d.ts +171 -0
- package/package/node_modules/@types/node/ts4.8/tty.d.ts +206 -0
- package/package/node_modules/@types/node/ts4.8/url.d.ts +897 -0
- package/package/node_modules/@types/node/ts4.8/util.d.ts +1850 -0
- package/package/node_modules/@types/node/ts4.8/v8.d.ts +396 -0
- package/package/node_modules/@types/node/ts4.8/vm.d.ts +509 -0
- package/package/node_modules/@types/node/ts4.8/wasi.d.ts +158 -0
- package/package/node_modules/@types/node/ts4.8/worker_threads.d.ts +689 -0
- package/package/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
- package/package/node_modules/@types/node/tty.d.ts +206 -0
- package/package/node_modules/@types/node/url.d.ts +897 -0
- package/package/node_modules/@types/node/util.d.ts +1850 -0
- package/package/node_modules/@types/node/v8.d.ts +396 -0
- package/package/node_modules/@types/node/vm.d.ts +509 -0
- package/package/node_modules/@types/node/wasi.d.ts +158 -0
- package/package/node_modules/@types/node/worker_threads.d.ts +689 -0
- package/package/node_modules/@types/node/zlib.d.ts +517 -0
- package/package/node_modules/@types/nodemailer/LICENSE +21 -0
- package/package/node_modules/@types/nodemailer/README.md +16 -0
- package/package/node_modules/@types/nodemailer/index.d.ts +83 -0
- package/package/node_modules/@types/nodemailer/lib/addressparser/index.d.ts +31 -0
- package/package/node_modules/@types/nodemailer/lib/base64/index.d.ts +22 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/index.d.ts +45 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/message-parser.d.ts +75 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/relaxed-body.d.ts +75 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/sign.d.ts +11 -0
- package/package/node_modules/@types/nodemailer/lib/fetch/cookies.d.ts +54 -0
- package/package/node_modules/@types/nodemailer/lib/fetch/index.d.ts +38 -0
- package/package/node_modules/@types/nodemailer/lib/json-transport/index.d.ts +50 -0
- package/package/node_modules/@types/nodemailer/lib/mail-composer/index.d.ts +25 -0
- package/package/node_modules/@types/nodemailer/lib/mailer/index.d.ts +230 -0
- package/package/node_modules/@types/nodemailer/lib/mailer/mail-message.d.ts +28 -0
- package/package/node_modules/@types/nodemailer/lib/mime-funcs/index.d.ts +87 -0
- package/package/node_modules/@types/nodemailer/lib/mime-funcs/mime-types.d.ts +2 -0
- package/package/node_modules/@types/nodemailer/lib/mime-node/index.d.ts +137 -0
- package/package/node_modules/@types/nodemailer/lib/mime-node/last-newline.d.ts +9 -0
- package/package/node_modules/@types/nodemailer/lib/qp/index.d.ts +23 -0
- package/package/node_modules/@types/nodemailer/lib/sendmail-transport/index.d.ts +53 -0
- package/package/node_modules/@types/nodemailer/lib/sendmail-transport/le-unix.d.ts +7 -0
- package/package/node_modules/@types/nodemailer/lib/sendmail-transport/le-windows.d.ts +7 -0
- package/package/node_modules/@types/nodemailer/lib/ses-transport/index.d.ts +136 -0
- package/package/node_modules/@types/nodemailer/lib/shared/index.d.ts +51 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-connection/data-stream.d.ts +11 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-connection/http-proxy-client.d.ts +11 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-connection/index.d.ts +254 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-pool/index.d.ts +90 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-pool/pool-resource.d.ts +66 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-transport/index.d.ts +115 -0
- package/package/node_modules/@types/nodemailer/lib/stream-transport/index.d.ts +56 -0
- package/package/node_modules/@types/nodemailer/lib/well-known/index.d.ts +6 -0
- package/package/node_modules/@types/nodemailer/lib/xoauth2/index.d.ts +110 -0
- package/package/node_modules/@types/nodemailer/package.json +37 -0
- package/package/node_modules/nodemailer/.gitattributes +6 -0
- package/package/node_modules/nodemailer/.prettierrc.js +8 -0
- package/package/node_modules/nodemailer/CHANGELOG.md +715 -0
- package/package/node_modules/nodemailer/CODE_OF_CONDUCT.md +76 -0
- package/package/node_modules/nodemailer/CONTRIBUTING.md +67 -0
- package/package/node_modules/nodemailer/LICENSE +16 -0
- package/package/node_modules/nodemailer/README.md +93 -0
- package/package/node_modules/nodemailer/SECURITY.txt +22 -0
- package/package/node_modules/nodemailer/lib/addressparser/index.js +313 -0
- package/package/node_modules/nodemailer/lib/base64/index.js +142 -0
- package/package/node_modules/nodemailer/lib/dkim/index.js +251 -0
- package/package/node_modules/nodemailer/lib/dkim/message-parser.js +155 -0
- package/package/node_modules/nodemailer/lib/dkim/relaxed-body.js +154 -0
- package/package/node_modules/nodemailer/lib/dkim/sign.js +117 -0
- package/package/node_modules/nodemailer/lib/fetch/cookies.js +281 -0
- package/package/node_modules/nodemailer/lib/fetch/index.js +269 -0
- package/package/node_modules/nodemailer/lib/json-transport/index.js +82 -0
- package/package/node_modules/nodemailer/lib/mail-composer/index.js +558 -0
- package/package/node_modules/nodemailer/lib/mailer/index.js +427 -0
- package/package/node_modules/nodemailer/lib/mailer/mail-message.js +315 -0
- package/package/node_modules/nodemailer/lib/mime-funcs/index.js +619 -0
- package/package/node_modules/nodemailer/lib/mime-funcs/mime-types.js +2102 -0
- package/package/node_modules/nodemailer/lib/mime-node/index.js +1290 -0
- package/package/node_modules/nodemailer/lib/mime-node/last-newline.js +33 -0
- package/package/node_modules/nodemailer/lib/mime-node/le-unix.js +43 -0
- package/package/node_modules/nodemailer/lib/mime-node/le-windows.js +52 -0
- package/package/node_modules/nodemailer/lib/nodemailer.js +143 -0
- package/package/node_modules/nodemailer/lib/qp/index.js +219 -0
- package/package/node_modules/nodemailer/lib/sendmail-transport/index.js +210 -0
- package/package/node_modules/nodemailer/lib/ses-transport/index.js +349 -0
- package/package/node_modules/nodemailer/lib/shared/index.js +639 -0
- package/package/node_modules/nodemailer/lib/smtp-connection/data-stream.js +108 -0
- package/package/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +143 -0
- package/package/node_modules/nodemailer/lib/smtp-connection/index.js +1786 -0
- package/package/node_modules/nodemailer/lib/smtp-pool/index.js +648 -0
- package/package/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +253 -0
- package/package/node_modules/nodemailer/lib/smtp-transport/index.js +416 -0
- package/package/node_modules/nodemailer/lib/stream-transport/index.js +135 -0
- package/package/node_modules/nodemailer/lib/well-known/index.js +47 -0
- package/package/node_modules/nodemailer/lib/well-known/services.json +286 -0
- package/package/node_modules/nodemailer/lib/xoauth2/index.js +376 -0
- package/package/node_modules/nodemailer/package.json +46 -0
- package/package/node_modules/nodemailer/postinstall.js +101 -0
- package/package/package-lock.json +60 -0
- package/package/package.json +6 -0
- package/package.json +19 -0
@@ -0,0 +1,897 @@
|
|
1
|
+
/**
|
2
|
+
* The `url` module provides utilities for URL resolution and parsing. It can be
|
3
|
+
* accessed using:
|
4
|
+
*
|
5
|
+
* ```js
|
6
|
+
* import url from 'url';
|
7
|
+
* ```
|
8
|
+
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/url.js)
|
9
|
+
*/
|
10
|
+
declare module 'url' {
|
11
|
+
import { Blob as NodeBlob } from 'node:buffer';
|
12
|
+
import { ClientRequestArgs } from 'node:http';
|
13
|
+
import { ParsedUrlQuery, ParsedUrlQueryInput } from 'node:querystring';
|
14
|
+
// Input to `url.format`
|
15
|
+
interface UrlObject {
|
16
|
+
auth?: string | null | undefined;
|
17
|
+
hash?: string | null | undefined;
|
18
|
+
host?: string | null | undefined;
|
19
|
+
hostname?: string | null | undefined;
|
20
|
+
href?: string | null | undefined;
|
21
|
+
pathname?: string | null | undefined;
|
22
|
+
protocol?: string | null | undefined;
|
23
|
+
search?: string | null | undefined;
|
24
|
+
slashes?: boolean | null | undefined;
|
25
|
+
port?: string | number | null | undefined;
|
26
|
+
query?: string | null | ParsedUrlQueryInput | undefined;
|
27
|
+
}
|
28
|
+
// Output of `url.parse`
|
29
|
+
interface Url {
|
30
|
+
auth: string | null;
|
31
|
+
hash: string | null;
|
32
|
+
host: string | null;
|
33
|
+
hostname: string | null;
|
34
|
+
href: string;
|
35
|
+
path: string | null;
|
36
|
+
pathname: string | null;
|
37
|
+
protocol: string | null;
|
38
|
+
search: string | null;
|
39
|
+
slashes: boolean | null;
|
40
|
+
port: string | null;
|
41
|
+
query: string | null | ParsedUrlQuery;
|
42
|
+
}
|
43
|
+
interface UrlWithParsedQuery extends Url {
|
44
|
+
query: ParsedUrlQuery;
|
45
|
+
}
|
46
|
+
interface UrlWithStringQuery extends Url {
|
47
|
+
query: string | null;
|
48
|
+
}
|
49
|
+
/**
|
50
|
+
* The `url.parse()` method takes a URL string, parses it, and returns a URL
|
51
|
+
* object.
|
52
|
+
*
|
53
|
+
* A `TypeError` is thrown if `urlString` is not a string.
|
54
|
+
*
|
55
|
+
* A `URIError` is thrown if the `auth` property is present but cannot be decoded.
|
56
|
+
*
|
57
|
+
* Use of the legacy `url.parse()` method is discouraged. Users should
|
58
|
+
* use the WHATWG `URL` API. Because the `url.parse()` method uses a
|
59
|
+
* lenient, non-standard algorithm for parsing URL strings, security
|
60
|
+
* issues can be introduced. Specifically, issues with [host name spoofing](https://hackerone.com/reports/678487) and
|
61
|
+
* incorrect handling of usernames and passwords have been identified.
|
62
|
+
*
|
63
|
+
* Deprecation of this API has been shelved for now primarily due to the the
|
64
|
+
* inability of the [WHATWG API to parse relative URLs](https://github.com/nodejs/node/issues/12682#issuecomment-1154492373).
|
65
|
+
* [Discussions are ongoing](https://github.com/whatwg/url/issues/531) for the best way to resolve this.
|
66
|
+
*
|
67
|
+
* @since v0.1.25
|
68
|
+
* @param urlString The URL string to parse.
|
69
|
+
* @param [parseQueryString=false] If `true`, the `query` property will always be set to an object returned by the {@link querystring} module's `parse()` method. If `false`, the `query` property
|
70
|
+
* on the returned URL object will be an unparsed, undecoded string.
|
71
|
+
* @param [slashesDenoteHost=false] If `true`, the first token after the literal string `//` and preceding the next `/` will be interpreted as the `host`. For instance, given `//foo/bar`, the
|
72
|
+
* result would be `{host: 'foo', pathname: '/bar'}` rather than `{pathname: '//foo/bar'}`.
|
73
|
+
*/
|
74
|
+
function parse(urlString: string): UrlWithStringQuery;
|
75
|
+
function parse(urlString: string, parseQueryString: false | undefined, slashesDenoteHost?: boolean): UrlWithStringQuery;
|
76
|
+
function parse(urlString: string, parseQueryString: true, slashesDenoteHost?: boolean): UrlWithParsedQuery;
|
77
|
+
function parse(urlString: string, parseQueryString: boolean, slashesDenoteHost?: boolean): Url;
|
78
|
+
/**
|
79
|
+
* The `url.format()` method returns a formatted URL string derived from`urlObject`.
|
80
|
+
*
|
81
|
+
* ```js
|
82
|
+
* const url = require('url');
|
83
|
+
* url.format({
|
84
|
+
* protocol: 'https',
|
85
|
+
* hostname: 'example.com',
|
86
|
+
* pathname: '/some/path',
|
87
|
+
* query: {
|
88
|
+
* page: 1,
|
89
|
+
* format: 'json'
|
90
|
+
* }
|
91
|
+
* });
|
92
|
+
*
|
93
|
+
* // => 'https://example.com/some/path?page=1&format=json'
|
94
|
+
* ```
|
95
|
+
*
|
96
|
+
* If `urlObject` is not an object or a string, `url.format()` will throw a `TypeError`.
|
97
|
+
*
|
98
|
+
* The formatting process operates as follows:
|
99
|
+
*
|
100
|
+
* * A new empty string `result` is created.
|
101
|
+
* * If `urlObject.protocol` is a string, it is appended as-is to `result`.
|
102
|
+
* * Otherwise, if `urlObject.protocol` is not `undefined` and is not a string, an `Error` is thrown.
|
103
|
+
* * For all string values of `urlObject.protocol` that _do not end_ with an ASCII
|
104
|
+
* colon (`:`) character, the literal string `:` will be appended to `result`.
|
105
|
+
* * If either of the following conditions is true, then the literal string `//`will be appended to `result`:
|
106
|
+
* * `urlObject.slashes` property is true;
|
107
|
+
* * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or`file`;
|
108
|
+
* * If the value of the `urlObject.auth` property is truthy, and either`urlObject.host` or `urlObject.hostname` are not `undefined`, the value of`urlObject.auth` will be coerced into a string
|
109
|
+
* and appended to `result`followed by the literal string `@`.
|
110
|
+
* * If the `urlObject.host` property is `undefined` then:
|
111
|
+
* * If the `urlObject.hostname` is a string, it is appended to `result`.
|
112
|
+
* * Otherwise, if `urlObject.hostname` is not `undefined` and is not a string,
|
113
|
+
* an `Error` is thrown.
|
114
|
+
* * If the `urlObject.port` property value is truthy, and `urlObject.hostname`is not `undefined`:
|
115
|
+
* * The literal string `:` is appended to `result`, and
|
116
|
+
* * The value of `urlObject.port` is coerced to a string and appended to`result`.
|
117
|
+
* * Otherwise, if the `urlObject.host` property value is truthy, the value of`urlObject.host` is coerced to a string and appended to `result`.
|
118
|
+
* * If the `urlObject.pathname` property is a string that is not an empty string:
|
119
|
+
* * If the `urlObject.pathname`_does not start_ with an ASCII forward slash
|
120
|
+
* (`/`), then the literal string `'/'` is appended to `result`.
|
121
|
+
* * The value of `urlObject.pathname` is appended to `result`.
|
122
|
+
* * Otherwise, if `urlObject.pathname` is not `undefined` and is not a string, an `Error` is thrown.
|
123
|
+
* * If the `urlObject.search` property is `undefined` and if the `urlObject.query`property is an `Object`, the literal string `?` is appended to `result`followed by the output of calling the
|
124
|
+
* `querystring` module's `stringify()`method passing the value of `urlObject.query`.
|
125
|
+
* * Otherwise, if `urlObject.search` is a string:
|
126
|
+
* * If the value of `urlObject.search`_does not start_ with the ASCII question
|
127
|
+
* mark (`?`) character, the literal string `?` is appended to `result`.
|
128
|
+
* * The value of `urlObject.search` is appended to `result`.
|
129
|
+
* * Otherwise, if `urlObject.search` is not `undefined` and is not a string, an `Error` is thrown.
|
130
|
+
* * If the `urlObject.hash` property is a string:
|
131
|
+
* * If the value of `urlObject.hash`_does not start_ with the ASCII hash (`#`)
|
132
|
+
* character, the literal string `#` is appended to `result`.
|
133
|
+
* * The value of `urlObject.hash` is appended to `result`.
|
134
|
+
* * Otherwise, if the `urlObject.hash` property is not `undefined` and is not a
|
135
|
+
* string, an `Error` is thrown.
|
136
|
+
* * `result` is returned.
|
137
|
+
* @since v0.1.25
|
138
|
+
* @deprecated Legacy: Use the WHATWG URL API instead.
|
139
|
+
* @param urlObject A URL object (as returned by `url.parse()` or constructed otherwise). If a string, it is converted to an object by passing it to `url.parse()`.
|
140
|
+
*/
|
141
|
+
function format(urlObject: URL, options?: URLFormatOptions): string;
|
142
|
+
/**
|
143
|
+
* The `url.format()` method returns a formatted URL string derived from`urlObject`.
|
144
|
+
*
|
145
|
+
* ```js
|
146
|
+
* const url = require('url');
|
147
|
+
* url.format({
|
148
|
+
* protocol: 'https',
|
149
|
+
* hostname: 'example.com',
|
150
|
+
* pathname: '/some/path',
|
151
|
+
* query: {
|
152
|
+
* page: 1,
|
153
|
+
* format: 'json'
|
154
|
+
* }
|
155
|
+
* });
|
156
|
+
*
|
157
|
+
* // => 'https://example.com/some/path?page=1&format=json'
|
158
|
+
* ```
|
159
|
+
*
|
160
|
+
* If `urlObject` is not an object or a string, `url.format()` will throw a `TypeError`.
|
161
|
+
*
|
162
|
+
* The formatting process operates as follows:
|
163
|
+
*
|
164
|
+
* * A new empty string `result` is created.
|
165
|
+
* * If `urlObject.protocol` is a string, it is appended as-is to `result`.
|
166
|
+
* * Otherwise, if `urlObject.protocol` is not `undefined` and is not a string, an `Error` is thrown.
|
167
|
+
* * For all string values of `urlObject.protocol` that _do not end_ with an ASCII
|
168
|
+
* colon (`:`) character, the literal string `:` will be appended to `result`.
|
169
|
+
* * If either of the following conditions is true, then the literal string `//`will be appended to `result`:
|
170
|
+
* * `urlObject.slashes` property is true;
|
171
|
+
* * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or`file`;
|
172
|
+
* * If the value of the `urlObject.auth` property is truthy, and either`urlObject.host` or `urlObject.hostname` are not `undefined`, the value of`urlObject.auth` will be coerced into a string
|
173
|
+
* and appended to `result`followed by the literal string `@`.
|
174
|
+
* * If the `urlObject.host` property is `undefined` then:
|
175
|
+
* * If the `urlObject.hostname` is a string, it is appended to `result`.
|
176
|
+
* * Otherwise, if `urlObject.hostname` is not `undefined` and is not a string,
|
177
|
+
* an `Error` is thrown.
|
178
|
+
* * If the `urlObject.port` property value is truthy, and `urlObject.hostname`is not `undefined`:
|
179
|
+
* * The literal string `:` is appended to `result`, and
|
180
|
+
* * The value of `urlObject.port` is coerced to a string and appended to`result`.
|
181
|
+
* * Otherwise, if the `urlObject.host` property value is truthy, the value of`urlObject.host` is coerced to a string and appended to `result`.
|
182
|
+
* * If the `urlObject.pathname` property is a string that is not an empty string:
|
183
|
+
* * If the `urlObject.pathname`_does not start_ with an ASCII forward slash
|
184
|
+
* (`/`), then the literal string `'/'` is appended to `result`.
|
185
|
+
* * The value of `urlObject.pathname` is appended to `result`.
|
186
|
+
* * Otherwise, if `urlObject.pathname` is not `undefined` and is not a string, an `Error` is thrown.
|
187
|
+
* * If the `urlObject.search` property is `undefined` and if the `urlObject.query`property is an `Object`, the literal string `?` is appended to `result`followed by the output of calling the
|
188
|
+
* `querystring` module's `stringify()`method passing the value of `urlObject.query`.
|
189
|
+
* * Otherwise, if `urlObject.search` is a string:
|
190
|
+
* * If the value of `urlObject.search`_does not start_ with the ASCII question
|
191
|
+
* mark (`?`) character, the literal string `?` is appended to `result`.
|
192
|
+
* * The value of `urlObject.search` is appended to `result`.
|
193
|
+
* * Otherwise, if `urlObject.search` is not `undefined` and is not a string, an `Error` is thrown.
|
194
|
+
* * If the `urlObject.hash` property is a string:
|
195
|
+
* * If the value of `urlObject.hash`_does not start_ with the ASCII hash (`#`)
|
196
|
+
* character, the literal string `#` is appended to `result`.
|
197
|
+
* * The value of `urlObject.hash` is appended to `result`.
|
198
|
+
* * Otherwise, if the `urlObject.hash` property is not `undefined` and is not a
|
199
|
+
* string, an `Error` is thrown.
|
200
|
+
* * `result` is returned.
|
201
|
+
* @since v0.1.25
|
202
|
+
* @deprecated Legacy: Use the WHATWG URL API instead.
|
203
|
+
* @param urlObject A URL object (as returned by `url.parse()` or constructed otherwise). If a string, it is converted to an object by passing it to `url.parse()`.
|
204
|
+
*/
|
205
|
+
function format(urlObject: UrlObject | string): string;
|
206
|
+
/**
|
207
|
+
* The `url.resolve()` method resolves a target URL relative to a base URL in a
|
208
|
+
* manner similar to that of a web browser resolving an anchor tag.
|
209
|
+
*
|
210
|
+
* ```js
|
211
|
+
* const url = require('url');
|
212
|
+
* url.resolve('/one/two/three', 'four'); // '/one/two/four'
|
213
|
+
* url.resolve('http://example.com/', '/one'); // 'http://example.com/one'
|
214
|
+
* url.resolve('http://example.com/one', '/two'); // 'http://example.com/two'
|
215
|
+
* ```
|
216
|
+
*
|
217
|
+
* To achieve the same result using the WHATWG URL API:
|
218
|
+
*
|
219
|
+
* ```js
|
220
|
+
* function resolve(from, to) {
|
221
|
+
* const resolvedUrl = new URL(to, new URL(from, 'resolve://'));
|
222
|
+
* if (resolvedUrl.protocol === 'resolve:') {
|
223
|
+
* // `from` is a relative URL.
|
224
|
+
* const { pathname, search, hash } = resolvedUrl;
|
225
|
+
* return pathname + search + hash;
|
226
|
+
* }
|
227
|
+
* return resolvedUrl.toString();
|
228
|
+
* }
|
229
|
+
*
|
230
|
+
* resolve('/one/two/three', 'four'); // '/one/two/four'
|
231
|
+
* resolve('http://example.com/', '/one'); // 'http://example.com/one'
|
232
|
+
* resolve('http://example.com/one', '/two'); // 'http://example.com/two'
|
233
|
+
* ```
|
234
|
+
* @since v0.1.25
|
235
|
+
* @deprecated Legacy: Use the WHATWG URL API instead.
|
236
|
+
* @param from The base URL to use if `to` is a relative URL.
|
237
|
+
* @param to The target URL to resolve.
|
238
|
+
*/
|
239
|
+
function resolve(from: string, to: string): string;
|
240
|
+
/**
|
241
|
+
* Returns the [Punycode](https://tools.ietf.org/html/rfc5891#section-4.4) ASCII serialization of the `domain`. If `domain` is an
|
242
|
+
* invalid domain, the empty string is returned.
|
243
|
+
*
|
244
|
+
* It performs the inverse operation to {@link domainToUnicode}.
|
245
|
+
*
|
246
|
+
* This feature is only available if the `node` executable was compiled with `ICU` enabled. If not, the domain names are passed through unchanged.
|
247
|
+
*
|
248
|
+
* ```js
|
249
|
+
* import url from 'url';
|
250
|
+
*
|
251
|
+
* console.log(url.domainToASCII('español.com'));
|
252
|
+
* // Prints xn--espaol-zwa.com
|
253
|
+
* console.log(url.domainToASCII('中文.com'));
|
254
|
+
* // Prints xn--fiq228c.com
|
255
|
+
* console.log(url.domainToASCII('xn--iñvalid.com'));
|
256
|
+
* // Prints an empty string
|
257
|
+
* ```
|
258
|
+
* @since v7.4.0, v6.13.0
|
259
|
+
*/
|
260
|
+
function domainToASCII(domain: string): string;
|
261
|
+
/**
|
262
|
+
* Returns the Unicode serialization of the `domain`. If `domain` is an invalid
|
263
|
+
* domain, the empty string is returned.
|
264
|
+
*
|
265
|
+
* It performs the inverse operation to {@link domainToASCII}.
|
266
|
+
*
|
267
|
+
* This feature is only available if the `node` executable was compiled with `ICU` enabled. If not, the domain names are passed through unchanged.
|
268
|
+
*
|
269
|
+
* ```js
|
270
|
+
* import url from 'url';
|
271
|
+
*
|
272
|
+
* console.log(url.domainToUnicode('xn--espaol-zwa.com'));
|
273
|
+
* // Prints español.com
|
274
|
+
* console.log(url.domainToUnicode('xn--fiq228c.com'));
|
275
|
+
* // Prints 中文.com
|
276
|
+
* console.log(url.domainToUnicode('xn--iñvalid.com'));
|
277
|
+
* // Prints an empty string
|
278
|
+
* ```
|
279
|
+
* @since v7.4.0, v6.13.0
|
280
|
+
*/
|
281
|
+
function domainToUnicode(domain: string): string;
|
282
|
+
/**
|
283
|
+
* This function ensures the correct decodings of percent-encoded characters as
|
284
|
+
* well as ensuring a cross-platform valid absolute path string.
|
285
|
+
*
|
286
|
+
* ```js
|
287
|
+
* import { fileURLToPath } from 'url';
|
288
|
+
*
|
289
|
+
* const __filename = fileURLToPath(import.meta.url);
|
290
|
+
*
|
291
|
+
* new URL('file:///C:/path/').pathname; // Incorrect: /C:/path/
|
292
|
+
* fileURLToPath('file:///C:/path/'); // Correct: C:\path\ (Windows)
|
293
|
+
*
|
294
|
+
* new URL('file://nas/foo.txt').pathname; // Incorrect: /foo.txt
|
295
|
+
* fileURLToPath('file://nas/foo.txt'); // Correct: \\nas\foo.txt (Windows)
|
296
|
+
*
|
297
|
+
* new URL('file:///你好.txt').pathname; // Incorrect: /%E4%BD%A0%E5%A5%BD.txt
|
298
|
+
* fileURLToPath('file:///你好.txt'); // Correct: /你好.txt (POSIX)
|
299
|
+
*
|
300
|
+
* new URL('file:///hello world').pathname; // Incorrect: /hello%20world
|
301
|
+
* fileURLToPath('file:///hello world'); // Correct: /hello world (POSIX)
|
302
|
+
* ```
|
303
|
+
* @since v10.12.0
|
304
|
+
* @param url The file URL string or URL object to convert to a path.
|
305
|
+
* @return The fully-resolved platform-specific Node.js file path.
|
306
|
+
*/
|
307
|
+
function fileURLToPath(url: string | URL): string;
|
308
|
+
/**
|
309
|
+
* This function ensures that `path` is resolved absolutely, and that the URL
|
310
|
+
* control characters are correctly encoded when converting into a File URL.
|
311
|
+
*
|
312
|
+
* ```js
|
313
|
+
* import { pathToFileURL } from 'url';
|
314
|
+
*
|
315
|
+
* new URL('/foo#1', 'file:'); // Incorrect: file:///foo#1
|
316
|
+
* pathToFileURL('/foo#1'); // Correct: file:///foo%231 (POSIX)
|
317
|
+
*
|
318
|
+
* new URL('/some/path%.c', 'file:'); // Incorrect: file:///some/path%.c
|
319
|
+
* pathToFileURL('/some/path%.c'); // Correct: file:///some/path%25.c (POSIX)
|
320
|
+
* ```
|
321
|
+
* @since v10.12.0
|
322
|
+
* @param path The path to convert to a File URL.
|
323
|
+
* @return The file URL object.
|
324
|
+
*/
|
325
|
+
function pathToFileURL(path: string): URL;
|
326
|
+
/**
|
327
|
+
* This utility function converts a URL object into an ordinary options object as
|
328
|
+
* expected by the `http.request()` and `https.request()` APIs.
|
329
|
+
*
|
330
|
+
* ```js
|
331
|
+
* import { urlToHttpOptions } from 'url';
|
332
|
+
* const myURL = new URL('https://a:b@測試?abc#foo');
|
333
|
+
*
|
334
|
+
* console.log(urlToHttpOptions(myURL));
|
335
|
+
* /*
|
336
|
+
* {
|
337
|
+
* protocol: 'https:',
|
338
|
+
* hostname: 'xn--g6w251d',
|
339
|
+
* hash: '#foo',
|
340
|
+
* search: '?abc',
|
341
|
+
* pathname: '/',
|
342
|
+
* path: '/?abc',
|
343
|
+
* href: 'https://a:b@xn--g6w251d/?abc#foo',
|
344
|
+
* auth: 'a:b'
|
345
|
+
* }
|
346
|
+
*
|
347
|
+
* ```
|
348
|
+
* @since v15.7.0, v14.18.0
|
349
|
+
* @param url The `WHATWG URL` object to convert to an options object.
|
350
|
+
* @return Options object
|
351
|
+
*/
|
352
|
+
function urlToHttpOptions(url: URL): ClientRequestArgs;
|
353
|
+
interface URLFormatOptions {
|
354
|
+
auth?: boolean | undefined;
|
355
|
+
fragment?: boolean | undefined;
|
356
|
+
search?: boolean | undefined;
|
357
|
+
unicode?: boolean | undefined;
|
358
|
+
}
|
359
|
+
/**
|
360
|
+
* Browser-compatible `URL` class, implemented by following the WHATWG URL
|
361
|
+
* Standard. [Examples of parsed URLs](https://url.spec.whatwg.org/#example-url-parsing) may be found in the Standard itself.
|
362
|
+
* The `URL` class is also available on the global object.
|
363
|
+
*
|
364
|
+
* In accordance with browser conventions, all properties of `URL` objects
|
365
|
+
* are implemented as getters and setters on the class prototype, rather than as
|
366
|
+
* data properties on the object itself. Thus, unlike `legacy urlObject` s,
|
367
|
+
* using the `delete` keyword on any properties of `URL` objects (e.g. `delete myURL.protocol`, `delete myURL.pathname`, etc) has no effect but will still
|
368
|
+
* return `true`.
|
369
|
+
* @since v7.0.0, v6.13.0
|
370
|
+
*/
|
371
|
+
class URL {
|
372
|
+
/**
|
373
|
+
* Creates a `'blob:nodedata:...'` URL string that represents the given `Blob` object and can be used to retrieve the `Blob` later.
|
374
|
+
*
|
375
|
+
* ```js
|
376
|
+
* const {
|
377
|
+
* Blob,
|
378
|
+
* resolveObjectURL,
|
379
|
+
* } = require('buffer');
|
380
|
+
*
|
381
|
+
* const blob = new Blob(['hello']);
|
382
|
+
* const id = URL.createObjectURL(blob);
|
383
|
+
*
|
384
|
+
* // later...
|
385
|
+
*
|
386
|
+
* const otherBlob = resolveObjectURL(id);
|
387
|
+
* console.log(otherBlob.size);
|
388
|
+
* ```
|
389
|
+
*
|
390
|
+
* The data stored by the registered `Blob` will be retained in memory until`URL.revokeObjectURL()` is called to remove it.
|
391
|
+
*
|
392
|
+
* `Blob` objects are registered within the current thread. If using Worker
|
393
|
+
* Threads, `Blob` objects registered within one Worker will not be available
|
394
|
+
* to other workers or the main thread.
|
395
|
+
* @since v16.7.0
|
396
|
+
* @experimental
|
397
|
+
*/
|
398
|
+
static createObjectURL(blob: NodeBlob): string;
|
399
|
+
/**
|
400
|
+
* Removes the stored `Blob` identified by the given ID. Attempting to revoke a
|
401
|
+
* ID that isn’t registered will silently fail.
|
402
|
+
* @since v16.7.0
|
403
|
+
* @experimental
|
404
|
+
* @param id A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`.
|
405
|
+
*/
|
406
|
+
static revokeObjectURL(objectUrl: string): void;
|
407
|
+
constructor(input: string, base?: string | URL);
|
408
|
+
/**
|
409
|
+
* Gets and sets the fragment portion of the URL.
|
410
|
+
*
|
411
|
+
* ```js
|
412
|
+
* const myURL = new URL('https://example.org/foo#bar');
|
413
|
+
* console.log(myURL.hash);
|
414
|
+
* // Prints #bar
|
415
|
+
*
|
416
|
+
* myURL.hash = 'baz';
|
417
|
+
* console.log(myURL.href);
|
418
|
+
* // Prints https://example.org/foo#baz
|
419
|
+
* ```
|
420
|
+
*
|
421
|
+
* Invalid URL characters included in the value assigned to the `hash` property
|
422
|
+
* are `percent-encoded`. The selection of which characters to
|
423
|
+
* percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
|
424
|
+
*/
|
425
|
+
hash: string;
|
426
|
+
/**
|
427
|
+
* Gets and sets the host portion of the URL.
|
428
|
+
*
|
429
|
+
* ```js
|
430
|
+
* const myURL = new URL('https://example.org:81/foo');
|
431
|
+
* console.log(myURL.host);
|
432
|
+
* // Prints example.org:81
|
433
|
+
*
|
434
|
+
* myURL.host = 'example.com:82';
|
435
|
+
* console.log(myURL.href);
|
436
|
+
* // Prints https://example.com:82/foo
|
437
|
+
* ```
|
438
|
+
*
|
439
|
+
* Invalid host values assigned to the `host` property are ignored.
|
440
|
+
*/
|
441
|
+
host: string;
|
442
|
+
/**
|
443
|
+
* Gets and sets the host name portion of the URL. The key difference between`url.host` and `url.hostname` is that `url.hostname` does _not_ include the
|
444
|
+
* port.
|
445
|
+
*
|
446
|
+
* ```js
|
447
|
+
* const myURL = new URL('https://example.org:81/foo');
|
448
|
+
* console.log(myURL.hostname);
|
449
|
+
* // Prints example.org
|
450
|
+
*
|
451
|
+
* // Setting the hostname does not change the port
|
452
|
+
* myURL.hostname = 'example.com:82';
|
453
|
+
* console.log(myURL.href);
|
454
|
+
* // Prints https://example.com:81/foo
|
455
|
+
*
|
456
|
+
* // Use myURL.host to change the hostname and port
|
457
|
+
* myURL.host = 'example.org:82';
|
458
|
+
* console.log(myURL.href);
|
459
|
+
* // Prints https://example.org:82/foo
|
460
|
+
* ```
|
461
|
+
*
|
462
|
+
* Invalid host name values assigned to the `hostname` property are ignored.
|
463
|
+
*/
|
464
|
+
hostname: string;
|
465
|
+
/**
|
466
|
+
* Gets and sets the serialized URL.
|
467
|
+
*
|
468
|
+
* ```js
|
469
|
+
* const myURL = new URL('https://example.org/foo');
|
470
|
+
* console.log(myURL.href);
|
471
|
+
* // Prints https://example.org/foo
|
472
|
+
*
|
473
|
+
* myURL.href = 'https://example.com/bar';
|
474
|
+
* console.log(myURL.href);
|
475
|
+
* // Prints https://example.com/bar
|
476
|
+
* ```
|
477
|
+
*
|
478
|
+
* Getting the value of the `href` property is equivalent to calling {@link toString}.
|
479
|
+
*
|
480
|
+
* Setting the value of this property to a new value is equivalent to creating a
|
481
|
+
* new `URL` object using `new URL(value)`. Each of the `URL`object's properties will be modified.
|
482
|
+
*
|
483
|
+
* If the value assigned to the `href` property is not a valid URL, a `TypeError`will be thrown.
|
484
|
+
*/
|
485
|
+
href: string;
|
486
|
+
/**
|
487
|
+
* Gets the read-only serialization of the URL's origin.
|
488
|
+
*
|
489
|
+
* ```js
|
490
|
+
* const myURL = new URL('https://example.org/foo/bar?baz');
|
491
|
+
* console.log(myURL.origin);
|
492
|
+
* // Prints https://example.org
|
493
|
+
* ```
|
494
|
+
*
|
495
|
+
* ```js
|
496
|
+
* const idnURL = new URL('https://測試');
|
497
|
+
* console.log(idnURL.origin);
|
498
|
+
* // Prints https://xn--g6w251d
|
499
|
+
*
|
500
|
+
* console.log(idnURL.hostname);
|
501
|
+
* // Prints xn--g6w251d
|
502
|
+
* ```
|
503
|
+
*/
|
504
|
+
readonly origin: string;
|
505
|
+
/**
|
506
|
+
* Gets and sets the password portion of the URL.
|
507
|
+
*
|
508
|
+
* ```js
|
509
|
+
* const myURL = new URL('https://abc:xyz@example.com');
|
510
|
+
* console.log(myURL.password);
|
511
|
+
* // Prints xyz
|
512
|
+
*
|
513
|
+
* myURL.password = '123';
|
514
|
+
* console.log(myURL.href);
|
515
|
+
* // Prints https://abc:123@example.com
|
516
|
+
* ```
|
517
|
+
*
|
518
|
+
* Invalid URL characters included in the value assigned to the `password` property
|
519
|
+
* are `percent-encoded`. The selection of which characters to
|
520
|
+
* percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
|
521
|
+
*/
|
522
|
+
password: string;
|
523
|
+
/**
|
524
|
+
* Gets and sets the path portion of the URL.
|
525
|
+
*
|
526
|
+
* ```js
|
527
|
+
* const myURL = new URL('https://example.org/abc/xyz?123');
|
528
|
+
* console.log(myURL.pathname);
|
529
|
+
* // Prints /abc/xyz
|
530
|
+
*
|
531
|
+
* myURL.pathname = '/abcdef';
|
532
|
+
* console.log(myURL.href);
|
533
|
+
* // Prints https://example.org/abcdef?123
|
534
|
+
* ```
|
535
|
+
*
|
536
|
+
* Invalid URL characters included in the value assigned to the `pathname`property are `percent-encoded`. The selection of which characters
|
537
|
+
* to percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
|
538
|
+
*/
|
539
|
+
pathname: string;
|
540
|
+
/**
|
541
|
+
* Gets and sets the port portion of the URL.
|
542
|
+
*
|
543
|
+
* The port value may be a number or a string containing a number in the range`0` to `65535` (inclusive). Setting the value to the default port of the`URL` objects given `protocol` will
|
544
|
+
* result in the `port` value becoming
|
545
|
+
* the empty string (`''`).
|
546
|
+
*
|
547
|
+
* The port value can be an empty string in which case the port depends on
|
548
|
+
* the protocol/scheme:
|
549
|
+
*
|
550
|
+
* <omitted>
|
551
|
+
*
|
552
|
+
* Upon assigning a value to the port, the value will first be converted to a
|
553
|
+
* string using `.toString()`.
|
554
|
+
*
|
555
|
+
* If that string is invalid but it begins with a number, the leading number is
|
556
|
+
* assigned to `port`.
|
557
|
+
* If the number lies outside the range denoted above, it is ignored.
|
558
|
+
*
|
559
|
+
* ```js
|
560
|
+
* const myURL = new URL('https://example.org:8888');
|
561
|
+
* console.log(myURL.port);
|
562
|
+
* // Prints 8888
|
563
|
+
*
|
564
|
+
* // Default ports are automatically transformed to the empty string
|
565
|
+
* // (HTTPS protocol's default port is 443)
|
566
|
+
* myURL.port = '443';
|
567
|
+
* console.log(myURL.port);
|
568
|
+
* // Prints the empty string
|
569
|
+
* console.log(myURL.href);
|
570
|
+
* // Prints https://example.org/
|
571
|
+
*
|
572
|
+
* myURL.port = 1234;
|
573
|
+
* console.log(myURL.port);
|
574
|
+
* // Prints 1234
|
575
|
+
* console.log(myURL.href);
|
576
|
+
* // Prints https://example.org:1234/
|
577
|
+
*
|
578
|
+
* // Completely invalid port strings are ignored
|
579
|
+
* myURL.port = 'abcd';
|
580
|
+
* console.log(myURL.port);
|
581
|
+
* // Prints 1234
|
582
|
+
*
|
583
|
+
* // Leading numbers are treated as a port number
|
584
|
+
* myURL.port = '5678abcd';
|
585
|
+
* console.log(myURL.port);
|
586
|
+
* // Prints 5678
|
587
|
+
*
|
588
|
+
* // Non-integers are truncated
|
589
|
+
* myURL.port = 1234.5678;
|
590
|
+
* console.log(myURL.port);
|
591
|
+
* // Prints 1234
|
592
|
+
*
|
593
|
+
* // Out-of-range numbers which are not represented in scientific notation
|
594
|
+
* // will be ignored.
|
595
|
+
* myURL.port = 1e10; // 10000000000, will be range-checked as described below
|
596
|
+
* console.log(myURL.port);
|
597
|
+
* // Prints 1234
|
598
|
+
* ```
|
599
|
+
*
|
600
|
+
* Numbers which contain a decimal point,
|
601
|
+
* such as floating-point numbers or numbers in scientific notation,
|
602
|
+
* are not an exception to this rule.
|
603
|
+
* Leading numbers up to the decimal point will be set as the URL's port,
|
604
|
+
* assuming they are valid:
|
605
|
+
*
|
606
|
+
* ```js
|
607
|
+
* myURL.port = 4.567e21;
|
608
|
+
* console.log(myURL.port);
|
609
|
+
* // Prints 4 (because it is the leading number in the string '4.567e21')
|
610
|
+
* ```
|
611
|
+
*/
|
612
|
+
port: string;
|
613
|
+
/**
|
614
|
+
* Gets and sets the protocol portion of the URL.
|
615
|
+
*
|
616
|
+
* ```js
|
617
|
+
* const myURL = new URL('https://example.org');
|
618
|
+
* console.log(myURL.protocol);
|
619
|
+
* // Prints https:
|
620
|
+
*
|
621
|
+
* myURL.protocol = 'ftp';
|
622
|
+
* console.log(myURL.href);
|
623
|
+
* // Prints ftp://example.org/
|
624
|
+
* ```
|
625
|
+
*
|
626
|
+
* Invalid URL protocol values assigned to the `protocol` property are ignored.
|
627
|
+
*/
|
628
|
+
protocol: string;
|
629
|
+
/**
|
630
|
+
* Gets and sets the serialized query portion of the URL.
|
631
|
+
*
|
632
|
+
* ```js
|
633
|
+
* const myURL = new URL('https://example.org/abc?123');
|
634
|
+
* console.log(myURL.search);
|
635
|
+
* // Prints ?123
|
636
|
+
*
|
637
|
+
* myURL.search = 'abc=xyz';
|
638
|
+
* console.log(myURL.href);
|
639
|
+
* // Prints https://example.org/abc?abc=xyz
|
640
|
+
* ```
|
641
|
+
*
|
642
|
+
* Any invalid URL characters appearing in the value assigned the `search`property will be `percent-encoded`. The selection of which
|
643
|
+
* characters to percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
|
644
|
+
*/
|
645
|
+
search: string;
|
646
|
+
/**
|
647
|
+
* Gets the `URLSearchParams` object representing the query parameters of the
|
648
|
+
* URL. This property is read-only but the `URLSearchParams` object it provides
|
649
|
+
* can be used to mutate the URL instance; to replace the entirety of query
|
650
|
+
* parameters of the URL, use the {@link search} setter. See `URLSearchParams` documentation for details.
|
651
|
+
*
|
652
|
+
* Use care when using `.searchParams` to modify the `URL` because,
|
653
|
+
* per the WHATWG specification, the `URLSearchParams` object uses
|
654
|
+
* different rules to determine which characters to percent-encode. For
|
655
|
+
* instance, the `URL` object will not percent encode the ASCII tilde (`~`)
|
656
|
+
* character, while `URLSearchParams` will always encode it:
|
657
|
+
*
|
658
|
+
* ```js
|
659
|
+
* const myUrl = new URL('https://example.org/abc?foo=~bar');
|
660
|
+
*
|
661
|
+
* console.log(myUrl.search); // prints ?foo=~bar
|
662
|
+
*
|
663
|
+
* // Modify the URL via searchParams...
|
664
|
+
* myUrl.searchParams.sort();
|
665
|
+
*
|
666
|
+
* console.log(myUrl.search); // prints ?foo=%7Ebar
|
667
|
+
* ```
|
668
|
+
*/
|
669
|
+
readonly searchParams: URLSearchParams;
|
670
|
+
/**
|
671
|
+
* Gets and sets the username portion of the URL.
|
672
|
+
*
|
673
|
+
* ```js
|
674
|
+
* const myURL = new URL('https://abc:xyz@example.com');
|
675
|
+
* console.log(myURL.username);
|
676
|
+
* // Prints abc
|
677
|
+
*
|
678
|
+
* myURL.username = '123';
|
679
|
+
* console.log(myURL.href);
|
680
|
+
* // Prints https://123:xyz@example.com/
|
681
|
+
* ```
|
682
|
+
*
|
683
|
+
* Any invalid URL characters appearing in the value assigned the `username`property will be `percent-encoded`. The selection of which
|
684
|
+
* characters to percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
|
685
|
+
*/
|
686
|
+
username: string;
|
687
|
+
/**
|
688
|
+
* The `toString()` method on the `URL` object returns the serialized URL. The
|
689
|
+
* value returned is equivalent to that of {@link href} and {@link toJSON}.
|
690
|
+
*/
|
691
|
+
toString(): string;
|
692
|
+
/**
|
693
|
+
* The `toJSON()` method on the `URL` object returns the serialized URL. The
|
694
|
+
* value returned is equivalent to that of {@link href} and {@link toString}.
|
695
|
+
*
|
696
|
+
* This method is automatically called when an `URL` object is serialized
|
697
|
+
* with [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).
|
698
|
+
*
|
699
|
+
* ```js
|
700
|
+
* const myURLs = [
|
701
|
+
* new URL('https://www.example.com'),
|
702
|
+
* new URL('https://test.example.org'),
|
703
|
+
* ];
|
704
|
+
* console.log(JSON.stringify(myURLs));
|
705
|
+
* // Prints ["https://www.example.com/","https://test.example.org/"]
|
706
|
+
* ```
|
707
|
+
*/
|
708
|
+
toJSON(): string;
|
709
|
+
}
|
710
|
+
/**
|
711
|
+
* The `URLSearchParams` API provides read and write access to the query of a`URL`. The `URLSearchParams` class can also be used standalone with one of the
|
712
|
+
* four following constructors.
|
713
|
+
* The `URLSearchParams` class is also available on the global object.
|
714
|
+
*
|
715
|
+
* The WHATWG `URLSearchParams` interface and the `querystring` module have
|
716
|
+
* similar purpose, but the purpose of the `querystring` module is more
|
717
|
+
* general, as it allows the customization of delimiter characters (`&` and `=`).
|
718
|
+
* On the other hand, this API is designed purely for URL query strings.
|
719
|
+
*
|
720
|
+
* ```js
|
721
|
+
* const myURL = new URL('https://example.org/?abc=123');
|
722
|
+
* console.log(myURL.searchParams.get('abc'));
|
723
|
+
* // Prints 123
|
724
|
+
*
|
725
|
+
* myURL.searchParams.append('abc', 'xyz');
|
726
|
+
* console.log(myURL.href);
|
727
|
+
* // Prints https://example.org/?abc=123&abc=xyz
|
728
|
+
*
|
729
|
+
* myURL.searchParams.delete('abc');
|
730
|
+
* myURL.searchParams.set('a', 'b');
|
731
|
+
* console.log(myURL.href);
|
732
|
+
* // Prints https://example.org/?a=b
|
733
|
+
*
|
734
|
+
* const newSearchParams = new URLSearchParams(myURL.searchParams);
|
735
|
+
* // The above is equivalent to
|
736
|
+
* // const newSearchParams = new URLSearchParams(myURL.search);
|
737
|
+
*
|
738
|
+
* newSearchParams.append('a', 'c');
|
739
|
+
* console.log(myURL.href);
|
740
|
+
* // Prints https://example.org/?a=b
|
741
|
+
* console.log(newSearchParams.toString());
|
742
|
+
* // Prints a=b&a=c
|
743
|
+
*
|
744
|
+
* // newSearchParams.toString() is implicitly called
|
745
|
+
* myURL.search = newSearchParams;
|
746
|
+
* console.log(myURL.href);
|
747
|
+
* // Prints https://example.org/?a=b&a=c
|
748
|
+
* newSearchParams.delete('a');
|
749
|
+
* console.log(myURL.href);
|
750
|
+
* // Prints https://example.org/?a=b&a=c
|
751
|
+
* ```
|
752
|
+
* @since v7.5.0, v6.13.0
|
753
|
+
*/
|
754
|
+
class URLSearchParams implements Iterable<[string, string]> {
|
755
|
+
constructor(init?: URLSearchParams | string | Record<string, string | ReadonlyArray<string>> | Iterable<[string, string]> | ReadonlyArray<[string, string]>);
|
756
|
+
/**
|
757
|
+
* Append a new name-value pair to the query string.
|
758
|
+
*/
|
759
|
+
append(name: string, value: string): void;
|
760
|
+
/**
|
761
|
+
* Remove all name-value pairs whose name is `name`.
|
762
|
+
*/
|
763
|
+
delete(name: string): void;
|
764
|
+
/**
|
765
|
+
* Returns an ES6 `Iterator` over each of the name-value pairs in the query.
|
766
|
+
* Each item of the iterator is a JavaScript `Array`. The first item of the `Array`is the `name`, the second item of the `Array` is the `value`.
|
767
|
+
*
|
768
|
+
* Alias for `urlSearchParams[@@iterator]()`.
|
769
|
+
*/
|
770
|
+
entries(): IterableIterator<[string, string]>;
|
771
|
+
/**
|
772
|
+
* Iterates over each name-value pair in the query and invokes the given function.
|
773
|
+
*
|
774
|
+
* ```js
|
775
|
+
* const myURL = new URL('https://example.org/?a=b&c=d');
|
776
|
+
* myURL.searchParams.forEach((value, name, searchParams) => {
|
777
|
+
* console.log(name, value, myURL.searchParams === searchParams);
|
778
|
+
* });
|
779
|
+
* // Prints:
|
780
|
+
* // a b true
|
781
|
+
* // c d true
|
782
|
+
* ```
|
783
|
+
* @param fn Invoked for each name-value pair in the query
|
784
|
+
* @param thisArg To be used as `this` value for when `fn` is called
|
785
|
+
*/
|
786
|
+
forEach<TThis = this>(callback: (this: TThis, value: string, name: string, searchParams: URLSearchParams) => void, thisArg?: TThis): void;
|
787
|
+
/**
|
788
|
+
* Returns the value of the first name-value pair whose name is `name`. If there
|
789
|
+
* are no such pairs, `null` is returned.
|
790
|
+
* @return or `null` if there is no name-value pair with the given `name`.
|
791
|
+
*/
|
792
|
+
get(name: string): string | null;
|
793
|
+
/**
|
794
|
+
* Returns the values of all name-value pairs whose name is `name`. If there are
|
795
|
+
* no such pairs, an empty array is returned.
|
796
|
+
*/
|
797
|
+
getAll(name: string): string[];
|
798
|
+
/**
|
799
|
+
* Returns `true` if there is at least one name-value pair whose name is `name`.
|
800
|
+
*/
|
801
|
+
has(name: string): boolean;
|
802
|
+
/**
|
803
|
+
* Returns an ES6 `Iterator` over the names of each name-value pair.
|
804
|
+
*
|
805
|
+
* ```js
|
806
|
+
* const params = new URLSearchParams('foo=bar&foo=baz');
|
807
|
+
* for (const name of params.keys()) {
|
808
|
+
* console.log(name);
|
809
|
+
* }
|
810
|
+
* // Prints:
|
811
|
+
* // foo
|
812
|
+
* // foo
|
813
|
+
* ```
|
814
|
+
*/
|
815
|
+
keys(): IterableIterator<string>;
|
816
|
+
/**
|
817
|
+
* Sets the value in the `URLSearchParams` object associated with `name` to`value`. If there are any pre-existing name-value pairs whose names are `name`,
|
818
|
+
* set the first such pair's value to `value` and remove all others. If not,
|
819
|
+
* append the name-value pair to the query string.
|
820
|
+
*
|
821
|
+
* ```js
|
822
|
+
* const params = new URLSearchParams();
|
823
|
+
* params.append('foo', 'bar');
|
824
|
+
* params.append('foo', 'baz');
|
825
|
+
* params.append('abc', 'def');
|
826
|
+
* console.log(params.toString());
|
827
|
+
* // Prints foo=bar&foo=baz&abc=def
|
828
|
+
*
|
829
|
+
* params.set('foo', 'def');
|
830
|
+
* params.set('xyz', 'opq');
|
831
|
+
* console.log(params.toString());
|
832
|
+
* // Prints foo=def&abc=def&xyz=opq
|
833
|
+
* ```
|
834
|
+
*/
|
835
|
+
set(name: string, value: string): void;
|
836
|
+
/**
|
837
|
+
* Sort all existing name-value pairs in-place by their names. Sorting is done
|
838
|
+
* with a [stable sorting algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability), so relative order between name-value pairs
|
839
|
+
* with the same name is preserved.
|
840
|
+
*
|
841
|
+
* This method can be used, in particular, to increase cache hits.
|
842
|
+
*
|
843
|
+
* ```js
|
844
|
+
* const params = new URLSearchParams('query[]=abc&type=search&query[]=123');
|
845
|
+
* params.sort();
|
846
|
+
* console.log(params.toString());
|
847
|
+
* // Prints query%5B%5D=abc&query%5B%5D=123&type=search
|
848
|
+
* ```
|
849
|
+
* @since v7.7.0, v6.13.0
|
850
|
+
*/
|
851
|
+
sort(): void;
|
852
|
+
/**
|
853
|
+
* Returns the search parameters serialized as a string, with characters
|
854
|
+
* percent-encoded where necessary.
|
855
|
+
*/
|
856
|
+
toString(): string;
|
857
|
+
/**
|
858
|
+
* Returns an ES6 `Iterator` over the values of each name-value pair.
|
859
|
+
*/
|
860
|
+
values(): IterableIterator<string>;
|
861
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
862
|
+
}
|
863
|
+
import { URL as _URL, URLSearchParams as _URLSearchParams } from 'url';
|
864
|
+
global {
|
865
|
+
interface URLSearchParams extends _URLSearchParams {}
|
866
|
+
interface URL extends _URL {}
|
867
|
+
interface Global {
|
868
|
+
URL: typeof _URL;
|
869
|
+
URLSearchParams: typeof _URLSearchParams;
|
870
|
+
}
|
871
|
+
/**
|
872
|
+
* `URL` class is a global reference for `require('url').URL`
|
873
|
+
* https://nodejs.org/api/url.html#the-whatwg-url-api
|
874
|
+
* @since v10.0.0
|
875
|
+
*/
|
876
|
+
var URL: typeof globalThis extends {
|
877
|
+
onmessage: any;
|
878
|
+
URL: infer T;
|
879
|
+
}
|
880
|
+
? T
|
881
|
+
: typeof _URL;
|
882
|
+
/**
|
883
|
+
* `URLSearchParams` class is a global reference for `require('url').URLSearchParams`
|
884
|
+
* https://nodejs.org/api/url.html#class-urlsearchparams
|
885
|
+
* @since v10.0.0
|
886
|
+
*/
|
887
|
+
var URLSearchParams: typeof globalThis extends {
|
888
|
+
onmessage: any;
|
889
|
+
URLSearchParams: infer T;
|
890
|
+
}
|
891
|
+
? T
|
892
|
+
: typeof _URLSearchParams;
|
893
|
+
}
|
894
|
+
}
|
895
|
+
declare module 'node:url' {
|
896
|
+
export * from 'url';
|
897
|
+
}
|