2012-02-27 11:09:35 -08:00
|
|
|
# URL
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2017-01-22 19:16:21 -08:00
|
|
|
<!--introduced_in=v0.10.0-->
|
|
|
|
|
2016-07-16 00:35:38 +02:00
|
|
|
> Stability: 2 - Stable
|
2012-03-02 15:14:03 -08:00
|
|
|
|
2020-06-22 13:56:08 -04:00
|
|
|
<!-- source_link=lib/url.js -->
|
|
|
|
|
2022-04-20 10:23:41 +02:00
|
|
|
The `node:url` module provides utilities for URL resolution and parsing. It can
|
|
|
|
be accessed using:
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2021-05-12 12:13:16 +02:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import url from 'node:url';
|
2021-05-12 12:13:16 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const url = require('node:url');
|
2016-05-20 13:11:09 -07:00
|
|
|
```
|
2015-08-28 16:58:18 -04:00
|
|
|
|
2020-06-14 14:49:34 -07:00
|
|
|
## URL strings and URL objects
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2016-05-20 13:11:09 -07:00
|
|
|
A URL string is a structured string containing multiple meaningful components.
|
|
|
|
When parsed, a URL object is returned containing properties for each of these
|
|
|
|
components.
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2022-04-20 10:23:41 +02:00
|
|
|
The `node:url` module provides two APIs for working with URLs: a legacy API that
|
|
|
|
is Node.js specific, and a newer API that implements the same
|
2017-04-28 14:00:50 -07:00
|
|
|
[WHATWG URL Standard][] used by web browsers.
|
|
|
|
|
2022-10-11 15:35:52 -07:00
|
|
|
A comparison between the WHATWG and legacy APIs is provided below. Above the URL
|
2020-11-17 00:06:14 -08:00
|
|
|
`'https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash'`, properties
|
2018-09-02 15:45:53 +03:00
|
|
|
of an object returned by the legacy `url.parse()` are shown. Below it are
|
2017-04-28 14:00:50 -07:00
|
|
|
properties of a WHATWG `URL` object.
|
|
|
|
|
2018-02-05 21:55:16 -08:00
|
|
|
WHATWG URL's `origin` property includes `protocol` and `host`, but not
|
2017-04-28 14:00:50 -07:00
|
|
|
`username` or `password`.
|
2010-11-21 17:22:34 -05:00
|
|
|
|
2020-04-23 11:01:52 -07:00
|
|
|
```text
|
2018-09-02 15:45:53 +03:00
|
|
|
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
|
|
|
|
│ href │
|
|
|
|
├──────────┬──┬─────────────────────┬────────────────────────┬───────────────────────────┬───────┤
|
|
|
|
│ protocol │ │ auth │ host │ path │ hash │
|
|
|
|
│ │ │ ├─────────────────┬──────┼──────────┬────────────────┤ │
|
|
|
|
│ │ │ │ hostname │ port │ pathname │ search │ │
|
|
|
|
│ │ │ │ │ │ ├─┬──────────────┤ │
|
|
|
|
│ │ │ │ │ │ │ │ query │ │
|
|
|
|
" https: // user : pass @ sub.example.com : 8080 /p/a/t/h ? query=string #hash "
|
|
|
|
│ │ │ │ │ hostname │ port │ │ │ │
|
|
|
|
│ │ │ │ ├─────────────────┴──────┤ │ │ │
|
|
|
|
│ protocol │ │ username │ password │ host │ │ │ │
|
|
|
|
├──────────┴──┼──────────┴──────────┼────────────────────────┤ │ │ │
|
|
|
|
│ origin │ │ origin │ pathname │ search │ hash │
|
|
|
|
├─────────────┴─────────────────────┴────────────────────────┴──────────┴────────────────┴───────┤
|
|
|
|
│ href │
|
|
|
|
└────────────────────────────────────────────────────────────────────────────────────────────────┘
|
2020-03-03 21:23:59 -08:00
|
|
|
(All spaces in the "" line should be ignored. They are purely for formatting.)
|
2016-05-20 13:11:09 -07:00
|
|
|
```
|
2012-04-30 10:30:05 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Parsing the URL string using the WHATWG API:
|
2014-05-07 18:59:23 +08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
```js
|
|
|
|
const myURL =
|
2018-09-02 15:45:53 +03:00
|
|
|
new URL('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
2014-05-07 18:59:23 +08:00
|
|
|
|
2022-10-11 15:35:52 -07:00
|
|
|
Parsing the URL string using the legacy API:
|
2010-11-21 17:22:34 -05:00
|
|
|
|
2021-05-12 12:13:16 +02:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import url from 'node:url';
|
2021-05-12 12:13:16 +02:00
|
|
|
const myURL =
|
|
|
|
url.parse('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const url = require('node:url');
|
2017-04-28 14:00:50 -07:00
|
|
|
const myURL =
|
2018-09-02 15:45:53 +03:00
|
|
|
url.parse('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
2010-11-21 17:22:34 -05:00
|
|
|
|
2021-03-19 14:43:18 -07:00
|
|
|
### Constructing a URL from component parts and getting the constructed string
|
|
|
|
|
|
|
|
It is possible to construct a WHATWG URL from component parts using either the
|
|
|
|
property setters or a template literal string:
|
|
|
|
|
|
|
|
```js
|
|
|
|
const myURL = new URL('https://example.org');
|
|
|
|
myURL.pathname = '/a/b/c';
|
|
|
|
myURL.search = '?d=e';
|
|
|
|
myURL.hash = '#fgh';
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
const pathname = '/a/b/c';
|
|
|
|
const search = '?d=e';
|
|
|
|
const hash = '#fgh';
|
|
|
|
const myURL = new URL(`https://example.org${pathname}${search}${hash}`);
|
|
|
|
```
|
|
|
|
|
|
|
|
To get the constructed URL string, use the `href` property accessor:
|
|
|
|
|
|
|
|
```js
|
|
|
|
console.log(myURL.href);
|
|
|
|
```
|
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
## The WHATWG URL API
|
2018-01-21 17:11:47 +01:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
### Class: `URL`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
<!-- YAML
|
2018-12-05 10:44:37 +01:00
|
|
|
added:
|
|
|
|
- v7.0.0
|
|
|
|
- v6.13.0
|
2018-01-21 17:11:47 +01:00
|
|
|
changes:
|
2018-03-02 09:53:46 -08:00
|
|
|
- version: v10.0.0
|
2018-01-21 17:11:47 +01:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/18281
|
|
|
|
description: The class is now available on the global object.
|
2017-04-28 14:00:50 -07:00
|
|
|
-->
|
2012-04-30 10:30:05 -07:00
|
|
|
|
2017-06-26 11:59:20 +08:00
|
|
|
Browser-compatible `URL` class, implemented by following the WHATWG URL
|
|
|
|
Standard. [Examples of parsed URLs][] may be found in the Standard itself.
|
2018-01-21 17:11:47 +01:00
|
|
|
The `URL` class is also available on the global object.
|
2017-06-26 11:59:20 +08:00
|
|
|
|
2018-02-05 21:55:16 -08:00
|
|
|
In accordance with browser conventions, all properties of `URL` objects
|
2017-06-26 11:59:20 +08:00
|
|
|
are implemented as getters and setters on the class prototype, rather than as
|
2018-04-29 20:46:41 +03:00
|
|
|
data properties on the object itself. Thus, unlike [legacy `urlObject`][]s,
|
|
|
|
using the `delete` keyword on any properties of `URL` objects (e.g. `delete
|
2017-06-26 11:59:20 +08:00
|
|
|
myURL.protocol`, `delete myURL.pathname`, etc) has no effect but will still
|
|
|
|
return `true`.
|
|
|
|
|
2020-06-06 22:06:34 -07:00
|
|
|
#### `new URL(input[, base])`
|
2012-04-30 10:30:05 -07:00
|
|
|
|
2023-09-20 14:40:54 +02:00
|
|
|
<!-- YAML
|
2023-03-31 09:04:03 -04:00
|
|
|
changes:
|
2023-07-10 08:12:52 -04:00
|
|
|
- version:
|
|
|
|
- v20.0.0
|
|
|
|
- v18.17.0
|
2023-03-31 09:04:03 -04:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/47339
|
|
|
|
description: ICU requirement is removed.
|
|
|
|
-->
|
|
|
|
|
2018-04-09 10:59:15 -07:00
|
|
|
* `input` {string} The absolute or relative input URL to parse. If `input`
|
|
|
|
is relative, then `base` is required. If `input` is absolute, the `base`
|
2022-01-24 18:04:22 -08:00
|
|
|
is ignored. If `input` is not a string, it is [converted to a string][] first.
|
2022-01-26 21:45:53 -08:00
|
|
|
* `base` {string} The base URL to resolve against if the `input` is not
|
|
|
|
absolute. If `base` is not a string, it is [converted to a string][] first.
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Creates a new `URL` object by parsing the `input` relative to the `base`. If
|
|
|
|
`base` is passed as a string, it will be parsed equivalent to `new URL(base)`.
|
2012-04-30 10:30:05 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
```js
|
|
|
|
const myURL = new URL('/foo', 'https://example.org/');
|
2017-06-27 13:32:32 -07:00
|
|
|
// https://example.org/foo
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2020-04-11 17:02:59 +03:00
|
|
|
The URL constructor is accessible as a property on the global object.
|
|
|
|
It can also be imported from the built-in url module:
|
|
|
|
|
2021-05-12 12:13:16 +02:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import { URL } from 'node:url';
|
2021-05-12 12:13:16 +02:00
|
|
|
console.log(URL === globalThis.URL); // Prints 'true'.
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
console.log(URL === require('node:url').URL); // Prints 'true'.
|
2020-04-11 17:02:59 +03:00
|
|
|
```
|
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
A `TypeError` will be thrown if the `input` or `base` are not valid URLs. Note
|
|
|
|
that an effort will be made to coerce the given values into strings. For
|
|
|
|
instance:
|
2011-10-19 15:06:49 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
```js
|
2017-05-30 00:25:41 +03:00
|
|
|
const myURL = new URL({ toString: () => 'https://example.org/' });
|
2017-06-27 13:32:32 -07:00
|
|
|
// https://example.org/
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
2012-04-30 10:30:05 -07:00
|
|
|
|
2020-01-12 08:09:26 -08:00
|
|
|
Unicode characters appearing within the host name of `input` will be
|
2017-04-28 14:00:50 -07:00
|
|
|
automatically converted to ASCII using the [Punycode][] algorithm.
|
2012-04-30 10:30:05 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
```js
|
2018-09-02 15:45:53 +03:00
|
|
|
const myURL = new URL('https://測試');
|
|
|
|
// https://xn--g6w251d/
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
2017-02-13 04:49:35 +02:00
|
|
|
|
2018-04-09 10:59:15 -07:00
|
|
|
In cases where it is not known in advance if `input` is an absolute URL
|
|
|
|
and a `base` is provided, it is advised to validate that the `origin` of
|
|
|
|
the `URL` object is what is expected.
|
|
|
|
|
|
|
|
```js
|
2018-09-02 15:45:53 +03:00
|
|
|
let myURL = new URL('http://Example.com/', 'https://example.org/');
|
|
|
|
// http://example.com/
|
2018-04-09 10:59:15 -07:00
|
|
|
|
2018-09-02 15:45:53 +03:00
|
|
|
myURL = new URL('https://Example.com/', 'https://example.org/');
|
|
|
|
// https://example.com/
|
2018-04-09 10:59:15 -07:00
|
|
|
|
2018-09-02 15:45:53 +03:00
|
|
|
myURL = new URL('foo://Example.com/', 'https://example.org/');
|
|
|
|
// foo://Example.com/
|
2018-04-09 10:59:15 -07:00
|
|
|
|
2018-09-02 15:45:53 +03:00
|
|
|
myURL = new URL('http:Example.com/', 'https://example.org/');
|
|
|
|
// http://example.com/
|
2018-04-09 10:59:15 -07:00
|
|
|
|
2018-09-02 15:45:53 +03:00
|
|
|
myURL = new URL('https:Example.com/', 'https://example.org/');
|
|
|
|
// https://example.org/Example.com/
|
2018-04-09 10:59:15 -07:00
|
|
|
|
2018-09-02 15:45:53 +03:00
|
|
|
myURL = new URL('foo:Example.com/', 'https://example.org/');
|
|
|
|
// foo:Example.com/
|
2018-04-09 10:59:15 -07:00
|
|
|
```
|
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.hash`
|
2017-02-13 04:49:35 +02:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* {string}
|
2017-02-13 04:49:35 +02:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Gets and sets the fragment portion of the URL.
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
```js
|
|
|
|
const myURL = new URL('https://example.org/foo#bar');
|
|
|
|
console.log(myURL.hash);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints #bar
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
myURL.hash = 'baz';
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org/foo#baz
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Invalid URL characters included in the value assigned to the `hash` property
|
2019-06-20 13:35:52 -06:00
|
|
|
are [percent-encoded][]. The selection of which characters to
|
2017-04-28 14:00:50 -07:00
|
|
|
percent-encode may vary somewhat from what the [`url.parse()`][] and
|
|
|
|
[`url.format()`][] methods would produce.
|
2015-08-28 16:58:18 -04:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.host`
|
2015-08-28 16:58:18 -04:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* {string}
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Gets and sets the host portion of the URL.
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
```js
|
|
|
|
const myURL = new URL('https://example.org:81/foo');
|
|
|
|
console.log(myURL.host);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints example.org:81
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
myURL.host = 'example.com:82';
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.com:82/foo
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Invalid host values assigned to the `host` property are ignored.
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.hostname`
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* {string}
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2020-01-12 08:09:26 -08:00
|
|
|
Gets and sets the host name portion of the URL. The key difference between
|
2021-10-10 21:55:04 -07:00
|
|
|
`url.host` and `url.hostname` is that `url.hostname` does _not_ include the
|
2017-04-28 14:00:50 -07:00
|
|
|
port.
|
2015-08-28 16:58:18 -04:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
```js
|
|
|
|
const myURL = new URL('https://example.org:81/foo');
|
|
|
|
console.log(myURL.hostname);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints example.org
|
2015-08-28 16:58:18 -04:00
|
|
|
|
2020-06-05 01:23:22 -07:00
|
|
|
// Setting the hostname does not change the port
|
2022-12-24 15:14:22 +09:00
|
|
|
myURL.hostname = 'example.com';
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.com:81/foo
|
2020-06-05 01:23:22 -07:00
|
|
|
|
2020-11-19 04:45:55 -08:00
|
|
|
// Use myURL.host to change the hostname and port
|
2020-06-05 01:23:22 -07:00
|
|
|
myURL.host = 'example.org:82';
|
|
|
|
console.log(myURL.href);
|
|
|
|
// Prints https://example.org:82/foo
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
|
|
|
|
2020-01-12 08:09:26 -08:00
|
|
|
Invalid host name values assigned to the `hostname` property are ignored.
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.href`
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* {string}
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Gets and sets the serialized URL.
|
2017-02-13 04:49:35 +02:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
```js
|
|
|
|
const myURL = new URL('https://example.org/foo');
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org/foo
|
2017-02-13 04:49:35 +02:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
myURL.href = 'https://example.com/bar';
|
2017-05-30 00:25:41 +03:00
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.com/bar
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
2017-02-13 04:49:35 +02:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Getting the value of the `href` property is equivalent to calling
|
|
|
|
[`url.toString()`][].
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Setting the value of this property to a new value is equivalent to creating a
|
|
|
|
new `URL` object using [`new URL(value)`][`new URL()`]. Each of the `URL`
|
|
|
|
object's properties will be modified.
|
2017-04-26 18:04:30 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
If the value assigned to the `href` property is not a valid URL, a `TypeError`
|
|
|
|
will be thrown.
|
2017-04-26 18:04:30 -07:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.origin`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2020-05-09 15:59:43 +02:00
|
|
|
<!-- YAML
|
|
|
|
changes:
|
2020-10-20, Version 15.0.0 (Current)
Notable changes:
Deprecations and Removals:
- **build**: remove --build-v8-with-gn configure option (Yang Guo)
(https://github.com/nodejs/node/pull/27576)
- **build**: drop support for VS2017 (Michaël Zasso)
(https://github.com/nodejs/node/pull/33694)
- **doc**: move DEP0018 to End-of-Life (Rich Trott)
(https://github.com/nodejs/node/pull/35316)
- **fs**: deprecation warning on recursive rmdir (Ian Sutherland)
(https://github.com/nodejs/node/pull/35562)
- **lib**: add EventTarget-related browser globals (Anna Henningsen)
(https://github.com/nodejs/node/pull/35496)
- **net**: remove long deprecated server.connections property (James M
Snell) (https://github.com/nodejs/node/pull/33647)
- **repl**: remove deprecated repl.memory function (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.turnOffEditorMode() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.parseREPLKeyword() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated bufferedCommand property (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated .rli (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **src**: remove deprecated node debug command (James M Snell)
(https://github.com/nodejs/node/pull/33648)
- **timers**: introduce timers/promises (James M Snell)
(https://github.com/nodejs/node/pull/33950)
- **util**: change default value of `maxStringLength` to 10000
(unknown) (https://github.com/nodejs/node/pull/32744)
- **wasi**: drop --experimental-wasm-bigint requirement (Colin Ihrig)
(https://github.com/nodejs/node/pull/35415)
npm 7 (https://github.com/nodejs/node/pull/35631):
Node.js 15 comes with a new major release of npm, npm 7. npm 7 comes
with many new features - including npm workspaces and a new
package-lock.json format. npm 7 also includes yarn.lock file support.
One of the big changes in npm 7 is that peer dependencies are now
installed by default.
Throw On Unhandled Rejections
(https://github.com/nodejs/node/pull/33021):
As of Node.js 15, the default mode for `unhandledRejection` is changed
to `throw` (from `warn`). In `throw` mode, if an `unhandledRejection`
hook is not set, the `unhandledRejection` is raised as an uncaught
exception. Users that have an `unhandledRejection` hook should see no
change in behavior, and it’s still possible to switch modes using the
`--unhandled-rejections=mode` process flag.
QUIC (https://github.com/nodejs/node/pull/32379):
Node.js 15 comes with experimental support QUIC, which can be enabled
by compiling Node.js with the `--experimental-quic` configuration flag.
The Node.js QUIC implementation is exposed by the core `net` module.
V8 8.6 (https://github.com/nodejs/node/pull/35415):
The V8 JavaScript engine has been updated to V8 8.6 (V8 8.4 is the
latest available in Node.js 14). Along with performance tweaks and
improvements the V8 update also brings the following language features:
* `Promise.any()` (from V8 8.5)
* `AggregateError` (from V8 8.5)
* `String.prototype.replaceAll()` (from V8 8.5)
* Logical assignment operators `&&=`, `||=`, and `??=` (from V8 8.5)
Other Notable Changes:
- **assert**: add `assert/strict` alias module (ExE Boss)
(https://github.com/nodejs/node/pull/34001)
- **dns**: add dns/promises alias (shisama)
(https://github.com/nodejs/node/pull/32953)
- **fs**: reimplement read and write streams using stream.construct
(Robert Nagy) (https://github.com/nodejs/node/pull/29656)
- **http2**: allow Host in HTTP/2 requests (Alba Mendez)
(https://github.com/nodejs/node/pull/34664)
- **lib**: add EventTarget-related browser globals (Anna Henningsen)
(https://github.com/nodejs/node/pull/35496)
- **lib**: unflag AbortController (James M Snell)
(https://github.com/nodejs/node/pull/33527)
- **lib**: initial experimental AbortController implementation (James M
Snell) (https://github.com/nodejs/node/pull/33527)
- **net**: autoDestroy Socket (Robert Nagy)
(https://github.com/nodejs/node/pull/31806)
- **src**: disallow JS execution inside FreeEnvironment (Anna
Henningsen) (https://github.com/nodejs/node/pull/33874)
- **stream**: construct (Robert Nagy)
(https://github.com/nodejs/node/pull/29656)
- **worker**: make MessageEvent class more Web-compatible (Anna
Henningsen) (https://github.com/nodejs/node/pull/35496)
Semver-Major Commits:
- **assert**: add `assert/strict` alias module (ExE Boss)
(https://github.com/nodejs/node/pull/34001)
- **build**: reset embedder string to "-node.0" (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **build**: remove --build-v8-with-gn configure option (Yang Guo)
(https://github.com/nodejs/node/pull/27576)
- **build**: drop support for VS2017 (Michaël Zasso)
(https://github.com/nodejs/node/pull/33694)
- **crypto**: refactoring internals, add WebCrypto (James M Snell)
(https://github.com/nodejs/node/pull/35093)
- **crypto**: move node\_crypto files to src/crypto (James M Snell)
(https://github.com/nodejs/node/pull/35093)
- **deps**: V8: cherry-pick d76abfed3512 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: V8: cherry-pick 717543bbf0ef (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: V8: cherry-pick 6be2f6e26e8d (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: fix V8 build issue with inline methods (Jiawen Geng)
(https://github.com/nodejs/node/pull/35415)
- **deps**: fix platform-embedded-file-writer-win for ARM64 (Michaël
Zasso) (https://github.com/nodejs/node/pull/35415)
- **deps**: update V8 postmortem metadata script (Colin Ihrig)
(https://github.com/nodejs/node/pull/35415)
- **deps**: update V8 to 8.6.395 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: upgrade npm to 7.0.0 (Myles Borins)
(https://github.com/nodejs/node/pull/35631)
- **deps**: update npm to 7.0.0-rc.3 (Myles Borins)
(https://github.com/nodejs/node/pull/35474)
- **deps**: V8: cherry-pick 0d6debcc5f08 (Gus Caplan)
(https://github.com/nodejs/node/pull/33600)
- **dns**: add dns/promises alias (shisama)
(https://github.com/nodejs/node/pull/32953)
- **doc**: move DEP0018 to End-of-Life (Rich Trott)
(https://github.com/nodejs/node/pull/35316)
- **doc**: update support macos version for 15.x (Ash Cripps)
(https://github.com/nodejs/node/pull/35022)
- **fs**: deprecation warning on recursive rmdir (Ian Sutherland)
(https://github.com/nodejs/node/pull/35562)
- **fs**: reimplement read and write streams using stream.construct
(Robert Nagy) (https://github.com/nodejs/node/pull/29656)
- **http**: fixed socket.setEncoding fatal error (iskore)
(https://github.com/nodejs/node/pull/33405)
- **http**: emit 'error' on aborted server request (Robert Nagy)
(https://github.com/nodejs/node/pull/33172)
- **http**: cleanup end argument handling (Robert Nagy)
(https://github.com/nodejs/node/pull/31818)
- **http2**: allow Host in HTTP/2 requests (Alba Mendez)
(https://github.com/nodejs/node/pull/34664)
- **http2**: add `invalidheaders` test (Pranshu Srivastava)
(https://github.com/nodejs/node/pull/33161)
- **http2**: refactor state code validation for the http2Stream class
(rickyes) (https://github.com/nodejs/node/pull/33535)
- **http2**: header field valid checks (Pranshu Srivastava)
(https://github.com/nodejs/node/pull/33193)
- **lib**: add EventTarget-related browser globals (Anna Henningsen)
(https://github.com/nodejs/node/pull/35496)
- **lib**: remove ERR\_INVALID\_OPT\_VALUE and
ERR\_INVALID\_OPT\_VALUE\_ENCODING (Denys Otrishko)
(https://github.com/nodejs/node/pull/34682)
- **lib**: handle one of args case in ERR\_MISSING\_ARGS (Denys
Otrishko) (https://github.com/nodejs/node/pull/34022)
- **lib**: remove NodeError from the prototype of errors with code
(Michaël Zasso) (https://github.com/nodejs/node/pull/33857)
- **lib**: unflag AbortController (James M Snell)
(https://github.com/nodejs/node/pull/33527)
- **lib**: initial experimental AbortController implementation (James M
Snell) (https://github.com/nodejs/node/pull/33527)
- **net**: check args in net.connect() and socket.connect() calls
(Denys Otrishko) (https://github.com/nodejs/node/pull/34022)
- **net**: remove long deprecated server.connections property (James M
Snell) (https://github.com/nodejs/node/pull/33647)
- **net**: autoDestroy Socket (Robert Nagy)
(https://github.com/nodejs/node/pull/31806)
- **process**: update v8 fast api calls usage (Maya Lekova)
(https://github.com/nodejs/node/pull/35415)
- **process**: change default --unhandled-rejections=throw (Dan
Fabulich) (https://github.com/nodejs/node/pull/33021)
- **process**: use v8 fast api calls for hrtime (Gus Caplan)
(https://github.com/nodejs/node/pull/33600)
- **process**: delay throwing an error using `throwDeprecation` (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/32312)
- **repl**: remove deprecated repl.memory function (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.turnOffEditorMode() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.parseREPLKeyword() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated bufferedCommand property (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated .rli (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **src**: implement NodePlatform::PostJob (Clemens Backes)
(https://github.com/nodejs/node/pull/35415)
- **src**: update NODE\_MODULE\_VERSION to 88 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **src**: error reporting on CPUUsage (Yash Ladha)
(https://github.com/nodejs/node/pull/34762)
- **src**: use node:moduleName as builtin module filename (Michaël
Zasso) (https://github.com/nodejs/node/pull/35498)
- **src**: enable wasm trap handler on windows (Gus Caplan)
(https://github.com/nodejs/node/pull/35033)
- **src**: update NODE\_MODULE\_VERSION to 86 (Michaël Zasso)
(https://github.com/nodejs/node/pull/33579)
- **src**: disallow JS execution inside FreeEnvironment (Anna
Henningsen) (https://github.com/nodejs/node/pull/33874)
- **src**: remove \_third\_party\_main support (Anna Henningsen)
(https://github.com/nodejs/node/pull/33971)
- **src**: remove deprecated node debug command (James M Snell)
(https://github.com/nodejs/node/pull/33648)
- **src**: remove unused CancelPendingDelayedTasks (Anna Henningsen)
(https://github.com/nodejs/node/pull/32859)
- **stream**: try to wait for flush to complete before 'finish' (Robert
Nagy) (https://github.com/nodejs/node/pull/34314)
- **stream**: cleanup and fix Readable.wrap (Robert Nagy)
(https://github.com/nodejs/node/pull/34204)
- **stream**: add promises version to utility functions (rickyes)
(https://github.com/nodejs/node/pull/33991)
- **stream**: fix writable.end callback behavior (Robert Nagy)
(https://github.com/nodejs/node/pull/34101)
- **stream**: construct (Robert Nagy)
(https://github.com/nodejs/node/pull/29656)
- **stream**: write should throw on unknown encoding (Robert Nagy)
(https://github.com/nodejs/node/pull/33075)
- **stream**: fix \_final and 'prefinish' timing (Robert Nagy)
(https://github.com/nodejs/node/pull/32780)
- **stream**: simplify Transform stream implementation (Robert Nagy)
(https://github.com/nodejs/node/pull/32763)
- **stream**: use callback to properly propagate error (Robert Nagy)
(https://github.com/nodejs/node/pull/29179)
- **test**: update tests after increasing typed array size to 4GB
(Kim-Anh Tran) (https://github.com/nodejs/node/pull/35415)
- **test**: fix tests for npm 7.0.0 (Myles Borins)
(https://github.com/nodejs/node/pull/35631)
- **test**: fix test suite to work with npm 7 (Myles Borins)
(https://github.com/nodejs/node/pull/35474)
- **test**: update WPT harness and tests (Michaël Zasso)
(https://github.com/nodejs/node/pull/33770)
- **timers**: introduce timers/promises (James M Snell)
(https://github.com/nodejs/node/pull/33950)
- **tools**: disable x86 safe exception handlers in V8 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **tools**: update V8 gypfiles for 8.6 (Ujjwal Sharma)
(https://github.com/nodejs/node/pull/35415)
- **tools**: update V8 gypfiles for 8.5 (Ujjwal Sharma)
(https://github.com/nodejs/node/pull/35415)
- **url**: file URL path normalization (Daijiro Wachi)
(https://github.com/nodejs/node/pull/35477)
- **url**: verify domain is not empty after "ToASCII" (Michaël Zasso)
(https://github.com/nodejs/node/pull/33770)
- **url**: remove U+0000 case in the fragment state (Michaël Zasso)
(https://github.com/nodejs/node/pull/33770)
- **url**: remove gopher from special schemes (Michaël Zasso)
(https://github.com/nodejs/node/pull/33325)
- **url**: forbid lt and gt in url host code point (Yash Ladha)
(https://github.com/nodejs/node/pull/33328)
- **util**: change default value of `maxStringLength` to 10000
(unknown) (https://github.com/nodejs/node/pull/32744)
- **wasi**: drop --experimental-wasm-bigint requirement (Colin Ihrig)
(https://github.com/nodejs/node/pull/35415)
- **win, child_process**: sanitize env variables (Bartosz Sosnowski)
(https://github.com/nodejs/node/pull/35210)
- **worker**: make MessageEvent class more Web-compatible (Anna
Henningsen) (https://github.com/nodejs/node/pull/35496)
- **worker**: set trackUnmanagedFds to true by default (Anna
Henningsen) (https://github.com/nodejs/node/pull/34394)
- **worker**: rename error code to be more accurate (Anna Henningsen)
(https://github.com/nodejs/node/pull/33872)
PR-URL: https://github.com/nodejs/node/pull/35014
2020-09-01 21:16:46 +01:00
|
|
|
- version: v15.0.0
|
2020-05-09 15:59:43 +02:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/33325
|
|
|
|
description: The scheme "gopher" is no longer special and `url.origin` now
|
|
|
|
returns `'null'` for it.
|
|
|
|
-->
|
2017-04-26 18:04:30 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* {string}
|
2017-04-26 18:04:30 -07:00
|
|
|
|
2017-06-23 08:51:44 +08:00
|
|
|
Gets the read-only serialization of the URL's origin.
|
2017-04-26 18:04:30 -07:00
|
|
|
|
|
|
|
```js
|
2017-04-28 14:00:50 -07:00
|
|
|
const myURL = new URL('https://example.org/foo/bar?baz');
|
|
|
|
console.log(myURL.origin);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org
|
2017-04-26 18:04:30 -07:00
|
|
|
```
|
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
```js
|
2018-09-02 15:45:53 +03:00
|
|
|
const idnURL = new URL('https://測試');
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(idnURL.origin);
|
2018-09-02 15:45:53 +03:00
|
|
|
// Prints https://xn--g6w251d
|
2017-04-26 18:04:30 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(idnURL.hostname);
|
2018-09-02 15:45:53 +03:00
|
|
|
// Prints xn--g6w251d
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
2017-04-26 18:04:30 -07:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.password`
|
2017-04-26 18:04:30 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* {string}
|
2017-04-26 18:04:30 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Gets and sets the password portion of the URL.
|
2017-04-26 18:04:30 -07:00
|
|
|
|
|
|
|
```js
|
2017-04-28 14:00:50 -07:00
|
|
|
const myURL = new URL('https://abc:xyz@example.com');
|
|
|
|
console.log(myURL.password);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints xyz
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
myURL.password = '123';
|
|
|
|
console.log(myURL.href);
|
2022-12-21 23:32:07 +09:00
|
|
|
// Prints https://abc:123@example.com/
|
2017-04-26 18:04:30 -07:00
|
|
|
```
|
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Invalid URL characters included in the value assigned to the `password` property
|
2019-06-20 13:35:52 -06:00
|
|
|
are [percent-encoded][]. The selection of which characters to
|
2017-04-28 14:00:50 -07:00
|
|
|
percent-encode may vary somewhat from what the [`url.parse()`][] and
|
|
|
|
[`url.format()`][] methods would produce.
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.pathname`
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* {string}
|
2016-05-20 13:11:09 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Gets and sets the path portion of the URL.
|
2016-06-08 15:27:57 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
```js
|
|
|
|
const myURL = new URL('https://example.org/abc/xyz?123');
|
|
|
|
console.log(myURL.pathname);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints /abc/xyz
|
2017-01-04 15:41:09 -08:00
|
|
|
|
|
|
|
myURL.pathname = '/abcdef';
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org/abcdef?123
|
2017-01-04 15:41:09 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
Invalid URL characters included in the value assigned to the `pathname`
|
2019-06-20 13:35:52 -06:00
|
|
|
property are [percent-encoded][]. The selection of which characters
|
2017-02-12 12:17:03 -08:00
|
|
|
to percent-encode may vary somewhat from what the [`url.parse()`][] and
|
|
|
|
[`url.format()`][] methods would produce.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.port`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2020-05-09 15:59:43 +02:00
|
|
|
<!-- YAML
|
|
|
|
changes:
|
2020-10-20, Version 15.0.0 (Current)
Notable changes:
Deprecations and Removals:
- **build**: remove --build-v8-with-gn configure option (Yang Guo)
(https://github.com/nodejs/node/pull/27576)
- **build**: drop support for VS2017 (Michaël Zasso)
(https://github.com/nodejs/node/pull/33694)
- **doc**: move DEP0018 to End-of-Life (Rich Trott)
(https://github.com/nodejs/node/pull/35316)
- **fs**: deprecation warning on recursive rmdir (Ian Sutherland)
(https://github.com/nodejs/node/pull/35562)
- **lib**: add EventTarget-related browser globals (Anna Henningsen)
(https://github.com/nodejs/node/pull/35496)
- **net**: remove long deprecated server.connections property (James M
Snell) (https://github.com/nodejs/node/pull/33647)
- **repl**: remove deprecated repl.memory function (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.turnOffEditorMode() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.parseREPLKeyword() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated bufferedCommand property (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated .rli (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **src**: remove deprecated node debug command (James M Snell)
(https://github.com/nodejs/node/pull/33648)
- **timers**: introduce timers/promises (James M Snell)
(https://github.com/nodejs/node/pull/33950)
- **util**: change default value of `maxStringLength` to 10000
(unknown) (https://github.com/nodejs/node/pull/32744)
- **wasi**: drop --experimental-wasm-bigint requirement (Colin Ihrig)
(https://github.com/nodejs/node/pull/35415)
npm 7 (https://github.com/nodejs/node/pull/35631):
Node.js 15 comes with a new major release of npm, npm 7. npm 7 comes
with many new features - including npm workspaces and a new
package-lock.json format. npm 7 also includes yarn.lock file support.
One of the big changes in npm 7 is that peer dependencies are now
installed by default.
Throw On Unhandled Rejections
(https://github.com/nodejs/node/pull/33021):
As of Node.js 15, the default mode for `unhandledRejection` is changed
to `throw` (from `warn`). In `throw` mode, if an `unhandledRejection`
hook is not set, the `unhandledRejection` is raised as an uncaught
exception. Users that have an `unhandledRejection` hook should see no
change in behavior, and it’s still possible to switch modes using the
`--unhandled-rejections=mode` process flag.
QUIC (https://github.com/nodejs/node/pull/32379):
Node.js 15 comes with experimental support QUIC, which can be enabled
by compiling Node.js with the `--experimental-quic` configuration flag.
The Node.js QUIC implementation is exposed by the core `net` module.
V8 8.6 (https://github.com/nodejs/node/pull/35415):
The V8 JavaScript engine has been updated to V8 8.6 (V8 8.4 is the
latest available in Node.js 14). Along with performance tweaks and
improvements the V8 update also brings the following language features:
* `Promise.any()` (from V8 8.5)
* `AggregateError` (from V8 8.5)
* `String.prototype.replaceAll()` (from V8 8.5)
* Logical assignment operators `&&=`, `||=`, and `??=` (from V8 8.5)
Other Notable Changes:
- **assert**: add `assert/strict` alias module (ExE Boss)
(https://github.com/nodejs/node/pull/34001)
- **dns**: add dns/promises alias (shisama)
(https://github.com/nodejs/node/pull/32953)
- **fs**: reimplement read and write streams using stream.construct
(Robert Nagy) (https://github.com/nodejs/node/pull/29656)
- **http2**: allow Host in HTTP/2 requests (Alba Mendez)
(https://github.com/nodejs/node/pull/34664)
- **lib**: add EventTarget-related browser globals (Anna Henningsen)
(https://github.com/nodejs/node/pull/35496)
- **lib**: unflag AbortController (James M Snell)
(https://github.com/nodejs/node/pull/33527)
- **lib**: initial experimental AbortController implementation (James M
Snell) (https://github.com/nodejs/node/pull/33527)
- **net**: autoDestroy Socket (Robert Nagy)
(https://github.com/nodejs/node/pull/31806)
- **src**: disallow JS execution inside FreeEnvironment (Anna
Henningsen) (https://github.com/nodejs/node/pull/33874)
- **stream**: construct (Robert Nagy)
(https://github.com/nodejs/node/pull/29656)
- **worker**: make MessageEvent class more Web-compatible (Anna
Henningsen) (https://github.com/nodejs/node/pull/35496)
Semver-Major Commits:
- **assert**: add `assert/strict` alias module (ExE Boss)
(https://github.com/nodejs/node/pull/34001)
- **build**: reset embedder string to "-node.0" (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **build**: remove --build-v8-with-gn configure option (Yang Guo)
(https://github.com/nodejs/node/pull/27576)
- **build**: drop support for VS2017 (Michaël Zasso)
(https://github.com/nodejs/node/pull/33694)
- **crypto**: refactoring internals, add WebCrypto (James M Snell)
(https://github.com/nodejs/node/pull/35093)
- **crypto**: move node\_crypto files to src/crypto (James M Snell)
(https://github.com/nodejs/node/pull/35093)
- **deps**: V8: cherry-pick d76abfed3512 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: V8: cherry-pick 717543bbf0ef (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: V8: cherry-pick 6be2f6e26e8d (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: fix V8 build issue with inline methods (Jiawen Geng)
(https://github.com/nodejs/node/pull/35415)
- **deps**: fix platform-embedded-file-writer-win for ARM64 (Michaël
Zasso) (https://github.com/nodejs/node/pull/35415)
- **deps**: update V8 postmortem metadata script (Colin Ihrig)
(https://github.com/nodejs/node/pull/35415)
- **deps**: update V8 to 8.6.395 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: upgrade npm to 7.0.0 (Myles Borins)
(https://github.com/nodejs/node/pull/35631)
- **deps**: update npm to 7.0.0-rc.3 (Myles Borins)
(https://github.com/nodejs/node/pull/35474)
- **deps**: V8: cherry-pick 0d6debcc5f08 (Gus Caplan)
(https://github.com/nodejs/node/pull/33600)
- **dns**: add dns/promises alias (shisama)
(https://github.com/nodejs/node/pull/32953)
- **doc**: move DEP0018 to End-of-Life (Rich Trott)
(https://github.com/nodejs/node/pull/35316)
- **doc**: update support macos version for 15.x (Ash Cripps)
(https://github.com/nodejs/node/pull/35022)
- **fs**: deprecation warning on recursive rmdir (Ian Sutherland)
(https://github.com/nodejs/node/pull/35562)
- **fs**: reimplement read and write streams using stream.construct
(Robert Nagy) (https://github.com/nodejs/node/pull/29656)
- **http**: fixed socket.setEncoding fatal error (iskore)
(https://github.com/nodejs/node/pull/33405)
- **http**: emit 'error' on aborted server request (Robert Nagy)
(https://github.com/nodejs/node/pull/33172)
- **http**: cleanup end argument handling (Robert Nagy)
(https://github.com/nodejs/node/pull/31818)
- **http2**: allow Host in HTTP/2 requests (Alba Mendez)
(https://github.com/nodejs/node/pull/34664)
- **http2**: add `invalidheaders` test (Pranshu Srivastava)
(https://github.com/nodejs/node/pull/33161)
- **http2**: refactor state code validation for the http2Stream class
(rickyes) (https://github.com/nodejs/node/pull/33535)
- **http2**: header field valid checks (Pranshu Srivastava)
(https://github.com/nodejs/node/pull/33193)
- **lib**: add EventTarget-related browser globals (Anna Henningsen)
(https://github.com/nodejs/node/pull/35496)
- **lib**: remove ERR\_INVALID\_OPT\_VALUE and
ERR\_INVALID\_OPT\_VALUE\_ENCODING (Denys Otrishko)
(https://github.com/nodejs/node/pull/34682)
- **lib**: handle one of args case in ERR\_MISSING\_ARGS (Denys
Otrishko) (https://github.com/nodejs/node/pull/34022)
- **lib**: remove NodeError from the prototype of errors with code
(Michaël Zasso) (https://github.com/nodejs/node/pull/33857)
- **lib**: unflag AbortController (James M Snell)
(https://github.com/nodejs/node/pull/33527)
- **lib**: initial experimental AbortController implementation (James M
Snell) (https://github.com/nodejs/node/pull/33527)
- **net**: check args in net.connect() and socket.connect() calls
(Denys Otrishko) (https://github.com/nodejs/node/pull/34022)
- **net**: remove long deprecated server.connections property (James M
Snell) (https://github.com/nodejs/node/pull/33647)
- **net**: autoDestroy Socket (Robert Nagy)
(https://github.com/nodejs/node/pull/31806)
- **process**: update v8 fast api calls usage (Maya Lekova)
(https://github.com/nodejs/node/pull/35415)
- **process**: change default --unhandled-rejections=throw (Dan
Fabulich) (https://github.com/nodejs/node/pull/33021)
- **process**: use v8 fast api calls for hrtime (Gus Caplan)
(https://github.com/nodejs/node/pull/33600)
- **process**: delay throwing an error using `throwDeprecation` (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/32312)
- **repl**: remove deprecated repl.memory function (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.turnOffEditorMode() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.parseREPLKeyword() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated bufferedCommand property (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated .rli (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **src**: implement NodePlatform::PostJob (Clemens Backes)
(https://github.com/nodejs/node/pull/35415)
- **src**: update NODE\_MODULE\_VERSION to 88 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **src**: error reporting on CPUUsage (Yash Ladha)
(https://github.com/nodejs/node/pull/34762)
- **src**: use node:moduleName as builtin module filename (Michaël
Zasso) (https://github.com/nodejs/node/pull/35498)
- **src**: enable wasm trap handler on windows (Gus Caplan)
(https://github.com/nodejs/node/pull/35033)
- **src**: update NODE\_MODULE\_VERSION to 86 (Michaël Zasso)
(https://github.com/nodejs/node/pull/33579)
- **src**: disallow JS execution inside FreeEnvironment (Anna
Henningsen) (https://github.com/nodejs/node/pull/33874)
- **src**: remove \_third\_party\_main support (Anna Henningsen)
(https://github.com/nodejs/node/pull/33971)
- **src**: remove deprecated node debug command (James M Snell)
(https://github.com/nodejs/node/pull/33648)
- **src**: remove unused CancelPendingDelayedTasks (Anna Henningsen)
(https://github.com/nodejs/node/pull/32859)
- **stream**: try to wait for flush to complete before 'finish' (Robert
Nagy) (https://github.com/nodejs/node/pull/34314)
- **stream**: cleanup and fix Readable.wrap (Robert Nagy)
(https://github.com/nodejs/node/pull/34204)
- **stream**: add promises version to utility functions (rickyes)
(https://github.com/nodejs/node/pull/33991)
- **stream**: fix writable.end callback behavior (Robert Nagy)
(https://github.com/nodejs/node/pull/34101)
- **stream**: construct (Robert Nagy)
(https://github.com/nodejs/node/pull/29656)
- **stream**: write should throw on unknown encoding (Robert Nagy)
(https://github.com/nodejs/node/pull/33075)
- **stream**: fix \_final and 'prefinish' timing (Robert Nagy)
(https://github.com/nodejs/node/pull/32780)
- **stream**: simplify Transform stream implementation (Robert Nagy)
(https://github.com/nodejs/node/pull/32763)
- **stream**: use callback to properly propagate error (Robert Nagy)
(https://github.com/nodejs/node/pull/29179)
- **test**: update tests after increasing typed array size to 4GB
(Kim-Anh Tran) (https://github.com/nodejs/node/pull/35415)
- **test**: fix tests for npm 7.0.0 (Myles Borins)
(https://github.com/nodejs/node/pull/35631)
- **test**: fix test suite to work with npm 7 (Myles Borins)
(https://github.com/nodejs/node/pull/35474)
- **test**: update WPT harness and tests (Michaël Zasso)
(https://github.com/nodejs/node/pull/33770)
- **timers**: introduce timers/promises (James M Snell)
(https://github.com/nodejs/node/pull/33950)
- **tools**: disable x86 safe exception handlers in V8 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **tools**: update V8 gypfiles for 8.6 (Ujjwal Sharma)
(https://github.com/nodejs/node/pull/35415)
- **tools**: update V8 gypfiles for 8.5 (Ujjwal Sharma)
(https://github.com/nodejs/node/pull/35415)
- **url**: file URL path normalization (Daijiro Wachi)
(https://github.com/nodejs/node/pull/35477)
- **url**: verify domain is not empty after "ToASCII" (Michaël Zasso)
(https://github.com/nodejs/node/pull/33770)
- **url**: remove U+0000 case in the fragment state (Michaël Zasso)
(https://github.com/nodejs/node/pull/33770)
- **url**: remove gopher from special schemes (Michaël Zasso)
(https://github.com/nodejs/node/pull/33325)
- **url**: forbid lt and gt in url host code point (Yash Ladha)
(https://github.com/nodejs/node/pull/33328)
- **util**: change default value of `maxStringLength` to 10000
(unknown) (https://github.com/nodejs/node/pull/32744)
- **wasi**: drop --experimental-wasm-bigint requirement (Colin Ihrig)
(https://github.com/nodejs/node/pull/35415)
- **win, child_process**: sanitize env variables (Bartosz Sosnowski)
(https://github.com/nodejs/node/pull/35210)
- **worker**: make MessageEvent class more Web-compatible (Anna
Henningsen) (https://github.com/nodejs/node/pull/35496)
- **worker**: set trackUnmanagedFds to true by default (Anna
Henningsen) (https://github.com/nodejs/node/pull/34394)
- **worker**: rename error code to be more accurate (Anna Henningsen)
(https://github.com/nodejs/node/pull/33872)
PR-URL: https://github.com/nodejs/node/pull/35014
2020-09-01 21:16:46 +01:00
|
|
|
- version: v15.0.0
|
2020-05-09 15:59:43 +02:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/33325
|
|
|
|
description: The scheme "gopher" is no longer special.
|
|
|
|
-->
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-03-05 18:03:39 +01:00
|
|
|
* {string}
|
2017-02-12 12:17:03 -08:00
|
|
|
|
|
|
|
Gets and sets the port portion of the URL.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2018-08-10 15:54:55 +02:00
|
|
|
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 result in the `port` value becoming
|
|
|
|
the empty string (`''`).
|
|
|
|
|
|
|
|
The port value can be an empty string in which case the port depends on
|
|
|
|
the protocol/scheme:
|
|
|
|
|
|
|
|
| protocol | port |
|
2019-09-23 15:10:58 +03:00
|
|
|
| -------- | ---- |
|
2018-08-10 15:54:55 +02:00
|
|
|
| "ftp" | 21 |
|
|
|
|
| "file" | |
|
|
|
|
| "http" | 80 |
|
|
|
|
| "https" | 443 |
|
|
|
|
| "ws" | 80 |
|
|
|
|
| "wss" | 443 |
|
|
|
|
|
|
|
|
Upon assigning a value to the port, the value will first be converted to a
|
|
|
|
string using `.toString()`.
|
|
|
|
|
|
|
|
If that string is invalid but it begins with a number, the leading number is
|
|
|
|
assigned to `port`.
|
|
|
|
If the number lies outside the range denoted above, it is ignored.
|
|
|
|
|
2017-01-04 15:41:09 -08:00
|
|
|
```js
|
|
|
|
const myURL = new URL('https://example.org:8888');
|
|
|
|
console.log(myURL.port);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 8888
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-02-12 12:17:03 -08:00
|
|
|
// Default ports are automatically transformed to the empty string
|
|
|
|
// (HTTPS protocol's default port is 443)
|
|
|
|
myURL.port = '443';
|
|
|
|
console.log(myURL.port);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints the empty string
|
2017-02-12 12:17:03 -08:00
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org/
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2017-01-04 15:41:09 -08:00
|
|
|
myURL.port = 1234;
|
2017-02-12 12:17:03 -08:00
|
|
|
console.log(myURL.port);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 1234
|
2017-01-04 15:41:09 -08:00
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org:1234/
|
2017-02-12 12:17:03 -08:00
|
|
|
|
|
|
|
// Completely invalid port strings are ignored
|
|
|
|
myURL.port = 'abcd';
|
|
|
|
console.log(myURL.port);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 1234
|
2017-02-12 12:17:03 -08:00
|
|
|
|
|
|
|
// Leading numbers are treated as a port number
|
|
|
|
myURL.port = '5678abcd';
|
|
|
|
console.log(myURL.port);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 5678
|
2017-02-12 12:17:03 -08:00
|
|
|
|
|
|
|
// Non-integers are truncated
|
|
|
|
myURL.port = 1234.5678;
|
|
|
|
console.log(myURL.port);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 1234
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2018-03-28 01:41:15 +03:00
|
|
|
// Out-of-range numbers which are not represented in scientific notation
|
|
|
|
// will be ignored.
|
|
|
|
myURL.port = 1e10; // 10000000000, will be range-checked as described below
|
2017-02-12 12:17:03 -08:00
|
|
|
console.log(myURL.port);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 1234
|
2017-01-04 15:41:09 -08:00
|
|
|
```
|
|
|
|
|
2019-06-20 13:35:52 -06:00
|
|
|
Numbers which contain a decimal point,
|
2018-03-28 01:41:15 +03:00
|
|
|
such as floating-point numbers or numbers in scientific notation,
|
|
|
|
are not an exception to this rule.
|
|
|
|
Leading numbers up to the decimal point will be set as the URL's port,
|
|
|
|
assuming they are valid:
|
|
|
|
|
|
|
|
```js
|
|
|
|
myURL.port = 4.567e21;
|
|
|
|
console.log(myURL.port);
|
|
|
|
// Prints 4 (because it is the leading number in the string '4.567e21')
|
|
|
|
```
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.protocol`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-03-05 18:03:39 +01:00
|
|
|
* {string}
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2017-01-04 15:41:09 -08:00
|
|
|
Gets and sets the protocol portion of the URL.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const myURL = new URL('https://example.org');
|
|
|
|
console.log(myURL.protocol);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https:
|
2017-01-04 15:41:09 -08:00
|
|
|
|
|
|
|
myURL.protocol = 'ftp';
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints ftp://example.org/
|
2017-01-04 15:41:09 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
Invalid URL protocol values assigned to the `protocol` property are ignored.
|
|
|
|
|
2020-06-14 14:49:34 -07:00
|
|
|
##### Special schemes
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2020-05-09 15:59:43 +02:00
|
|
|
<!-- YAML
|
|
|
|
changes:
|
2020-10-20, Version 15.0.0 (Current)
Notable changes:
Deprecations and Removals:
- **build**: remove --build-v8-with-gn configure option (Yang Guo)
(https://github.com/nodejs/node/pull/27576)
- **build**: drop support for VS2017 (Michaël Zasso)
(https://github.com/nodejs/node/pull/33694)
- **doc**: move DEP0018 to End-of-Life (Rich Trott)
(https://github.com/nodejs/node/pull/35316)
- **fs**: deprecation warning on recursive rmdir (Ian Sutherland)
(https://github.com/nodejs/node/pull/35562)
- **lib**: add EventTarget-related browser globals (Anna Henningsen)
(https://github.com/nodejs/node/pull/35496)
- **net**: remove long deprecated server.connections property (James M
Snell) (https://github.com/nodejs/node/pull/33647)
- **repl**: remove deprecated repl.memory function (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.turnOffEditorMode() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.parseREPLKeyword() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated bufferedCommand property (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated .rli (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **src**: remove deprecated node debug command (James M Snell)
(https://github.com/nodejs/node/pull/33648)
- **timers**: introduce timers/promises (James M Snell)
(https://github.com/nodejs/node/pull/33950)
- **util**: change default value of `maxStringLength` to 10000
(unknown) (https://github.com/nodejs/node/pull/32744)
- **wasi**: drop --experimental-wasm-bigint requirement (Colin Ihrig)
(https://github.com/nodejs/node/pull/35415)
npm 7 (https://github.com/nodejs/node/pull/35631):
Node.js 15 comes with a new major release of npm, npm 7. npm 7 comes
with many new features - including npm workspaces and a new
package-lock.json format. npm 7 also includes yarn.lock file support.
One of the big changes in npm 7 is that peer dependencies are now
installed by default.
Throw On Unhandled Rejections
(https://github.com/nodejs/node/pull/33021):
As of Node.js 15, the default mode for `unhandledRejection` is changed
to `throw` (from `warn`). In `throw` mode, if an `unhandledRejection`
hook is not set, the `unhandledRejection` is raised as an uncaught
exception. Users that have an `unhandledRejection` hook should see no
change in behavior, and it’s still possible to switch modes using the
`--unhandled-rejections=mode` process flag.
QUIC (https://github.com/nodejs/node/pull/32379):
Node.js 15 comes with experimental support QUIC, which can be enabled
by compiling Node.js with the `--experimental-quic` configuration flag.
The Node.js QUIC implementation is exposed by the core `net` module.
V8 8.6 (https://github.com/nodejs/node/pull/35415):
The V8 JavaScript engine has been updated to V8 8.6 (V8 8.4 is the
latest available in Node.js 14). Along with performance tweaks and
improvements the V8 update also brings the following language features:
* `Promise.any()` (from V8 8.5)
* `AggregateError` (from V8 8.5)
* `String.prototype.replaceAll()` (from V8 8.5)
* Logical assignment operators `&&=`, `||=`, and `??=` (from V8 8.5)
Other Notable Changes:
- **assert**: add `assert/strict` alias module (ExE Boss)
(https://github.com/nodejs/node/pull/34001)
- **dns**: add dns/promises alias (shisama)
(https://github.com/nodejs/node/pull/32953)
- **fs**: reimplement read and write streams using stream.construct
(Robert Nagy) (https://github.com/nodejs/node/pull/29656)
- **http2**: allow Host in HTTP/2 requests (Alba Mendez)
(https://github.com/nodejs/node/pull/34664)
- **lib**: add EventTarget-related browser globals (Anna Henningsen)
(https://github.com/nodejs/node/pull/35496)
- **lib**: unflag AbortController (James M Snell)
(https://github.com/nodejs/node/pull/33527)
- **lib**: initial experimental AbortController implementation (James M
Snell) (https://github.com/nodejs/node/pull/33527)
- **net**: autoDestroy Socket (Robert Nagy)
(https://github.com/nodejs/node/pull/31806)
- **src**: disallow JS execution inside FreeEnvironment (Anna
Henningsen) (https://github.com/nodejs/node/pull/33874)
- **stream**: construct (Robert Nagy)
(https://github.com/nodejs/node/pull/29656)
- **worker**: make MessageEvent class more Web-compatible (Anna
Henningsen) (https://github.com/nodejs/node/pull/35496)
Semver-Major Commits:
- **assert**: add `assert/strict` alias module (ExE Boss)
(https://github.com/nodejs/node/pull/34001)
- **build**: reset embedder string to "-node.0" (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **build**: remove --build-v8-with-gn configure option (Yang Guo)
(https://github.com/nodejs/node/pull/27576)
- **build**: drop support for VS2017 (Michaël Zasso)
(https://github.com/nodejs/node/pull/33694)
- **crypto**: refactoring internals, add WebCrypto (James M Snell)
(https://github.com/nodejs/node/pull/35093)
- **crypto**: move node\_crypto files to src/crypto (James M Snell)
(https://github.com/nodejs/node/pull/35093)
- **deps**: V8: cherry-pick d76abfed3512 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: V8: cherry-pick 717543bbf0ef (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: V8: cherry-pick 6be2f6e26e8d (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: fix V8 build issue with inline methods (Jiawen Geng)
(https://github.com/nodejs/node/pull/35415)
- **deps**: fix platform-embedded-file-writer-win for ARM64 (Michaël
Zasso) (https://github.com/nodejs/node/pull/35415)
- **deps**: update V8 postmortem metadata script (Colin Ihrig)
(https://github.com/nodejs/node/pull/35415)
- **deps**: update V8 to 8.6.395 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **deps**: upgrade npm to 7.0.0 (Myles Borins)
(https://github.com/nodejs/node/pull/35631)
- **deps**: update npm to 7.0.0-rc.3 (Myles Borins)
(https://github.com/nodejs/node/pull/35474)
- **deps**: V8: cherry-pick 0d6debcc5f08 (Gus Caplan)
(https://github.com/nodejs/node/pull/33600)
- **dns**: add dns/promises alias (shisama)
(https://github.com/nodejs/node/pull/32953)
- **doc**: move DEP0018 to End-of-Life (Rich Trott)
(https://github.com/nodejs/node/pull/35316)
- **doc**: update support macos version for 15.x (Ash Cripps)
(https://github.com/nodejs/node/pull/35022)
- **fs**: deprecation warning on recursive rmdir (Ian Sutherland)
(https://github.com/nodejs/node/pull/35562)
- **fs**: reimplement read and write streams using stream.construct
(Robert Nagy) (https://github.com/nodejs/node/pull/29656)
- **http**: fixed socket.setEncoding fatal error (iskore)
(https://github.com/nodejs/node/pull/33405)
- **http**: emit 'error' on aborted server request (Robert Nagy)
(https://github.com/nodejs/node/pull/33172)
- **http**: cleanup end argument handling (Robert Nagy)
(https://github.com/nodejs/node/pull/31818)
- **http2**: allow Host in HTTP/2 requests (Alba Mendez)
(https://github.com/nodejs/node/pull/34664)
- **http2**: add `invalidheaders` test (Pranshu Srivastava)
(https://github.com/nodejs/node/pull/33161)
- **http2**: refactor state code validation for the http2Stream class
(rickyes) (https://github.com/nodejs/node/pull/33535)
- **http2**: header field valid checks (Pranshu Srivastava)
(https://github.com/nodejs/node/pull/33193)
- **lib**: add EventTarget-related browser globals (Anna Henningsen)
(https://github.com/nodejs/node/pull/35496)
- **lib**: remove ERR\_INVALID\_OPT\_VALUE and
ERR\_INVALID\_OPT\_VALUE\_ENCODING (Denys Otrishko)
(https://github.com/nodejs/node/pull/34682)
- **lib**: handle one of args case in ERR\_MISSING\_ARGS (Denys
Otrishko) (https://github.com/nodejs/node/pull/34022)
- **lib**: remove NodeError from the prototype of errors with code
(Michaël Zasso) (https://github.com/nodejs/node/pull/33857)
- **lib**: unflag AbortController (James M Snell)
(https://github.com/nodejs/node/pull/33527)
- **lib**: initial experimental AbortController implementation (James M
Snell) (https://github.com/nodejs/node/pull/33527)
- **net**: check args in net.connect() and socket.connect() calls
(Denys Otrishko) (https://github.com/nodejs/node/pull/34022)
- **net**: remove long deprecated server.connections property (James M
Snell) (https://github.com/nodejs/node/pull/33647)
- **net**: autoDestroy Socket (Robert Nagy)
(https://github.com/nodejs/node/pull/31806)
- **process**: update v8 fast api calls usage (Maya Lekova)
(https://github.com/nodejs/node/pull/35415)
- **process**: change default --unhandled-rejections=throw (Dan
Fabulich) (https://github.com/nodejs/node/pull/33021)
- **process**: use v8 fast api calls for hrtime (Gus Caplan)
(https://github.com/nodejs/node/pull/33600)
- **process**: delay throwing an error using `throwDeprecation` (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/32312)
- **repl**: remove deprecated repl.memory function (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.turnOffEditorMode() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated repl.parseREPLKeyword() function (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated bufferedCommand property (Ruben
Bridgewater) (https://github.com/nodejs/node/pull/33286)
- **repl**: remove deprecated .rli (Ruben Bridgewater)
(https://github.com/nodejs/node/pull/33286)
- **src**: implement NodePlatform::PostJob (Clemens Backes)
(https://github.com/nodejs/node/pull/35415)
- **src**: update NODE\_MODULE\_VERSION to 88 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **src**: error reporting on CPUUsage (Yash Ladha)
(https://github.com/nodejs/node/pull/34762)
- **src**: use node:moduleName as builtin module filename (Michaël
Zasso) (https://github.com/nodejs/node/pull/35498)
- **src**: enable wasm trap handler on windows (Gus Caplan)
(https://github.com/nodejs/node/pull/35033)
- **src**: update NODE\_MODULE\_VERSION to 86 (Michaël Zasso)
(https://github.com/nodejs/node/pull/33579)
- **src**: disallow JS execution inside FreeEnvironment (Anna
Henningsen) (https://github.com/nodejs/node/pull/33874)
- **src**: remove \_third\_party\_main support (Anna Henningsen)
(https://github.com/nodejs/node/pull/33971)
- **src**: remove deprecated node debug command (James M Snell)
(https://github.com/nodejs/node/pull/33648)
- **src**: remove unused CancelPendingDelayedTasks (Anna Henningsen)
(https://github.com/nodejs/node/pull/32859)
- **stream**: try to wait for flush to complete before 'finish' (Robert
Nagy) (https://github.com/nodejs/node/pull/34314)
- **stream**: cleanup and fix Readable.wrap (Robert Nagy)
(https://github.com/nodejs/node/pull/34204)
- **stream**: add promises version to utility functions (rickyes)
(https://github.com/nodejs/node/pull/33991)
- **stream**: fix writable.end callback behavior (Robert Nagy)
(https://github.com/nodejs/node/pull/34101)
- **stream**: construct (Robert Nagy)
(https://github.com/nodejs/node/pull/29656)
- **stream**: write should throw on unknown encoding (Robert Nagy)
(https://github.com/nodejs/node/pull/33075)
- **stream**: fix \_final and 'prefinish' timing (Robert Nagy)
(https://github.com/nodejs/node/pull/32780)
- **stream**: simplify Transform stream implementation (Robert Nagy)
(https://github.com/nodejs/node/pull/32763)
- **stream**: use callback to properly propagate error (Robert Nagy)
(https://github.com/nodejs/node/pull/29179)
- **test**: update tests after increasing typed array size to 4GB
(Kim-Anh Tran) (https://github.com/nodejs/node/pull/35415)
- **test**: fix tests for npm 7.0.0 (Myles Borins)
(https://github.com/nodejs/node/pull/35631)
- **test**: fix test suite to work with npm 7 (Myles Borins)
(https://github.com/nodejs/node/pull/35474)
- **test**: update WPT harness and tests (Michaël Zasso)
(https://github.com/nodejs/node/pull/33770)
- **timers**: introduce timers/promises (James M Snell)
(https://github.com/nodejs/node/pull/33950)
- **tools**: disable x86 safe exception handlers in V8 (Michaël Zasso)
(https://github.com/nodejs/node/pull/35415)
- **tools**: update V8 gypfiles for 8.6 (Ujjwal Sharma)
(https://github.com/nodejs/node/pull/35415)
- **tools**: update V8 gypfiles for 8.5 (Ujjwal Sharma)
(https://github.com/nodejs/node/pull/35415)
- **url**: file URL path normalization (Daijiro Wachi)
(https://github.com/nodejs/node/pull/35477)
- **url**: verify domain is not empty after "ToASCII" (Michaël Zasso)
(https://github.com/nodejs/node/pull/33770)
- **url**: remove U+0000 case in the fragment state (Michaël Zasso)
(https://github.com/nodejs/node/pull/33770)
- **url**: remove gopher from special schemes (Michaël Zasso)
(https://github.com/nodejs/node/pull/33325)
- **url**: forbid lt and gt in url host code point (Yash Ladha)
(https://github.com/nodejs/node/pull/33328)
- **util**: change default value of `maxStringLength` to 10000
(unknown) (https://github.com/nodejs/node/pull/32744)
- **wasi**: drop --experimental-wasm-bigint requirement (Colin Ihrig)
(https://github.com/nodejs/node/pull/35415)
- **win, child_process**: sanitize env variables (Bartosz Sosnowski)
(https://github.com/nodejs/node/pull/35210)
- **worker**: make MessageEvent class more Web-compatible (Anna
Henningsen) (https://github.com/nodejs/node/pull/35496)
- **worker**: set trackUnmanagedFds to true by default (Anna
Henningsen) (https://github.com/nodejs/node/pull/34394)
- **worker**: rename error code to be more accurate (Anna Henningsen)
(https://github.com/nodejs/node/pull/33872)
PR-URL: https://github.com/nodejs/node/pull/35014
2020-09-01 21:16:46 +01:00
|
|
|
- version: v15.0.0
|
2020-05-09 15:59:43 +02:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/33325
|
|
|
|
description: The scheme "gopher" is no longer special.
|
|
|
|
-->
|
2018-08-10 21:37:53 -07:00
|
|
|
|
|
|
|
The [WHATWG URL Standard][] considers a handful of URL protocol schemes to be
|
|
|
|
_special_ in terms of how they are parsed and serialized. When a URL is
|
|
|
|
parsed using one of these special protocols, the `url.protocol` property
|
|
|
|
may be changed to another special protocol but cannot be changed to a
|
|
|
|
non-special protocol, and vice versa.
|
|
|
|
|
|
|
|
For instance, changing from `http` to `https` works:
|
|
|
|
|
|
|
|
```js
|
|
|
|
const u = new URL('http://example.org');
|
|
|
|
u.protocol = 'https';
|
|
|
|
console.log(u.href);
|
2022-12-29 06:19:34 +09:00
|
|
|
// https://example.org/
|
2018-08-10 21:37:53 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
However, changing from `http` to a hypothetical `fish` protocol does not
|
|
|
|
because the new protocol is not special.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const u = new URL('http://example.org');
|
|
|
|
u.protocol = 'fish';
|
|
|
|
console.log(u.href);
|
2022-12-29 06:19:34 +09:00
|
|
|
// http://example.org/
|
2018-08-10 21:37:53 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
Likewise, changing from a non-special protocol to a special protocol is also
|
|
|
|
not permitted:
|
|
|
|
|
|
|
|
```js
|
|
|
|
const u = new URL('fish://example.org');
|
|
|
|
u.protocol = 'http';
|
|
|
|
console.log(u.href);
|
|
|
|
// fish://example.org
|
|
|
|
```
|
|
|
|
|
2019-06-05 22:35:59 -07:00
|
|
|
According to the WHATWG URL Standard, special protocol schemes are `ftp`,
|
2020-05-09 15:59:43 +02:00
|
|
|
`file`, `http`, `https`, `ws`, and `wss`.
|
2018-08-10 21:37:53 -07:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.search`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-03-05 18:03:39 +01:00
|
|
|
* {string}
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2017-01-04 15:41:09 -08:00
|
|
|
Gets and sets the serialized query portion of the URL.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const myURL = new URL('https://example.org/abc?123');
|
|
|
|
console.log(myURL.search);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints ?123
|
2017-01-04 15:41:09 -08:00
|
|
|
|
|
|
|
myURL.search = 'abc=xyz';
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org/abc?abc=xyz
|
2017-01-04 15:41:09 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
Any invalid URL characters appearing in the value assigned the `search`
|
2019-06-20 13:35:52 -06:00
|
|
|
property will be [percent-encoded][]. The selection of which
|
2017-02-12 12:17:03 -08:00
|
|
|
characters to percent-encode may vary somewhat from what the [`url.parse()`][]
|
|
|
|
and [`url.format()`][] methods would produce.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.searchParams`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-02-12 12:17:03 -08:00
|
|
|
* {URLSearchParams}
|
|
|
|
|
|
|
|
Gets the [`URLSearchParams`][] object representing the query parameters of the
|
2020-05-04 10:33:51 -07:00
|
|
|
URL. This property is read-only but the `URLSearchParams` object it provides
|
|
|
|
can be used to mutate the URL instance; to replace the entirety of query
|
|
|
|
parameters of the URL, use the [`url.search`][] setter. See
|
|
|
|
[`URLSearchParams`][] documentation for details.
|
|
|
|
|
|
|
|
Use care when using `.searchParams` to modify the `URL` because,
|
|
|
|
per the WHATWG specification, the `URLSearchParams` object uses
|
|
|
|
different rules to determine which characters to percent-encode. For
|
|
|
|
instance, the `URL` object will not percent encode the ASCII tilde (`~`)
|
|
|
|
character, while `URLSearchParams` will always encode it:
|
|
|
|
|
|
|
|
```js
|
2023-03-08 16:34:55 +09:00
|
|
|
const myURL = new URL('https://example.org/abc?foo=~bar');
|
2020-05-04 10:33:51 -07:00
|
|
|
|
2023-03-08 16:34:55 +09:00
|
|
|
console.log(myURL.search); // prints ?foo=~bar
|
2020-05-04 10:33:51 -07:00
|
|
|
|
|
|
|
// Modify the URL via searchParams...
|
2023-03-08 16:34:55 +09:00
|
|
|
myURL.searchParams.sort();
|
2020-05-04 10:33:51 -07:00
|
|
|
|
2023-03-08 16:34:55 +09:00
|
|
|
console.log(myURL.search); // prints ?foo=%7Ebar
|
2020-05-04 10:33:51 -07:00
|
|
|
```
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.username`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-03-05 18:03:39 +01:00
|
|
|
* {string}
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2017-01-04 15:41:09 -08:00
|
|
|
Gets and sets the username portion of the URL.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const myURL = new URL('https://abc:xyz@example.com');
|
|
|
|
console.log(myURL.username);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints abc
|
2017-01-04 15:41:09 -08:00
|
|
|
|
|
|
|
myURL.username = '123';
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://123:xyz@example.com/
|
2017-01-04 15:41:09 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
Any invalid URL characters appearing in the value assigned the `username`
|
2019-06-20 13:35:52 -06:00
|
|
|
property will be [percent-encoded][]. The selection of which
|
2017-02-12 12:17:03 -08:00
|
|
|
characters to percent-encode may vary somewhat from what the [`url.parse()`][]
|
|
|
|
and [`url.format()`][] methods would produce.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.toString()`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-03-05 18:03:39 +01:00
|
|
|
* Returns: {string}
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2017-01-04 15:41:09 -08:00
|
|
|
The `toString()` method on the `URL` object returns the serialized URL. The
|
2017-02-08 10:51:07 +01:00
|
|
|
value returned is equivalent to that of [`url.href`][] and [`url.toJSON()`][].
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `url.toJSON()`
|
2017-02-08 10:51:07 +01:00
|
|
|
|
2024-11-13 16:47:28 +00:00
|
|
|
<!-- YAML
|
|
|
|
added:
|
|
|
|
- v7.7.0
|
|
|
|
- v6.13.0
|
|
|
|
-->
|
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* Returns: {string}
|
|
|
|
|
|
|
|
The `toJSON()` method on the `URL` object returns the serialized URL. The
|
|
|
|
value returned is equivalent to that of [`url.href`][] and
|
|
|
|
[`url.toString()`][].
|
|
|
|
|
|
|
|
This method is automatically called when an `URL` object is serialized
|
|
|
|
with [`JSON.stringify()`][].
|
|
|
|
|
|
|
|
```js
|
|
|
|
const myURLs = [
|
|
|
|
new URL('https://www.example.com'),
|
2021-02-06 05:36:58 -08:00
|
|
|
new URL('https://test.example.org'),
|
2017-04-28 14:00:50 -07:00
|
|
|
];
|
|
|
|
console.log(JSON.stringify(myURLs));
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints ["https://www.example.com/","https://test.example.org/"]
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
|
|
|
|
2021-08-06 19:26:37 -07:00
|
|
|
#### `URL.createObjectURL(blob)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2021-08-06 19:26:37 -07:00
|
|
|
<!-- YAML
|
2021-08-16 17:03:53 -04:00
|
|
|
added: v16.7.0
|
2025-03-16 17:27:47 -07:00
|
|
|
changes:
|
|
|
|
- version: REPLACEME
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/57513
|
|
|
|
description: Marking the API stable.
|
2021-08-06 19:26:37 -07:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `blob` {Blob}
|
|
|
|
* Returns: {string}
|
|
|
|
|
|
|
|
Creates a `'blob:nodedata:...'` URL string that represents the given {Blob}
|
|
|
|
object and can be used to retrieve the `Blob` later.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const {
|
|
|
|
Blob,
|
|
|
|
resolveObjectURL,
|
2022-04-20 10:23:41 +02:00
|
|
|
} = require('node:buffer');
|
2021-08-06 19:26:37 -07:00
|
|
|
|
|
|
|
const blob = new Blob(['hello']);
|
|
|
|
const id = URL.createObjectURL(blob);
|
|
|
|
|
|
|
|
// later...
|
|
|
|
|
|
|
|
const otherBlob = resolveObjectURL(id);
|
|
|
|
console.log(otherBlob.size);
|
|
|
|
```
|
|
|
|
|
|
|
|
The data stored by the registered {Blob} will be retained in memory until
|
|
|
|
`URL.revokeObjectURL()` is called to remove it.
|
|
|
|
|
|
|
|
`Blob` objects are registered within the current thread. If using Worker
|
|
|
|
Threads, `Blob` objects registered within one Worker will not be available
|
|
|
|
to other workers or the main thread.
|
|
|
|
|
|
|
|
#### `URL.revokeObjectURL(id)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2021-08-06 19:26:37 -07:00
|
|
|
<!-- YAML
|
2021-08-16 17:03:53 -04:00
|
|
|
added: v16.7.0
|
2025-03-16 17:27:47 -07:00
|
|
|
changes:
|
|
|
|
- version: REPLACEME
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/57513
|
|
|
|
description: Marking the API stable.
|
2021-08-06 19:26:37 -07:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `id` {string} A `'blob:nodedata:...` URL string returned by a prior call to
|
|
|
|
`URL.createObjectURL()`.
|
|
|
|
|
2022-03-06 17:24:42 +08:00
|
|
|
Removes the stored {Blob} identified by the given ID. Attempting to revoke a
|
2022-05-17 21:04:51 +02:00
|
|
|
ID that isn't registered will silently fail.
|
2021-08-06 19:26:37 -07:00
|
|
|
|
2023-03-22 15:44:44 -04:00
|
|
|
#### `URL.canParse(input[, base])`
|
|
|
|
|
|
|
|
<!-- YAML
|
2023-07-10 08:12:52 -04:00
|
|
|
added:
|
|
|
|
- v19.9.0
|
|
|
|
- v18.17.0
|
2023-03-22 15:44:44 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `input` {string} The absolute or relative input URL to parse. If `input`
|
|
|
|
is relative, then `base` is required. If `input` is absolute, the `base`
|
|
|
|
is ignored. If `input` is not a string, it is [converted to a string][] first.
|
|
|
|
* `base` {string} The base URL to resolve against if the `input` is not
|
|
|
|
absolute. If `base` is not a string, it is [converted to a string][] first.
|
|
|
|
* Returns: {boolean}
|
|
|
|
|
|
|
|
Checks if an `input` relative to the `base` can be parsed to a `URL`.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const isValid = URL.canParse('/foo', 'https://example.org/'); // true
|
|
|
|
|
|
|
|
const isNotValid = URL.canParse('/foo'); // false
|
|
|
|
```
|
|
|
|
|
2024-07-04 22:51:03 -04:00
|
|
|
#### `URL.parse(input[, base])`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added: v22.1.0
|
|
|
|
-->
|
|
|
|
|
|
|
|
* `input` {string} The absolute or relative input URL to parse. If `input`
|
|
|
|
is relative, then `base` is required. If `input` is absolute, the `base`
|
|
|
|
is ignored. If `input` is not a string, it is [converted to a string][] first.
|
|
|
|
* `base` {string} The base URL to resolve against if the `input` is not
|
|
|
|
absolute. If `base` is not a string, it is [converted to a string][] first.
|
|
|
|
* Returns: {URL|null}
|
|
|
|
|
|
|
|
Parses a string as a URL. If `base` is provided, it will be used as the base
|
|
|
|
URL for the purpose of resolving non-absolute `input` URLs. Returns `null`
|
|
|
|
if `input` is not a valid.
|
|
|
|
|
2025-01-30 14:38:19 -05:00
|
|
|
### Class: `URLPattern`
|
|
|
|
|
|
|
|
<!-- YAML
|
2025-02-11 09:55:52 -05:00
|
|
|
added: v23.8.0
|
2025-01-30 14:38:19 -05:00
|
|
|
-->
|
|
|
|
|
2025-02-12 19:25:09 +01:00
|
|
|
> Stability: 1 - Experimental
|
|
|
|
|
2025-01-30 14:38:19 -05:00
|
|
|
The `URLPattern` API provides an interface to match URLs or parts of URLs
|
|
|
|
against a pattern.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html');
|
|
|
|
console.log(myPattern.exec('https://nodejs.org/docs/latest/api/dns.html'));
|
|
|
|
// Prints:
|
|
|
|
// {
|
|
|
|
// "hash": { "groups": { "0": "" }, "input": "" },
|
|
|
|
// "hostname": { "groups": {}, "input": "nodejs.org" },
|
|
|
|
// "inputs": [
|
|
|
|
// "https://nodejs.org/docs/latest/api/dns.html"
|
|
|
|
// ],
|
|
|
|
// "password": { "groups": { "0": "" }, "input": "" },
|
|
|
|
// "pathname": { "groups": { "0": "dns" }, "input": "/docs/latest/api/dns.html" },
|
|
|
|
// "port": { "groups": {}, "input": "" },
|
|
|
|
// "protocol": { "groups": {}, "input": "https" },
|
|
|
|
// "search": { "groups": { "0": "" }, "input": "" },
|
|
|
|
// "username": { "groups": { "0": "" }, "input": "" }
|
|
|
|
// }
|
|
|
|
|
|
|
|
console.log(myPattern.test('https://nodejs.org/docs/latest/api/dns.html'));
|
|
|
|
// Prints: true
|
|
|
|
```
|
|
|
|
|
|
|
|
#### `new URLPattern()`
|
|
|
|
|
|
|
|
Instantiate a new empty `URLPattern` object.
|
|
|
|
|
|
|
|
#### `new URLPattern(string[, baseURL][, options])`
|
|
|
|
|
|
|
|
* `string` {string} A URL string
|
|
|
|
* `baseURL` {string | undefined} A base URL string
|
|
|
|
* `options` {Object} Options
|
|
|
|
|
|
|
|
Parse the `string` as a URL, and use it to instantiate a new
|
|
|
|
`URLPattern` object.
|
|
|
|
|
|
|
|
If `baseURL` is not specified, it defaults to `undefined`.
|
|
|
|
|
|
|
|
An option can have `ignoreCase` boolean attribute which enables
|
|
|
|
case-insensitive matching if set to true.
|
|
|
|
|
|
|
|
The constructor can throw a `TypeError` to indicate parsing failure.
|
|
|
|
|
2025-03-15 11:24:20 +02:00
|
|
|
#### `new URLPattern(obj[, baseURL][, options])`
|
2025-01-30 14:38:19 -05:00
|
|
|
|
|
|
|
* `obj` {Object} An input pattern
|
|
|
|
* `baseURL` {string | undefined} A base URL string
|
|
|
|
* `options` {Object} Options
|
|
|
|
|
|
|
|
Parse the `Object` as an input pattern, and use it to instantiate a new
|
|
|
|
`URLPattern` object. The object members can be any of `protocol`, `username`,
|
|
|
|
`password`, `hostname`, `port`, `pathname`, `search`, `hash` or `baseURL`.
|
|
|
|
|
|
|
|
If `baseURL` is not specified, it defaults to `undefined`.
|
|
|
|
|
|
|
|
An option can have `ignoreCase` boolean attribute which enables
|
|
|
|
case-insensitive matching if set to true.
|
|
|
|
|
|
|
|
The constructor can throw a `TypeError` to indicate parsing failure.
|
|
|
|
|
|
|
|
#### `urlPattern.exec(input[, baseURL])`
|
|
|
|
|
|
|
|
* `input` {string | Object} A URL or URL parts
|
|
|
|
* `baseURL` {string | undefined} A base URL string
|
|
|
|
|
|
|
|
Input can be a string or an object providing the individual URL parts. The
|
|
|
|
object members can be any of `protocol`, `username`, `password`, `hostname`,
|
|
|
|
`port`, `pathname`, `search`, `hash` or `baseURL`.
|
|
|
|
|
|
|
|
If `baseURL` is not specified, it will default to `undefined`.
|
|
|
|
|
|
|
|
Returns an object with an `inputs` key containing the array of arguments
|
|
|
|
passed into the function and keys of the URL components which contains the
|
|
|
|
matched input and matched groups.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html');
|
|
|
|
console.log(myPattern.exec('https://nodejs.org/docs/latest/api/dns.html'));
|
|
|
|
// Prints:
|
|
|
|
// {
|
|
|
|
// "hash": { "groups": { "0": "" }, "input": "" },
|
|
|
|
// "hostname": { "groups": {}, "input": "nodejs.org" },
|
|
|
|
// "inputs": [
|
|
|
|
// "https://nodejs.org/docs/latest/api/dns.html"
|
|
|
|
// ],
|
|
|
|
// "password": { "groups": { "0": "" }, "input": "" },
|
|
|
|
// "pathname": { "groups": { "0": "dns" }, "input": "/docs/latest/api/dns.html" },
|
|
|
|
// "port": { "groups": {}, "input": "" },
|
|
|
|
// "protocol": { "groups": {}, "input": "https" },
|
|
|
|
// "search": { "groups": { "0": "" }, "input": "" },
|
|
|
|
// "username": { "groups": { "0": "" }, "input": "" }
|
|
|
|
// }
|
|
|
|
```
|
|
|
|
|
|
|
|
#### `urlPattern.test(input[, baseURL])`
|
|
|
|
|
|
|
|
* `input` {string | Object} A URL or URL parts
|
|
|
|
* `baseURL` {string | undefined} A base URL string
|
|
|
|
|
|
|
|
Input can be a string or an object providing the individual URL parts. The
|
|
|
|
object members can be any of `protocol`, `username`, `password`, `hostname`,
|
|
|
|
`port`, `pathname`, `search`, `hash` or `baseURL`.
|
|
|
|
|
|
|
|
If `baseURL` is not specified, it will default to `undefined`.
|
|
|
|
|
|
|
|
Returns a boolean indicating if the input matches the current pattern.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html');
|
|
|
|
console.log(myPattern.test('https://nodejs.org/docs/latest/api/dns.html'));
|
|
|
|
// Prints: true
|
|
|
|
```
|
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
### Class: `URLSearchParams`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
<!-- YAML
|
2018-12-05 10:44:37 +01:00
|
|
|
added:
|
|
|
|
- v7.5.0
|
|
|
|
- v6.13.0
|
2018-01-21 17:11:47 +01:00
|
|
|
changes:
|
2018-03-02 09:53:46 -08:00
|
|
|
- version: v10.0.0
|
2018-01-21 17:11:47 +01:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/18281
|
|
|
|
description: The class is now available on the global object.
|
2017-04-28 14:00:50 -07:00
|
|
|
-->
|
|
|
|
|
|
|
|
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
|
|
|
|
four following constructors.
|
2018-01-21 17:11:47 +01:00
|
|
|
The `URLSearchParams` class is also available on the global object.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
The WHATWG `URLSearchParams` interface and the [`querystring`][] module have
|
|
|
|
similar purpose, but the purpose of the [`querystring`][] module is more
|
|
|
|
general, as it allows the customization of delimiter characters (`&` and `=`).
|
|
|
|
On the other hand, this API is designed purely for URL query strings.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const myURL = new URL('https://example.org/?abc=123');
|
|
|
|
console.log(myURL.searchParams.get('abc'));
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 123
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
myURL.searchParams.append('abc', 'xyz');
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org/?abc=123&abc=xyz
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
myURL.searchParams.delete('abc');
|
|
|
|
myURL.searchParams.set('a', 'b');
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org/?a=b
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
const newSearchParams = new URLSearchParams(myURL.searchParams);
|
|
|
|
// The above is equivalent to
|
|
|
|
// const newSearchParams = new URLSearchParams(myURL.search);
|
|
|
|
|
|
|
|
newSearchParams.append('a', 'c');
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org/?a=b
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(newSearchParams.toString());
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints a=b&a=c
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
// newSearchParams.toString() is implicitly called
|
|
|
|
myURL.search = newSearchParams;
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org/?a=b&a=c
|
2017-04-28 14:00:50 -07:00
|
|
|
newSearchParams.delete('a');
|
|
|
|
console.log(myURL.href);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints https://example.org/?a=b&a=c
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
|
|
|
|
2020-06-06 22:06:34 -07:00
|
|
|
#### `new URLSearchParams()`
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
Instantiate a new empty `URLSearchParams` object.
|
|
|
|
|
2020-06-06 22:06:34 -07:00
|
|
|
#### `new URLSearchParams(string)`
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
* `string` {string} A query string
|
|
|
|
|
|
|
|
Parse the `string` as a query string, and use it to instantiate a new
|
|
|
|
`URLSearchParams` object. A leading `'?'`, if present, is ignored.
|
|
|
|
|
|
|
|
```js
|
|
|
|
let params;
|
|
|
|
|
|
|
|
params = new URLSearchParams('user=abc&query=xyz');
|
|
|
|
console.log(params.get('user'));
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 'abc'
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(params.toString());
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 'user=abc&query=xyz'
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
params = new URLSearchParams('?user=abc&query=xyz');
|
|
|
|
console.log(params.toString());
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 'user=abc&query=xyz'
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
|
|
|
|
2020-06-06 22:06:34 -07:00
|
|
|
#### `new URLSearchParams(obj)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
<!-- YAML
|
2018-12-05 10:44:37 +01:00
|
|
|
added:
|
|
|
|
- v7.10.0
|
|
|
|
- v6.13.0
|
2017-04-28 14:00:50 -07:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `obj` {Object} An object representing a collection of key-value pairs
|
|
|
|
|
|
|
|
Instantiate a new `URLSearchParams` object with a query hash map. The key and
|
|
|
|
value of each property of `obj` are always coerced to strings.
|
|
|
|
|
2018-02-05 21:55:16 -08:00
|
|
|
Unlike [`querystring`][] module, duplicate keys in the form of array values are
|
|
|
|
not allowed. Arrays are stringified using [`array.toString()`][], which simply
|
|
|
|
joins all array elements with commas.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
const params = new URLSearchParams({
|
|
|
|
user: 'abc',
|
2022-11-17 08:19:12 -05:00
|
|
|
query: ['first', 'second'],
|
2017-04-28 14:00:50 -07:00
|
|
|
});
|
|
|
|
console.log(params.getAll('query'));
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints [ 'first,second' ]
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(params.toString());
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 'user=abc&query=first%2Csecond'
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
|
|
|
|
2020-06-06 22:06:34 -07:00
|
|
|
#### `new URLSearchParams(iterable)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
<!-- YAML
|
2018-12-05 10:44:37 +01:00
|
|
|
added:
|
|
|
|
- v7.10.0
|
|
|
|
- v6.13.0
|
2017-04-28 14:00:50 -07:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `iterable` {Iterable} An iterable object whose elements are key-value pairs
|
|
|
|
|
|
|
|
Instantiate a new `URLSearchParams` object with an iterable map in a way that
|
2025-02-07 15:33:06 +01:00
|
|
|
is similar to {Map}'s constructor. `iterable` can be an `Array` or any
|
2017-04-28 14:00:50 -07:00
|
|
|
iterable object. That means `iterable` can be another `URLSearchParams`, in
|
|
|
|
which case the constructor will simply create a clone of the provided
|
2018-04-02 08:38:48 +03:00
|
|
|
`URLSearchParams`. Elements of `iterable` are key-value pairs, and can
|
2017-04-28 14:00:50 -07:00
|
|
|
themselves be any iterable object.
|
|
|
|
|
|
|
|
Duplicate keys are allowed.
|
|
|
|
|
|
|
|
```js
|
|
|
|
let params;
|
|
|
|
|
|
|
|
// Using an array
|
|
|
|
params = new URLSearchParams([
|
|
|
|
['user', 'abc'],
|
|
|
|
['query', 'first'],
|
2021-02-06 05:36:58 -08:00
|
|
|
['query', 'second'],
|
2017-04-28 14:00:50 -07:00
|
|
|
]);
|
|
|
|
console.log(params.toString());
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 'user=abc&query=first&query=second'
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
// Using a Map object
|
|
|
|
const map = new Map();
|
|
|
|
map.set('user', 'abc');
|
|
|
|
map.set('query', 'xyz');
|
|
|
|
params = new URLSearchParams(map);
|
|
|
|
console.log(params.toString());
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 'user=abc&query=xyz'
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
// Using a generator function
|
|
|
|
function* getQueryPairs() {
|
|
|
|
yield ['user', 'abc'];
|
|
|
|
yield ['query', 'first'];
|
|
|
|
yield ['query', 'second'];
|
|
|
|
}
|
|
|
|
params = new URLSearchParams(getQueryPairs());
|
|
|
|
console.log(params.toString());
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 'user=abc&query=first&query=second'
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
// Each key-value pair must have exactly two elements
|
|
|
|
new URLSearchParams([
|
2021-02-06 05:36:58 -08:00
|
|
|
['user', 'abc', 'error'],
|
2017-04-28 14:00:50 -07:00
|
|
|
]);
|
2017-06-27 13:32:32 -07:00
|
|
|
// Throws TypeError [ERR_INVALID_TUPLE]:
|
|
|
|
// Each query pair must be an iterable [name, value] tuple
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlSearchParams.append(name, value)`
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
* `name` {string}
|
|
|
|
* `value` {string}
|
|
|
|
|
|
|
|
Append a new name-value pair to the query string.
|
|
|
|
|
2023-05-14 20:05:19 +05:30
|
|
|
#### `urlSearchParams.delete(name[, value])`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
changes:
|
2023-09-16 22:51:24 -04:00
|
|
|
- version:
|
|
|
|
- v20.2.0
|
|
|
|
- v18.18.0
|
2023-05-14 20:05:19 +05:30
|
|
|
pr-url: https://github.com/nodejs/node/pull/47885
|
|
|
|
description: Add support for optional `value` argument.
|
|
|
|
-->
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
* `name` {string}
|
2023-05-14 20:05:19 +05:30
|
|
|
* `value` {string}
|
|
|
|
|
|
|
|
If `value` is provided, removes all name-value pairs
|
|
|
|
where name is `name` and value is `value`..
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2023-05-14 20:05:19 +05:30
|
|
|
If `value` is not provided, removes all name-value pairs whose name is `name`.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlSearchParams.entries()`
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
* Returns: {Iterator}
|
|
|
|
|
2018-04-29 20:46:41 +03:00
|
|
|
Returns an ES6 `Iterator` over each of the name-value pairs in the query.
|
|
|
|
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`.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
Alias for [`urlSearchParams[@@iterator]()`][`urlSearchParams@@iterator()`].
|
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlSearchParams.forEach(fn[, thisArg])`
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2022-01-24 19:39:16 +03:30
|
|
|
<!-- YAML
|
|
|
|
changes:
|
2022-04-19, Version 18.0.0 (Current)
Notable Changes:
Deprecations and Removals:
- (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`,
`fs.writeFileSync`
(Livia Medeiros) (https://github.com/nodejs/node/pull/42607)
- (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup`
options type coercion
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) process: runtime deprecate multipleResolves
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896)
- (SEMVER-MAJOR) stream: remove thenable support (Robert Nagy)
(https://github.com/nodejs/node/pull/40773)
- (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life
(Tobias Nießen) (https://github.com/nodejs/node/pull/41479)
fetch (experimental):
An experimental fetch API is available on the global scope by default.
The implementation is based upon https://undici.nodejs.org/#/,
an HTTP/1.1 client written for Node.js by contributors to the project.
Through this addition, the following globals are made available: `fetch`
, `FormData`, `Headers`, `Request`, `Response`.
Disable this API with the `--no-experimental-fetch` command-line flag.
Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/41811.
HTTP Timeouts:
`server.headersTimeout`, which limits the amount of time the parser will
wait to receive the complete HTTP headers, is now set to `60000` (60
seconds) by default.
`server.requestTimeout`, which sets the timeout value in milliseconds
for receiving the entire request from the client, is now set to `300000`
(5 minutes) by default.
If these timeouts expire, the server responds with status 408 without
forwarding the request to the request listener and then closes the
connection.
Both timeouts must be set to a non-zero value to protect against
potential Denial-of-Service attacks in case the server is deployed
without a reverse proxy in front.
Contributed by Paolo Insogna in https://github.com/nodejs/node/pull/41263.
Test Runner module (experimental):
The `node:test` module facilitates the creation of JavaScript tests that
report results in TAP format. This module is only available under the
`node:` scheme.
Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/42325.
Toolchain and Compiler Upgrades:
- Prebuilt binaries for Linux are now built on Red Hat Enterprise Linux
(RHEL) 8 and are compatible with Linux distributions based on glibc
2.28 or later, for example, Debian 10, RHEL 8, Ubuntu 20.04.
- Prebuilt binaries for macOS now require macOS 10.15 or later.
- For AIX the minimum supported architecture has been raised from Power
7 to Power 8.
Prebuilt binaries for 32-bit Windows will initially not be available due
to issues building the V8 dependency in Node.js. We hope to restore
32-bit Windows binaries for Node.js 18 with a future V8 update.
Node.js does not support running on operating systems that are no longer
supported by their vendor. For operating systems where their vendor has
planned to end support earlier than April 2025, such as Windows 8.1
(January 2023) and Windows Server 2012 R2 (October 2023), support for
Node.js 18 will end at the earlier date.
Full details about the supported toolchains and compilers are documented
in the Node.js `BUILDING.md` file.
Contributed by Richard Lau in https://github.com/nodejs/node/pull/42292,
https://github.com/nodejs/node/pull/42604 and https://github.com/nodejs/node/pull/42659
, and Michaël Zasso in https://github.com/nodejs/node/pull/42105 and
https://github.com/nodejs/node/pull/42666.
V8 10.1:
The V8 engine is updated to version 10.1, which is part of Chromium 101.
Compared to the version included in Node.js 17.9.0, the following new
features are included:
- The `findLast` and `findLastIndex` array methods.
- Improvements to the `Intl.Locale` API.
- The `Intl.supportedValuesOf` function.
- Improved performance of class fields and private class methods (the
initialization of them is now as fast as ordinary property stores).
The data format returned by the serialization API (`v8.serialize(value)`)
has changed, and cannot be deserialized by earlier versions of Node.js.
On the other hand, it is still possible to deserialize the previous
format, as the API is backwards-compatible.
Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/42657.
Web Streams API (experimental):
Node.js now exposes the experimental implementation of the Web Streams
API on the global scope. This means the following APIs are now globally
available:
- `ReadableStream`, `ReadableStreamDefaultReader`,
`ReadableStreamBYOBReader`, `ReadableStreamBYOBRequest`,
`ReadableByteStreamController`, `ReadableStreamDefaultController`,
`TransformStream`, `TransformStreamDefaultController`, `WritableStream`,
`WritableStreamDefaultWriter`, `WritableStreamDefaultController`,
`ByteLengthQueuingStrategy`, `CountQueuingStrategy`, `TextEncoderStream`,
`TextDecoderStream`, `CompressionStream`, `DecompressionStream`.
Contributed James Snell in https://github.com/nodejs/node/pull/39062,
and Antoine du Hamel in https://github.com/nodejs/node/pull/42225.
Other Notable Changes:
- (SEMVER-MAJOR) buffer: expose Blob as a global
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) child\_process: improve argument validation
(Rich Trott) (https://github.com/nodejs/node/pull/41305)
- doc: add RafaelGSS to collaborators
(RafaelGSS) (https://github.com/nodejs/node/pull/42718)
- (SEMVER-MAJOR) http: make TCP noDelay enabled by default
(Paolo Insogna) (https://github.com/nodejs/node/pull/42163)
- (SEMVER-MAJOR) net: make `server.address()` return an integer for
`family`
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) worker: expose BroadcastChannel as a global
(James M Snell) (https://github.com/nodejs/node/pull/41271)
- (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported
(James M Snell) (https://github.com/nodejs/node/pull/41271)
Semver-Major Commits:
- (SEMVER-MAJOR) assert,util: compare RegExp.lastIndex while using deep
equal checks
(Ruben Bridgewater) (https://github.com/nodejs/node/pull/41020)
- (SEMVER-MAJOR) buffer: refactor `byteLength` to remove outdated
optimizations
(Rongjian Zhang) (https://github.com/nodejs/node/pull/38545)
- (SEMVER-MAJOR) buffer: expose Blob as a global
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) buffer: graduate Blob from experimental
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) build: make x86 Windows support temporarily
experimental
(Michaël Zasso) (https://github.com/nodejs/node/pull/42666)
- (SEMVER-MAJOR) build: bump macOS deployment target to 10.15
(Richard Lau) (https://github.com/nodejs/node/pull/42292)
- (SEMVER-MAJOR) build: downgrade Windows 8.1 and server 2012 R2 to
experimental
(Michaël Zasso) (https://github.com/nodejs/node/pull/42105)
- (SEMVER-MAJOR) child\_process: improve argument validation
(Rich Trott) (https://github.com/nodejs/node/pull/41305)
- (SEMVER-MAJOR) cluster: make `kill` to be just `process.kill`
(Bar Admoni) (https://github.com/nodejs/node/pull/34312)
- (SEMVER-MAJOR) crypto: cleanup validation
(Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/39841)
- (SEMVER-MAJOR) crypto: prettify othername in PrintGeneralName
(Tobias Nießen) (https://github.com/nodejs/node/pull/42123)
- (SEMVER-MAJOR) crypto: fix X509Certificate toLegacyObject
(Tobias Nießen) (https://github.com/nodejs/node/pull/42124)
- (SEMVER-MAJOR) crypto: use RFC2253 format in PrintGeneralName
(Tobias Nießen) (https://github.com/nodejs/node/pull/42002)
- (SEMVER-MAJOR) crypto: change default check(Host|Email) behavior
(Tobias Nießen) (https://github.com/nodejs/node/pull/41600)
- (SEMVER-MAJOR) deps: V8: cherry-pick semver-major commits from 10.2
(Michaël Zasso) (https://github.com/nodejs/node/pull/42657)
- (SEMVER-MAJOR) deps: update V8 to 10.1.124.6
(Michaël Zasso) (https://github.com/nodejs/node/pull/42657)
- (SEMVER-MAJOR) deps: update V8 to 9.8.177.9
(Michaël Zasso) (https://github.com/nodejs/node/pull/41610)
- (SEMVER-MAJOR) deps: update V8 to 9.7.106.18
(Michaël Zasso) (https://github.com/nodejs/node/pull/40907)
- (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup`
options type coercion
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) doc: update minimum glibc requirements for Linux
(Richard Lau) (https://github.com/nodejs/node/pull/42659)
- (SEMVER-MAJOR) doc: update AIX minimum supported arch
(Richard Lau) (https://github.com/nodejs/node/pull/42604)
- (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`,
`fs.writeFileSync`
(Livia Medeiros) (https://github.com/nodejs/node/pull/42607)
- (SEMVER-MAJOR) http: refactor headersTimeout and requestTimeout logic
(Paolo Insogna) (https://github.com/nodejs/node/pull/41263)
- (SEMVER-MAJOR) http: make TCP noDelay enabled by default
(Paolo Insogna) (https://github.com/nodejs/node/pull/42163)
- (SEMVER-MAJOR) lib: enable fetch by default
(Michaël Zasso) (https://github.com/nodejs/node/pull/41811)
- (SEMVER-MAJOR) lib: replace validator and error
(Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/41678)
- (SEMVER-MAJOR) module,repl: support 'node:'-only core modules
(Colin Ihrig) (https://github.com/nodejs/node/pull/42325)
- (SEMVER-MAJOR) net: make `server.address()` return an integer for
`family`
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) process: disallow some uses of Object.defineProperty()
on process.env
(Himself65) (https://github.com/nodejs/node/pull/28006)
- (SEMVER-MAJOR) process: runtime deprecate multipleResolves
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896)
- (SEMVER-MAJOR) readline: fix question still called after closed
(Xuguang Mei) (https://github.com/nodejs/node/pull/42464)
- (SEMVER-MAJOR) stream: remove thenable support
(Robert Nagy) (https://github.com/nodejs/node/pull/40773)
- (SEMVER-MAJOR) stream: expose web streams globals, remove runtime
experimental warning
(Antoine du Hamel) (https://github.com/nodejs/node/pull/42225)
- (SEMVER-MAJOR) stream: need to cleanup event listeners if last stream
is readable
(Xuguang Mei) (https://github.com/nodejs/node/pull/41954)
- (SEMVER-MAJOR) stream: revert revert `map` spec compliance
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41933)
- (SEMVER-MAJOR) stream: throw invalid arg type from End Of Stream
(Jithil P Ponnan) (https://github.com/nodejs/node/pull/41766)
- (SEMVER-MAJOR) stream: don't emit finish after destroy
(Robert Nagy) (https://github.com/nodejs/node/pull/40852)
- (SEMVER-MAJOR) stream: add errored and closed props
(Robert Nagy) (https://github.com/nodejs/node/pull/40696)
- (SEMVER-MAJOR) test: add initial test module
(Colin Ihrig) (https://github.com/nodejs/node/pull/42325)
- (SEMVER-MAJOR) timers: refactor internal classes to ES2015 syntax
(Rabbit) (https://github.com/nodejs/node/pull/37408)
- (SEMVER-MAJOR) tls: represent registeredID numerically always
(Tobias Nießen) (https://github.com/nodejs/node/pull/41561)
- (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life
(Tobias Nießen) (https://github.com/nodejs/node/pull/41479)
- (SEMVER-MAJOR) url: throw on NULL in IPv6 hostname
(Rich Trott) (https://github.com/nodejs/node/pull/42313)
- (SEMVER-MAJOR) v8: make v8.writeHeapSnapshot() error codes consistent
(Darshan Sen) (https://github.com/nodejs/node/pull/42577)
- (SEMVER-MAJOR) v8: make writeHeapSnapshot throw if fopen fails
(Antonio Román) (https://github.com/nodejs/node/pull/41373)
- (SEMVER-MAJOR) worker: expose BroadcastChannel as a global
(James M Snell) (https://github.com/nodejs/node/pull/41271)
- (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported
(James M Snell) (https://github.com/nodejs/node/pull/41271)
PR-URL: https://github.com/nodejs/node/pull/42262
2022-03-08 01:39:47 +00:00
|
|
|
- version: v18.0.0
|
2022-01-24 19:39:16 +03:30
|
|
|
pr-url: https://github.com/nodejs/node/pull/41678
|
|
|
|
description: Passing an invalid callback to the `fn` argument
|
|
|
|
now throws `ERR_INVALID_ARG_TYPE` instead of
|
|
|
|
`ERR_INVALID_CALLBACK`.
|
|
|
|
-->
|
|
|
|
|
2018-04-29 20:46:41 +03:00
|
|
|
* `fn` {Function} Invoked for each name-value pair in the query
|
|
|
|
* `thisArg` {Object} To be used as `this` value for when `fn` is called
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
Iterates over each name-value pair in the query and invokes the given function.
|
|
|
|
|
|
|
|
```js
|
|
|
|
const myURL = new URL('https://example.org/?a=b&c=d');
|
|
|
|
myURL.searchParams.forEach((value, name, searchParams) => {
|
|
|
|
console.log(name, value, myURL.searchParams === searchParams);
|
|
|
|
});
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints:
|
|
|
|
// a b true
|
|
|
|
// c d true
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlSearchParams.get(name)`
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
* `name` {string}
|
2024-02-14 00:37:42 +03:00
|
|
|
* Returns: {string | null} A string or `null` if there is no name-value pair
|
|
|
|
with the given `name`.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
Returns the value of the first name-value pair whose name is `name`. If there
|
|
|
|
are no such pairs, `null` is returned.
|
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlSearchParams.getAll(name)`
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
* `name` {string}
|
2021-10-10 21:55:04 -07:00
|
|
|
* Returns: {string\[]}
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
Returns the values of all name-value pairs whose name is `name`. If there are
|
|
|
|
no such pairs, an empty array is returned.
|
|
|
|
|
2023-05-14 20:05:19 +05:30
|
|
|
#### `urlSearchParams.has(name[, value])`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
changes:
|
2023-09-16 22:51:24 -04:00
|
|
|
- version:
|
|
|
|
- v20.2.0
|
|
|
|
- v18.18.0
|
2023-05-14 20:05:19 +05:30
|
|
|
pr-url: https://github.com/nodejs/node/pull/47885
|
|
|
|
description: Add support for optional `value` argument.
|
|
|
|
-->
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
* `name` {string}
|
2023-05-14 20:05:19 +05:30
|
|
|
* `value` {string}
|
2017-04-28 14:00:50 -07:00
|
|
|
* Returns: {boolean}
|
|
|
|
|
2023-05-14 20:05:19 +05:30
|
|
|
Checks if the `URLSearchParams` object contains key-value pair(s) based on
|
|
|
|
`name` and an optional `value` argument.
|
|
|
|
|
|
|
|
If `value` is provided, returns `true` when name-value pair with
|
|
|
|
same `name` and `value` exists.
|
|
|
|
|
|
|
|
If `value` is not provided, returns `true` if there is at least one name-value
|
|
|
|
pair whose name is `name`.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlSearchParams.keys()`
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
* Returns: {Iterator}
|
|
|
|
|
2018-04-29 20:46:41 +03:00
|
|
|
Returns an ES6 `Iterator` over the names of each name-value pair.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
const params = new URLSearchParams('foo=bar&foo=baz');
|
|
|
|
for (const name of params.keys()) {
|
|
|
|
console.log(name);
|
|
|
|
}
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints:
|
|
|
|
// foo
|
|
|
|
// foo
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlSearchParams.set(name, value)`
|
2017-02-08 10:51:07 +01:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* `name` {string}
|
|
|
|
* `value` {string}
|
2017-02-08 10:51:07 +01:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
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`,
|
|
|
|
set the first such pair's value to `value` and remove all others. If not,
|
|
|
|
append the name-value pair to the query string.
|
2017-02-08 10:51:07 +01:00
|
|
|
|
|
|
|
```js
|
2017-04-28 14:00:50 -07:00
|
|
|
const params = new URLSearchParams();
|
|
|
|
params.append('foo', 'bar');
|
|
|
|
params.append('foo', 'baz');
|
|
|
|
params.append('abc', 'def');
|
|
|
|
console.log(params.toString());
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints foo=bar&foo=baz&abc=def
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
params.set('foo', 'def');
|
|
|
|
params.set('xyz', 'opq');
|
|
|
|
console.log(params.toString());
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints foo=def&abc=def&xyz=opq
|
2017-02-08 10:51:07 +01:00
|
|
|
```
|
|
|
|
|
2023-01-22 12:14:11 -08:00
|
|
|
#### `urlSearchParams.size`
|
|
|
|
|
|
|
|
<!-- YAML
|
2023-04-10 23:02:28 -04:00
|
|
|
added:
|
|
|
|
- v19.8.0
|
|
|
|
- v18.16.0
|
2023-01-22 12:14:11 -08:00
|
|
|
-->
|
|
|
|
|
|
|
|
The total number of parameter entries.
|
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlSearchParams.sort()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2017-04-26 17:41:17 -07:00
|
|
|
<!-- YAML
|
2018-12-05 10:44:37 +01:00
|
|
|
added:
|
|
|
|
- v7.7.0
|
|
|
|
- v6.13.0
|
2017-04-26 17:41:17 -07:00
|
|
|
-->
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Sort all existing name-value pairs in-place by their names. Sorting is done
|
|
|
|
with a [stable sorting algorithm][], so relative order between name-value pairs
|
|
|
|
with the same name is preserved.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
This method can be used, in particular, to increase cache hits.
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2017-01-04 15:41:09 -08:00
|
|
|
```js
|
2017-04-28 14:00:50 -07:00
|
|
|
const params = new URLSearchParams('query[]=abc&type=search&query[]=123');
|
|
|
|
params.sort();
|
|
|
|
console.log(params.toString());
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints query%5B%5D=abc&query%5B%5D=123&type=search
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlSearchParams.toString()`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* Returns: {string}
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Returns the search parameters serialized as a string, with characters
|
|
|
|
percent-encoded where necessary.
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlSearchParams.values()`
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* Returns: {Iterator}
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2018-04-29 20:46:41 +03:00
|
|
|
Returns an ES6 `Iterator` over the values of each name-value pair.
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlSearchParams[Symbol.iterator]()`
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* Returns: {Iterator}
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2018-04-29 20:46:41 +03:00
|
|
|
Returns an ES6 `Iterator` over each of the name-value pairs in the query string.
|
|
|
|
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`.
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Alias for [`urlSearchParams.entries()`][].
|
2017-01-28 12:02:35 -08:00
|
|
|
|
|
|
|
```js
|
2017-04-28 14:00:50 -07:00
|
|
|
const params = new URLSearchParams('foo=bar&xyz=baz');
|
|
|
|
for (const [name, value] of params) {
|
|
|
|
console.log(name, value);
|
|
|
|
}
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints:
|
|
|
|
// foo bar
|
|
|
|
// xyz baz
|
2017-04-28 14:00:50 -07:00
|
|
|
```
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
### `url.domainToASCII(domain)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
<!-- YAML
|
2018-12-05 10:44:37 +01:00
|
|
|
added:
|
|
|
|
- v7.4.0
|
|
|
|
- v6.13.0
|
2023-03-31 09:04:03 -04:00
|
|
|
changes:
|
2023-07-10 08:12:52 -04:00
|
|
|
- version:
|
|
|
|
- v20.0.0
|
|
|
|
- v18.17.0
|
2023-03-31 09:04:03 -04:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/47339
|
|
|
|
description: ICU requirement is removed.
|
2017-04-28 14:00:50 -07:00
|
|
|
-->
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* `domain` {string}
|
|
|
|
* Returns: {string}
|
|
|
|
|
|
|
|
Returns the [Punycode][] ASCII serialization of the `domain`. If `domain` is an
|
|
|
|
invalid domain, the empty string is returned.
|
|
|
|
|
|
|
|
It performs the inverse operation to [`url.domainToUnicode()`][].
|
|
|
|
|
2021-05-12 12:13:16 +02:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import url from 'node:url';
|
2021-05-12 12:13:16 +02:00
|
|
|
|
|
|
|
console.log(url.domainToASCII('español.com'));
|
|
|
|
// Prints xn--espaol-zwa.com
|
|
|
|
console.log(url.domainToASCII('中文.com'));
|
|
|
|
// Prints xn--fiq228c.com
|
|
|
|
console.log(url.domainToASCII('xn--iñvalid.com'));
|
|
|
|
// Prints an empty string
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const url = require('node:url');
|
2021-05-12 12:13:16 +02:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(url.domainToASCII('español.com'));
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints xn--espaol-zwa.com
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(url.domainToASCII('中文.com'));
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints xn--fiq228c.com
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(url.domainToASCII('xn--iñvalid.com'));
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints an empty string
|
2017-01-04 15:41:09 -08:00
|
|
|
```
|
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
### `url.domainToUnicode(domain)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2017-04-26 17:41:17 -07:00
|
|
|
<!-- YAML
|
2018-12-05 10:44:37 +01:00
|
|
|
added:
|
|
|
|
- v7.4.0
|
|
|
|
- v6.13.0
|
2023-03-31 09:04:03 -04:00
|
|
|
changes:
|
2023-07-10 08:12:52 -04:00
|
|
|
- version:
|
|
|
|
- v20.0.0
|
|
|
|
- v18.17.0
|
2023-03-31 09:04:03 -04:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/47339
|
|
|
|
description: ICU requirement is removed.
|
2017-04-26 17:41:17 -07:00
|
|
|
-->
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* `domain` {string}
|
|
|
|
* Returns: {string}
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
Returns the Unicode serialization of the `domain`. If `domain` is an invalid
|
|
|
|
domain, the empty string is returned.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
It performs the inverse operation to [`url.domainToASCII()`][].
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2021-05-12 12:13:16 +02:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import url from 'node:url';
|
2021-05-12 12:13:16 +02:00
|
|
|
|
|
|
|
console.log(url.domainToUnicode('xn--espaol-zwa.com'));
|
|
|
|
// Prints español.com
|
|
|
|
console.log(url.domainToUnicode('xn--fiq228c.com'));
|
|
|
|
// Prints 中文.com
|
|
|
|
console.log(url.domainToUnicode('xn--iñvalid.com'));
|
|
|
|
// Prints an empty string
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const url = require('node:url');
|
2021-05-12 12:13:16 +02:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(url.domainToUnicode('xn--espaol-zwa.com'));
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints español.com
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(url.domainToUnicode('xn--fiq228c.com'));
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints 中文.com
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(url.domainToUnicode('xn--iñvalid.com'));
|
2017-06-27 13:32:32 -07:00
|
|
|
// Prints an empty string
|
2017-01-28 12:02:35 -08:00
|
|
|
```
|
|
|
|
|
2024-04-24 11:47:48 -04:00
|
|
|
### `url.fileURLToPath(url[, options])`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2018-12-05 10:44:37 +01:00
|
|
|
<!-- YAML
|
|
|
|
added: v10.12.0
|
2024-04-24 11:47:48 -04:00
|
|
|
changes:
|
2024-05-02 11:31:36 +02:00
|
|
|
- version:
|
|
|
|
- v22.1.0
|
|
|
|
- v20.13.0
|
2024-04-24 11:47:48 -04:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/52509
|
|
|
|
description: The `options` argument can now be used to
|
|
|
|
determine how to parse the `path` argument.
|
2018-12-05 10:44:37 +01:00
|
|
|
-->
|
2018-08-24 18:13:32 +02:00
|
|
|
|
|
|
|
* `url` {URL | string} The file URL string or URL object to convert to a path.
|
2024-04-24 11:47:48 -04:00
|
|
|
* `options` {Object}
|
|
|
|
* `windows` {boolean|undefined} `true` if the `path` should be
|
|
|
|
return as a windows filepath, `false` for posix, and
|
|
|
|
`undefined` for the system default.
|
|
|
|
**Default:** `undefined`.
|
2018-08-24 18:13:32 +02:00
|
|
|
* Returns: {string} The fully-resolved platform-specific Node.js file path.
|
|
|
|
|
|
|
|
This function ensures the correct decodings of percent-encoded characters as
|
|
|
|
well as ensuring a cross-platform valid absolute path string.
|
|
|
|
|
2021-05-12 16:44:33 +08:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import { fileURLToPath } from 'node:url';
|
2021-05-12 16:44:33 +08:00
|
|
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
|
|
|
|
new URL('file:///C:/path/').pathname; // Incorrect: /C:/path/
|
|
|
|
fileURLToPath('file:///C:/path/'); // Correct: C:\path\ (Windows)
|
|
|
|
|
|
|
|
new URL('file://nas/foo.txt').pathname; // Incorrect: /foo.txt
|
|
|
|
fileURLToPath('file://nas/foo.txt'); // Correct: \\nas\foo.txt (Windows)
|
|
|
|
|
|
|
|
new URL('file:///你好.txt').pathname; // Incorrect: /%E4%BD%A0%E5%A5%BD.txt
|
|
|
|
fileURLToPath('file:///你好.txt'); // Correct: /你好.txt (POSIX)
|
|
|
|
|
|
|
|
new URL('file:///hello world').pathname; // Incorrect: /hello%20world
|
|
|
|
fileURLToPath('file:///hello world'); // Correct: /hello world (POSIX)
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const { fileURLToPath } = require('node:url');
|
2021-05-12 16:44:33 +08:00
|
|
|
new URL('file:///C:/path/').pathname; // Incorrect: /C:/path/
|
|
|
|
fileURLToPath('file:///C:/path/'); // Correct: C:\path\ (Windows)
|
2018-08-24 18:13:32 +02:00
|
|
|
|
2021-05-12 16:44:33 +08:00
|
|
|
new URL('file://nas/foo.txt').pathname; // Incorrect: /foo.txt
|
|
|
|
fileURLToPath('file://nas/foo.txt'); // Correct: \\nas\foo.txt (Windows)
|
2018-08-24 18:13:32 +02:00
|
|
|
|
2021-05-12 16:44:33 +08:00
|
|
|
new URL('file:///你好.txt').pathname; // Incorrect: /%E4%BD%A0%E5%A5%BD.txt
|
|
|
|
fileURLToPath('file:///你好.txt'); // Correct: /你好.txt (POSIX)
|
2018-08-24 18:13:32 +02:00
|
|
|
|
2021-05-12 16:44:33 +08:00
|
|
|
new URL('file:///hello world').pathname; // Incorrect: /hello%20world
|
|
|
|
fileURLToPath('file:///hello world'); // Correct: /hello world (POSIX)
|
2018-08-24 18:13:32 +02:00
|
|
|
```
|
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
### `url.format(URL[, options])`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2017-04-26 17:41:17 -07:00
|
|
|
<!-- YAML
|
2017-04-28 14:00:50 -07:00
|
|
|
added: v7.6.0
|
2017-04-26 17:41:17 -07:00
|
|
|
-->
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* `URL` {URL} A [WHATWG URL][] object
|
|
|
|
* `options` {Object}
|
|
|
|
* `auth` {boolean} `true` if the serialized URL string should include the
|
2018-04-02 04:44:32 +03:00
|
|
|
username and password, `false` otherwise. **Default:** `true`.
|
2017-04-28 14:00:50 -07:00
|
|
|
* `fragment` {boolean} `true` if the serialized URL string should include the
|
2018-04-02 04:44:32 +03:00
|
|
|
fragment, `false` otherwise. **Default:** `true`.
|
2017-04-28 14:00:50 -07:00
|
|
|
* `search` {boolean} `true` if the serialized URL string should include the
|
2018-04-02 04:44:32 +03:00
|
|
|
search query, `false` otherwise. **Default:** `true`.
|
2017-04-28 14:00:50 -07:00
|
|
|
* `unicode` {boolean} `true` if Unicode characters appearing in the host
|
|
|
|
component of the URL string should be encoded directly as opposed to being
|
2018-04-02 04:44:32 +03:00
|
|
|
Punycode encoded. **Default:** `false`.
|
2018-04-11 21:07:14 +03:00
|
|
|
* Returns: {string}
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2018-04-29 20:46:41 +03:00
|
|
|
Returns a customizable serialization of a URL `String` representation of a
|
2017-04-28 14:00:50 -07:00
|
|
|
[WHATWG URL][] object.
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The URL object has both a `toString()` method and `href` property that return
|
|
|
|
string serializations of the URL. These are not, however, customizable in
|
|
|
|
any way. The `url.format(URL[, options])` method allows for basic customization
|
|
|
|
of the output.
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2021-05-12 16:44:33 +08:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import url from 'node:url';
|
2021-05-12 16:44:33 +08:00
|
|
|
const myURL = new URL('https://a:b@測試?abc#foo');
|
|
|
|
|
|
|
|
console.log(myURL.href);
|
|
|
|
// Prints https://a:b@xn--g6w251d/?abc#foo
|
|
|
|
|
|
|
|
console.log(myURL.toString());
|
|
|
|
// Prints https://a:b@xn--g6w251d/?abc#foo
|
|
|
|
|
|
|
|
console.log(url.format(myURL, { fragment: false, unicode: true, auth: false }));
|
|
|
|
// Prints 'https://測試/?abc'
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const url = require('node:url');
|
2018-09-02 15:45:53 +03:00
|
|
|
const myURL = new URL('https://a:b@測試?abc#foo');
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(myURL.href);
|
2018-09-02 15:45:53 +03:00
|
|
|
// Prints https://a:b@xn--g6w251d/?abc#foo
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
console.log(myURL.toString());
|
2018-09-02 15:45:53 +03:00
|
|
|
// Prints https://a:b@xn--g6w251d/?abc#foo
|
2017-01-28 12:02:35 -08:00
|
|
|
|
2017-05-30 00:25:41 +03:00
|
|
|
console.log(url.format(myURL, { fragment: false, unicode: true, auth: false }));
|
2018-09-02 15:45:53 +03:00
|
|
|
// Prints 'https://測試/?abc'
|
2017-01-28 12:02:35 -08:00
|
|
|
```
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2024-04-24 11:47:48 -04:00
|
|
|
### `url.pathToFileURL(path[, options])`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2018-12-05 10:44:37 +01:00
|
|
|
<!-- YAML
|
|
|
|
added: v10.12.0
|
2024-04-24 11:47:48 -04:00
|
|
|
changes:
|
2024-05-02 11:31:36 +02:00
|
|
|
- version:
|
|
|
|
- v22.1.0
|
|
|
|
- v20.13.0
|
2024-04-24 11:47:48 -04:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/52509
|
|
|
|
description: The `options` argument can now be used to
|
|
|
|
determine how to return the `path` value.
|
2018-12-05 10:44:37 +01:00
|
|
|
-->
|
2018-08-24 18:13:32 +02:00
|
|
|
|
|
|
|
* `path` {string} The path to convert to a File URL.
|
2024-04-24 11:47:48 -04:00
|
|
|
* `options` {Object}
|
|
|
|
* `windows` {boolean|undefined} `true` if the `path` should be
|
|
|
|
treated as a windows filepath, `false` for posix, and
|
|
|
|
`undefined` for the system default.
|
|
|
|
**Default:** `undefined`.
|
2018-08-24 18:13:32 +02:00
|
|
|
* Returns: {URL} The file URL object.
|
|
|
|
|
|
|
|
This function ensures that `path` is resolved absolutely, and that the URL
|
|
|
|
control characters are correctly encoded when converting into a File URL.
|
|
|
|
|
2021-05-12 16:44:33 +08:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import { pathToFileURL } from 'node:url';
|
2021-05-12 16:44:33 +08:00
|
|
|
|
|
|
|
new URL('/foo#1', 'file:'); // Incorrect: file:///foo#1
|
|
|
|
pathToFileURL('/foo#1'); // Correct: file:///foo%231 (POSIX)
|
|
|
|
|
|
|
|
new URL('/some/path%.c', 'file:'); // Incorrect: file:///some/path%.c
|
|
|
|
pathToFileURL('/some/path%.c'); // Correct: file:///some/path%25.c (POSIX)
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const { pathToFileURL } = require('node:url');
|
2021-05-12 16:44:33 +08:00
|
|
|
new URL(__filename); // Incorrect: throws (POSIX)
|
|
|
|
new URL(__filename); // Incorrect: C:\... (Windows)
|
|
|
|
pathToFileURL(__filename); // Correct: file:///... (POSIX)
|
|
|
|
pathToFileURL(__filename); // Correct: file:///C:/... (Windows)
|
2018-08-24 18:13:32 +02:00
|
|
|
|
2021-05-12 16:44:33 +08:00
|
|
|
new URL('/foo#1', 'file:'); // Incorrect: file:///foo#1
|
|
|
|
pathToFileURL('/foo#1'); // Correct: file:///foo%231 (POSIX)
|
2018-08-24 18:13:32 +02:00
|
|
|
|
2021-05-12 16:44:33 +08:00
|
|
|
new URL('/some/path%.c', 'file:'); // Incorrect: file:///some/path%.c
|
|
|
|
pathToFileURL('/some/path%.c'); // Correct: file:///some/path%25.c (POSIX)
|
2018-08-24 18:13:32 +02:00
|
|
|
```
|
|
|
|
|
2021-01-06 16:10:28 +08:00
|
|
|
### `url.urlToHttpOptions(url)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2021-01-06 16:10:28 +08:00
|
|
|
<!-- YAML
|
2021-09-04 15:29:35 +02:00
|
|
|
added:
|
|
|
|
- v15.7.0
|
|
|
|
- v14.18.0
|
2023-03-19 04:25:35 +01:00
|
|
|
changes:
|
2023-07-10 08:12:52 -04:00
|
|
|
- version:
|
|
|
|
- v19.9.0
|
|
|
|
- v18.17.0
|
2023-03-19 04:25:35 +01:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/46989
|
|
|
|
description: The returned object will also contain all the own enumerable
|
|
|
|
properties of the `url` argument.
|
2021-01-06 16:10:28 +08:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `url` {URL} The [WHATWG URL][] object to convert to an options object.
|
|
|
|
* Returns: {Object} Options object
|
|
|
|
* `protocol` {string} Protocol to use.
|
|
|
|
* `hostname` {string} A domain name or IP address of the server to issue the
|
|
|
|
request to.
|
|
|
|
* `hash` {string} The fragment portion of the URL.
|
|
|
|
* `search` {string} The serialized query portion of the URL.
|
|
|
|
* `pathname` {string} The path portion of the URL.
|
|
|
|
* `path` {string} Request path. Should include query string if any.
|
|
|
|
E.G. `'/index.html?page=12'`. An exception is thrown when the request path
|
|
|
|
contains illegal characters. Currently, only spaces are rejected but that
|
|
|
|
may change in the future.
|
|
|
|
* `href` {string} The serialized URL.
|
|
|
|
* `port` {number} Port of remote server.
|
|
|
|
* `auth` {string} Basic authentication i.e. `'user:password'` to compute an
|
|
|
|
Authorization header.
|
|
|
|
|
|
|
|
This utility function converts a URL object into an ordinary options object as
|
|
|
|
expected by the [`http.request()`][] and [`https.request()`][] APIs.
|
|
|
|
|
2021-05-12 12:13:16 +02:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import { urlToHttpOptions } from 'node:url';
|
2021-05-12 12:13:16 +02:00
|
|
|
const myURL = new URL('https://a:b@測試?abc#foo');
|
|
|
|
|
2021-08-06 00:17:32 +08:00
|
|
|
console.log(urlToHttpOptions(myURL));
|
2021-12-07 06:35:08 -08:00
|
|
|
/*
|
2021-05-12 12:13:16 +02:00
|
|
|
{
|
|
|
|
protocol: 'https:',
|
|
|
|
hostname: 'xn--g6w251d',
|
|
|
|
hash: '#foo',
|
|
|
|
search: '?abc',
|
|
|
|
pathname: '/',
|
|
|
|
path: '/?abc',
|
|
|
|
href: 'https://a:b@xn--g6w251d/?abc#foo',
|
|
|
|
auth: 'a:b'
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const { urlToHttpOptions } = require('node:url');
|
2021-01-06 16:10:28 +08:00
|
|
|
const myURL = new URL('https://a:b@測試?abc#foo');
|
|
|
|
|
2023-03-08 16:34:55 +09:00
|
|
|
console.log(urlToHttpOptions(myURL));
|
2021-12-07 06:35:08 -08:00
|
|
|
/*
|
2021-01-06 16:10:28 +08:00
|
|
|
{
|
|
|
|
protocol: 'https:',
|
|
|
|
hostname: 'xn--g6w251d',
|
|
|
|
hash: '#foo',
|
|
|
|
search: '?abc',
|
|
|
|
pathname: '/',
|
|
|
|
path: '/?abc',
|
|
|
|
href: 'https://a:b@xn--g6w251d/?abc#foo',
|
|
|
|
auth: 'a:b'
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
```
|
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
## Legacy URL API
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2020-08-26 13:03:41 +02:00
|
|
|
<!-- YAML
|
2021-03-17 12:40:58 -07:00
|
|
|
changes:
|
2021-05-11, Version 14.17.0 'Fermium' (LTS)
Notable Changes:
Diagnostics channel (experimental module):
`diagnostics_channel` is a new experimental module that provides an API
to create named channels to report arbitrary message data for
diagnostics purposes.
The module was initially introduced in Node.js v15.1.0 and is
backported to v14.17.0 to enable testing it at a larger scale.
With `diagnostics_channel`, Node.js core and module authors can publish
contextual data about what they are doing at a given time. This could
be the hostname and query string of a mysql query, for example. Just
create a named channel with `dc.channel(name)` and call
`channel.publish(data)` to send the data to any listeners to that
channel.
```js
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
MySQL.prototype.query = function query(queryString, values, callback) {
// Broadcast query information whenever a query is made
channel.publish({
query: queryString,
host: this.hostname,
});
this.doQuery(queryString, values, callback);
};
```
Channels are like one big global event emitter but are split into
separate objects to ensure they get the best performance. If nothing is
listening to the channel, the publishing overhead should be as close to
zero as possible. Consuming channel data is as easy as using
`channel.subscribe(listener)` to run a function whenever a message is
published to that channel.
```js
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
channel.subscribe(({ query, host }) => {
console.log(`mysql query to ${host}: ${query}`);
});
```
The data captured can be used to provide context for what an app is
doing at a given time. This can be used for things like augmenting
tracing data, tracking network and filesystem activity, logging
queries, and many other things. It's also a very useful data source
for diagnostics tools to provide a clearer picture of exactly what the
application is doing at a given point in the data they are presenting.
Contributed by Stephen Belanger (https://github.com/nodejs/node/pull/34895).
UUID support in the crypto module:
The new `crypto.randomUUID()` method now allows to generate random
[RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) Version 4
UUID strings:
```js
const { randomUUID } = require('crypto');
console.log(randomUUID());
// 'aa7c91a1-f8fc-4339-b9db-f93fc7233429'
```
Contributed by James M Snell (https://github.com/nodejs/node/pull/36729).
Experimental support for `AbortController` and `AbortSignal`:
Node.js 14.17.0 adds experimental partial support for `AbortController`
and `AbortSignal`.
Both constructors can be enabled globally using the
`--experimental-abortcontroller` flag.
Additionally, several Node.js APIs have been updated to support
`AbortSignal` for cancellation.
It is not mandatory to use the built-in constructors with them. Any
spec-compliant third-party alternatives should be compatible.
`AbortSignal` support was added to the following methods:
* `child_process.exec`
* `child_process.execFile`
* `child_process.fork`
* `child_process.spawn`
* `dgram.createSocket`
* `events.on`
* `events.once`
* `fs.readFile`
* `fs.watch`
* `fs.writeFile`
* `http.request`
* `https.request`
* `http2Session.request`
* The promisified variants of `setImmediate` and `setTimeout`
Other notable changes:
* doc:
* revoke deprecation of legacy url, change status to legacy (James M Snell) (https://github.com/nodejs/node/pull/37784)
* add legacy status to stability index (James M Snell) (https://github.com/nodejs/node/pull/37784)
* upgrade stability status of report API (Gireesh Punathil) (https://github.com/nodejs/node/pull/35654)
* deps:
* V8: Backport various patches for Apple Silicon support (BoHong Li) (https://github.com/nodejs/node/pull/38051)
* update ICU to 68.1 (Michaël Zasso) (https://github.com/nodejs/node/pull/36187)
* upgrade to libuv 1.41.0 (Colin Ihrig) (https://github.com/nodejs/node/pull/37360)
* http:
* add http.ClientRequest.getRawHeaderNames() (simov) (https://github.com/nodejs/node/pull/37660)
* report request start and end with diagnostics\_channel (Stephen Belanger) (https://github.com/nodejs/node/pull/34895)
* util:
* add getSystemErrorMap() impl (eladkeyshawn) (https://github.com/nodejs/node/pull/38101)
PR-URL: https://github.com/nodejs/node/pull/38507
2021-05-02 23:12:18 -04:00
|
|
|
- version:
|
|
|
|
- v15.13.0
|
|
|
|
- v14.17.0
|
2021-03-17 12:40:58 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/37784
|
|
|
|
description: Deprecation revoked. Status changed to "Legacy".
|
|
|
|
- version: v11.0.0
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/22715
|
|
|
|
description: This API is deprecated.
|
2020-08-26 13:03:41 +02:00
|
|
|
-->
|
2018-09-05 11:33:20 -07:00
|
|
|
|
2021-03-17 12:40:58 -07:00
|
|
|
> Stability: 3 - Legacy: Use the WHATWG URL API instead.
|
|
|
|
|
2018-04-29 20:46:41 +03:00
|
|
|
### Legacy `urlObject`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2018-09-05 11:33:20 -07:00
|
|
|
<!-- YAML
|
|
|
|
changes:
|
2021-05-11, Version 14.17.0 'Fermium' (LTS)
Notable Changes:
Diagnostics channel (experimental module):
`diagnostics_channel` is a new experimental module that provides an API
to create named channels to report arbitrary message data for
diagnostics purposes.
The module was initially introduced in Node.js v15.1.0 and is
backported to v14.17.0 to enable testing it at a larger scale.
With `diagnostics_channel`, Node.js core and module authors can publish
contextual data about what they are doing at a given time. This could
be the hostname and query string of a mysql query, for example. Just
create a named channel with `dc.channel(name)` and call
`channel.publish(data)` to send the data to any listeners to that
channel.
```js
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
MySQL.prototype.query = function query(queryString, values, callback) {
// Broadcast query information whenever a query is made
channel.publish({
query: queryString,
host: this.hostname,
});
this.doQuery(queryString, values, callback);
};
```
Channels are like one big global event emitter but are split into
separate objects to ensure they get the best performance. If nothing is
listening to the channel, the publishing overhead should be as close to
zero as possible. Consuming channel data is as easy as using
`channel.subscribe(listener)` to run a function whenever a message is
published to that channel.
```js
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
channel.subscribe(({ query, host }) => {
console.log(`mysql query to ${host}: ${query}`);
});
```
The data captured can be used to provide context for what an app is
doing at a given time. This can be used for things like augmenting
tracing data, tracking network and filesystem activity, logging
queries, and many other things. It's also a very useful data source
for diagnostics tools to provide a clearer picture of exactly what the
application is doing at a given point in the data they are presenting.
Contributed by Stephen Belanger (https://github.com/nodejs/node/pull/34895).
UUID support in the crypto module:
The new `crypto.randomUUID()` method now allows to generate random
[RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) Version 4
UUID strings:
```js
const { randomUUID } = require('crypto');
console.log(randomUUID());
// 'aa7c91a1-f8fc-4339-b9db-f93fc7233429'
```
Contributed by James M Snell (https://github.com/nodejs/node/pull/36729).
Experimental support for `AbortController` and `AbortSignal`:
Node.js 14.17.0 adds experimental partial support for `AbortController`
and `AbortSignal`.
Both constructors can be enabled globally using the
`--experimental-abortcontroller` flag.
Additionally, several Node.js APIs have been updated to support
`AbortSignal` for cancellation.
It is not mandatory to use the built-in constructors with them. Any
spec-compliant third-party alternatives should be compatible.
`AbortSignal` support was added to the following methods:
* `child_process.exec`
* `child_process.execFile`
* `child_process.fork`
* `child_process.spawn`
* `dgram.createSocket`
* `events.on`
* `events.once`
* `fs.readFile`
* `fs.watch`
* `fs.writeFile`
* `http.request`
* `https.request`
* `http2Session.request`
* The promisified variants of `setImmediate` and `setTimeout`
Other notable changes:
* doc:
* revoke deprecation of legacy url, change status to legacy (James M Snell) (https://github.com/nodejs/node/pull/37784)
* add legacy status to stability index (James M Snell) (https://github.com/nodejs/node/pull/37784)
* upgrade stability status of report API (Gireesh Punathil) (https://github.com/nodejs/node/pull/35654)
* deps:
* V8: Backport various patches for Apple Silicon support (BoHong Li) (https://github.com/nodejs/node/pull/38051)
* update ICU to 68.1 (Michaël Zasso) (https://github.com/nodejs/node/pull/36187)
* upgrade to libuv 1.41.0 (Colin Ihrig) (https://github.com/nodejs/node/pull/37360)
* http:
* add http.ClientRequest.getRawHeaderNames() (simov) (https://github.com/nodejs/node/pull/37660)
* report request start and end with diagnostics\_channel (Stephen Belanger) (https://github.com/nodejs/node/pull/34895)
* util:
* add getSystemErrorMap() impl (eladkeyshawn) (https://github.com/nodejs/node/pull/38101)
PR-URL: https://github.com/nodejs/node/pull/38507
2021-05-02 23:12:18 -04:00
|
|
|
- version:
|
|
|
|
- v15.13.0
|
|
|
|
- v14.17.0
|
2021-03-17 12:40:58 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/37784
|
|
|
|
description: Deprecation revoked. Status changed to "Legacy".
|
2018-10-02 16:01:19 -07:00
|
|
|
- version: v11.0.0
|
2018-09-05 11:33:20 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/22715
|
|
|
|
description: The Legacy URL API is deprecated. Use the WHATWG URL API.
|
|
|
|
-->
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2022-04-20 10:23:41 +02:00
|
|
|
The legacy `urlObject` (`require('node:url').Url` or
|
|
|
|
`import { Url } from 'node:url'`) is
|
2021-05-12 12:13:16 +02:00
|
|
|
created and returned by the `url.parse()` function.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.auth`
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
The `auth` property is the username and password portion of the URL, also
|
2018-08-14 15:16:13 -07:00
|
|
|
referred to as _userinfo_. This string subset follows the `protocol` and
|
2018-08-14 15:20:40 -07:00
|
|
|
double slashes (if present) and precedes the `host` component, delimited by `@`.
|
|
|
|
The string is either the username, or it is the username and password separated
|
|
|
|
by `:`.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2018-04-29 14:16:44 +03:00
|
|
|
For example: `'user:pass'`.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.hash`
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2018-08-14 15:29:22 -07:00
|
|
|
The `hash` property is the fragment identifier portion of the URL including the
|
|
|
|
leading `#` character.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2018-04-29 14:16:44 +03:00
|
|
|
For example: `'#hash'`.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.host`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `host` property is the full lower-cased host portion of the URL, including
|
|
|
|
the `port` if specified.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2018-09-02 15:45:53 +03:00
|
|
|
For example: `'sub.example.com:8080'`.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.hostname`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `hostname` property is the lower-cased host name portion of the `host`
|
2021-10-10 21:55:04 -07:00
|
|
|
component _without_ the `port` included.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2018-09-02 15:45:53 +03:00
|
|
|
For example: `'sub.example.com'`.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.href`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `href` property is the full URL string that was parsed with both the
|
|
|
|
`protocol` and `host` components converted to lower-case.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2018-09-02 15:45:53 +03:00
|
|
|
For example: `'http://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash'`.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.path`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `path` property is a concatenation of the `pathname` and `search`
|
|
|
|
components.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2018-04-29 14:16:44 +03:00
|
|
|
For example: `'/p/a/t/h?query=string'`.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
No decoding of the `path` is performed.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.pathname`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `pathname` property consists of the entire path section of the URL. This
|
|
|
|
is everything following the `host` (including the `port`) and before the start
|
|
|
|
of the `query` or `hash` components, delimited by either the ASCII question
|
|
|
|
mark (`?`) or hash (`#`) characters.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2018-08-26 19:02:27 +03:00
|
|
|
For example: `'/p/a/t/h'`.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
No decoding of the path string is performed.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.port`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `port` property is the numeric port portion of the `host` component.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2018-04-29 14:16:44 +03:00
|
|
|
For example: `'8080'`.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.protocol`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `protocol` property identifies the URL's lower-cased protocol scheme.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2018-04-29 14:16:44 +03:00
|
|
|
For example: `'http:'`.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.query`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `query` property is either the query string without the leading ASCII
|
|
|
|
question mark (`?`), or an object returned by the [`querystring`][] module's
|
|
|
|
`parse()` method. Whether the `query` property is a string or object is
|
|
|
|
determined by the `parseQueryString` argument passed to `url.parse()`.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2018-04-29 14:16:44 +03:00
|
|
|
For example: `'query=string'` or `{'query': 'string'}`.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
If returned as a string, no decoding of the query string is performed. If
|
|
|
|
returned as an object, both keys and values are decoded.
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.search`
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `search` property consists of the entire "query string" portion of the
|
|
|
|
URL, including the leading ASCII question mark (`?`) character.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2018-04-29 14:16:44 +03:00
|
|
|
For example: `'?query=string'`.
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
No decoding of the query string is performed.
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
#### `urlObject.slashes`
|
2017-02-12 12:17:03 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `slashes` property is a `boolean` with a value of `true` if two ASCII
|
|
|
|
forward-slash characters (`/`) are required following the colon in the
|
|
|
|
`protocol`.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
### `url.format(urlObject)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2017-04-26 17:41:17 -07:00
|
|
|
<!-- YAML
|
2017-04-28 14:00:50 -07:00
|
|
|
added: v0.1.25
|
2017-07-30 20:15:16 +08:00
|
|
|
changes:
|
2021-10-19, Version 17.0.0 (Current)
Notable Changes:
Deprecations and Removals:
- (SEMVER-MAJOR) dns: runtime deprecate type coercion of `dns.lookup`
options
(Antoine du Hamel) [https://github.com/nodejs/node/pull/39793]
- doc: deprecate (doc-only) http abort related
(dr-js) [https://github.com/nodejs/node/pull/36670]
- (SEMVER-MAJOR) module: subpath folder mappings EOL
(Guy Bedford) [https://github.com/nodejs/node/pull/40121]
- (SEMVER-MAJOR) module: runtime deprecate trailing slash patterns
(Guy Bedford) [https://github.com/nodejs/node/pull/40117]
OpenSSL 3.0:
Node.js now includes OpenSSL 3.0, specifically https://github.com/quictls/openssl
which provides QUIC support.
While OpenSSL 3.0 APIs should be mostly compatible with those provided
by OpenSSL 1.1.1, we do anticipate some ecosystem impact due to
tightened restrictions on the allowed algorithms and key sizes.
If you hit an `ERR_OSSL_EVP_UNSUPPORTED` error in your application with
Node.js 17, it’s likely that your application or a module you’re using
is attempting to use an algorithm or key size which is no longer allowed
by default with OpenSSL 3.0. A command-line option,
`--openssl-legacy-provider`, has been added to revert to the legacy
provider as a temporary workaround for these tightened restrictions.
For details about all the features in
OpenSSL 3.0 please see https://www.openssl.org/blog/blog/2021/09/07/OpenSSL3.Final.
(Daniel Bevenius) [https://github.com/nodejs/node/pull/38512]
Contributed in https://github.com/nodejs/node/pull/38512, https://github.com/nodejs/node/pull/40478
V8 9.5:
The V8 JavaScript engine is updated to V8 9.5. This release comes with
additional supported types for the `Intl.DisplayNames` API and Extended
`timeZoneName` options in the `Intl.DateTimeFormat` API. You can read
more details in the V8 9.5 release post https://v8.dev/blog/v8-release-95.
(Michaël Zasso) [https://github.com/nodejs/node/pull/40178]
Readline Promise API:
The `readline` module provides an interface for reading data from a
Readable stream (such as `process.stdin`) one line at a time.
(Antoine du Hamel) [https://github.com/nodejs/node/pull/37947]
Other Notable Changes:
- (SEMVER-MAJOR) dns: default to verbatim=true in dns.lookup()
(treysis) [https://github.com/nodejs/node/pull/39987]
- (SEMVER-MAJOR) errors: print Node.js version on fatal exceptions that
cause exit
(Divlo) [https://github.com/nodejs/node/pull/38332]
- deps: upgrade npm to 8.1.0
(npm team) [https://github.com/nodejs/node/pull/40463]
- (SEMVER-MINOR) fs: add FileHandle.prototype.readableWebStream()
(James M Snell) [https://github.com/nodejs/node/pull/39331]
- (SEMVER-MAJOR) lib: add structuredClone() global
(Ethan Arrowood) [https://github.com/nodejs/node/pull/39759]
- (SEMVER-MAJOR) lib: expose `DOMException` as global
(Khaidi Chu) [https://github.com/nodejs/node/pull/39176]
- (SEMVER-MAJOR) stream: finished should error on errored stream
(Robert Nagy) [https://github.com/nodejs/node/pull/39235]
Semver-Major Commits:
- (SEMVER-MAJOR) build: compile with C++17 (MSVC)
(Richard Lau) [https://github.com/nodejs/node/pull/38807]
- (SEMVER-MAJOR) build: compile with --gnu++17
(Richard Lau) [https://github.com/nodejs/node/pull/38807]
- (SEMVER-MAJOR) deps: update V8 to 9.5.172.19
(Michaël Zasso) [https://github.com/nodejs/node/pull/40178]
- (SEMVER-MAJOR) deps,test,src,doc,tools: update to OpenSSL 3.0
(Daniel Bevenius) [https://github.com/nodejs/node/pull/38512]
- (SEMVER-MAJOR) dgram: tighten `address` validation in `socket.send`
(Voltrex) [https://github.com/nodejs/node/pull/39190]
- (SEMVER-MAJOR) dns: runtime deprecate type coercion of `dns.lookup` options
(Antoine du Hamel) [https://github.com/nodejs/node/pull/39793]
- (SEMVER-MAJOR) dns: default to verbatim=true in dns.lookup()
(treysis) [https://github.com/nodejs/node/pull/39987]
- (SEMVER-MAJOR) doc: update minimum supported FreeBSD to 12.2
(Michaël Zasso) [https://github.com/nodejs/node/pull/40179]
- (SEMVER-MAJOR) errors: disp ver on fatal except that causes exit
(Divlo) [https://github.com/nodejs/node/pull/38332]
- (SEMVER-MAJOR) fs: fix rmsync error swallowing
(Nitzan Uziely) [https://github.com/nodejs/node/pull/38684]
- (SEMVER-MAJOR) fs: aggregate errors in fsPromises to avoid error swallowing
(Nitzan Uziely) [https://github.com/nodejs/node/pull/38259]
- (SEMVER-MAJOR) lib: add structuredClone() global
(Ethan Arrowood) [https://github.com/nodejs/node/pull/39759]
- (SEMVER-MAJOR) lib: expose `DOMException` as global
(Khaidi Chu) [https://github.com/nodejs/node/pull/39176]
- (SEMVER-MAJOR) module: subpath folder mappings EOL
(Guy Bedford) [https://github.com/nodejs/node/pull/40121]
- (SEMVER-MAJOR) module: runtime deprecate trailing slash patterns
(Guy Bedford) [https://github.com/nodejs/node/pull/40117]
- (SEMVER-MAJOR) readline: validate `AbortSignal`s and remove unused event listeners
(Antoine du Hamel) [https://github.com/nodejs/node/pull/37947]
- (SEMVER-MAJOR) readline: introduce promise-based API
(Antoine du Hamel) [https://github.com/nodejs/node/pull/37947]
- (SEMVER-MAJOR) readline: refactor `Interface` to ES2015 class
(Antoine du Hamel) [https://github.com/nodejs/node/pull/37947]
- (SEMVER-MAJOR) src: allow CAP\_NET\_BIND\_SERVICE in SafeGetenv
(Daniel Bevenius) [https://github.com/nodejs/node/pull/37727]
- (SEMVER-MAJOR) src: return Maybe from a couple of functions
(Darshan Sen) [https://github.com/nodejs/node/pull/39603]
- (SEMVER-MAJOR) src: allow custom PageAllocator in NodePlatform
(Shelley Vohr) [https://github.com/nodejs/node/pull/38362]
- (SEMVER-MAJOR) stream: fix highwatermark threshold and add the missing error
(Rongjian Zhang) [https://github.com/nodejs/node/pull/38700]
- (SEMVER-MAJOR) stream: don't emit 'data' after 'error' or 'close'
(Robert Nagy) [https://github.com/nodejs/node/pull/39639]
- (SEMVER-MAJOR) stream: do not emit `end` on readable error
(Szymon Marczak) [https://github.com/nodejs/node/pull/39607]
- (SEMVER-MAJOR) stream: forward errored to callback
(Robert Nagy) [https://github.com/nodejs/node/pull/39364]
- (SEMVER-MAJOR) stream: destroy readable on read error
(Robert Nagy) [https://github.com/nodejs/node/pull/39342]
- (SEMVER-MAJOR) stream: validate abort signal
(Robert Nagy) [https://github.com/nodejs/node/pull/39346]
- (SEMVER-MAJOR) stream: unify stream utils
(Robert Nagy) [https://github.com/nodejs/node/pull/39294]
- (SEMVER-MAJOR) stream: throw on premature close in Readable\
(Darshan Sen) [https://github.com/nodejs/node/pull/39117]
- (SEMVER-MAJOR) stream: finished should error on errored stream
(Robert Nagy) [https://github.com/nodejs/node/pull/39235]
- (SEMVER-MAJOR) stream: error Duplex write/read if not writable/readable
(Robert Nagy) [https://github.com/nodejs/node/pull/34385]
- (SEMVER-MAJOR) stream: bypass legacy destroy for pipeline and async iteration
(Robert Nagy) [https://github.com/nodejs/node/pull/38505]
- (SEMVER-MAJOR) url: throw invalid this on detached accessors
(James M Snell) [https://github.com/nodejs/node/pull/39752]
- (SEMVER-MAJOR) url: forbid certain confusable changes from being introduced by toASCII
(Timothy Gu) [https://github.com/nodejs/node/pull/38631]
PR-URL: https://github.com/nodejs/node/pull/40119
2021-09-15 01:55:37 +01:00
|
|
|
- version: v17.0.0
|
2021-05-11 00:59:30 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/38631
|
|
|
|
description: Now throws an `ERR_INVALID_URL` exception when Punycode
|
|
|
|
conversion of a hostname introduces changes that could cause
|
|
|
|
the URL to be re-parsed differently.
|
2021-05-11, Version 14.17.0 'Fermium' (LTS)
Notable Changes:
Diagnostics channel (experimental module):
`diagnostics_channel` is a new experimental module that provides an API
to create named channels to report arbitrary message data for
diagnostics purposes.
The module was initially introduced in Node.js v15.1.0 and is
backported to v14.17.0 to enable testing it at a larger scale.
With `diagnostics_channel`, Node.js core and module authors can publish
contextual data about what they are doing at a given time. This could
be the hostname and query string of a mysql query, for example. Just
create a named channel with `dc.channel(name)` and call
`channel.publish(data)` to send the data to any listeners to that
channel.
```js
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
MySQL.prototype.query = function query(queryString, values, callback) {
// Broadcast query information whenever a query is made
channel.publish({
query: queryString,
host: this.hostname,
});
this.doQuery(queryString, values, callback);
};
```
Channels are like one big global event emitter but are split into
separate objects to ensure they get the best performance. If nothing is
listening to the channel, the publishing overhead should be as close to
zero as possible. Consuming channel data is as easy as using
`channel.subscribe(listener)` to run a function whenever a message is
published to that channel.
```js
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
channel.subscribe(({ query, host }) => {
console.log(`mysql query to ${host}: ${query}`);
});
```
The data captured can be used to provide context for what an app is
doing at a given time. This can be used for things like augmenting
tracing data, tracking network and filesystem activity, logging
queries, and many other things. It's also a very useful data source
for diagnostics tools to provide a clearer picture of exactly what the
application is doing at a given point in the data they are presenting.
Contributed by Stephen Belanger (https://github.com/nodejs/node/pull/34895).
UUID support in the crypto module:
The new `crypto.randomUUID()` method now allows to generate random
[RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) Version 4
UUID strings:
```js
const { randomUUID } = require('crypto');
console.log(randomUUID());
// 'aa7c91a1-f8fc-4339-b9db-f93fc7233429'
```
Contributed by James M Snell (https://github.com/nodejs/node/pull/36729).
Experimental support for `AbortController` and `AbortSignal`:
Node.js 14.17.0 adds experimental partial support for `AbortController`
and `AbortSignal`.
Both constructors can be enabled globally using the
`--experimental-abortcontroller` flag.
Additionally, several Node.js APIs have been updated to support
`AbortSignal` for cancellation.
It is not mandatory to use the built-in constructors with them. Any
spec-compliant third-party alternatives should be compatible.
`AbortSignal` support was added to the following methods:
* `child_process.exec`
* `child_process.execFile`
* `child_process.fork`
* `child_process.spawn`
* `dgram.createSocket`
* `events.on`
* `events.once`
* `fs.readFile`
* `fs.watch`
* `fs.writeFile`
* `http.request`
* `https.request`
* `http2Session.request`
* The promisified variants of `setImmediate` and `setTimeout`
Other notable changes:
* doc:
* revoke deprecation of legacy url, change status to legacy (James M Snell) (https://github.com/nodejs/node/pull/37784)
* add legacy status to stability index (James M Snell) (https://github.com/nodejs/node/pull/37784)
* upgrade stability status of report API (Gireesh Punathil) (https://github.com/nodejs/node/pull/35654)
* deps:
* V8: Backport various patches for Apple Silicon support (BoHong Li) (https://github.com/nodejs/node/pull/38051)
* update ICU to 68.1 (Michaël Zasso) (https://github.com/nodejs/node/pull/36187)
* upgrade to libuv 1.41.0 (Colin Ihrig) (https://github.com/nodejs/node/pull/37360)
* http:
* add http.ClientRequest.getRawHeaderNames() (simov) (https://github.com/nodejs/node/pull/37660)
* report request start and end with diagnostics\_channel (Stephen Belanger) (https://github.com/nodejs/node/pull/34895)
* util:
* add getSystemErrorMap() impl (eladkeyshawn) (https://github.com/nodejs/node/pull/38101)
PR-URL: https://github.com/nodejs/node/pull/38507
2021-05-02 23:12:18 -04:00
|
|
|
- version:
|
|
|
|
- v15.13.0
|
|
|
|
- v14.17.0
|
2021-03-17 12:40:58 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/37784
|
|
|
|
description: Deprecation revoked. Status changed to "Legacy".
|
2018-10-02 16:01:19 -07:00
|
|
|
- version: v11.0.0
|
2018-09-05 11:33:20 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/22715
|
|
|
|
description: The Legacy URL API is deprecated. Use the WHATWG URL API.
|
2017-07-30 20:15:16 +08:00
|
|
|
- version: v7.0.0
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/7234
|
|
|
|
description: URLs with a `file:` scheme will now always use the correct
|
2020-07-28 21:47:58 -07:00
|
|
|
number of slashes regardless of `slashes` option. A falsy
|
2017-07-30 20:15:16 +08:00
|
|
|
`slashes` option with no protocol is now also respected at all
|
|
|
|
times.
|
2017-04-26 17:41:17 -07:00
|
|
|
-->
|
2017-01-28 13:59:13 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* `urlObject` {Object|string} 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()`.
|
2017-01-28 13:59:13 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `url.format()` method returns a formatted URL string derived from
|
|
|
|
`urlObject`.
|
2017-01-28 13:59:13 -08:00
|
|
|
|
2018-02-20 12:10:54 -08:00
|
|
|
```js
|
2022-04-20 10:23:41 +02:00
|
|
|
const url = require('node:url');
|
2018-02-20 12:10:54 -08:00
|
|
|
url.format({
|
|
|
|
protocol: 'https',
|
|
|
|
hostname: 'example.com',
|
|
|
|
pathname: '/some/path',
|
|
|
|
query: {
|
|
|
|
page: 1,
|
2022-11-17 08:19:12 -05:00
|
|
|
format: 'json',
|
|
|
|
},
|
2018-02-20 12:10:54 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
// => 'https://example.com/some/path?page=1&format=json'
|
|
|
|
```
|
|
|
|
|
2017-11-25 11:35:42 +01:00
|
|
|
If `urlObject` is not an object or a string, `url.format()` will throw a
|
2017-04-28 14:00:50 -07:00
|
|
|
[`TypeError`][].
|
2017-01-28 13:59:13 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The formatting process operates as follows:
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* A new empty string `result` is created.
|
|
|
|
* If `urlObject.protocol` is a string, it is appended as-is to `result`.
|
|
|
|
* Otherwise, if `urlObject.protocol` is not `undefined` and is not a string, an
|
|
|
|
[`Error`][] is thrown.
|
2021-10-10 21:55:04 -07:00
|
|
|
* For all string values of `urlObject.protocol` that _do not end_ with an ASCII
|
2017-04-28 14:00:50 -07:00
|
|
|
colon (`:`) character, the literal string `:` will be appended to `result`.
|
|
|
|
* If either of the following conditions is true, then the literal string `//`
|
|
|
|
will be appended to `result`:
|
2019-09-01 02:18:32 -04:00
|
|
|
* `urlObject.slashes` property is true;
|
|
|
|
* `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or
|
|
|
|
`file`;
|
2017-04-28 14:00:50 -07:00
|
|
|
* 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 and appended to `result`
|
2021-10-10 21:55:04 -07:00
|
|
|
followed by the literal string `@`.
|
2017-04-28 14:00:50 -07:00
|
|
|
* If the `urlObject.host` property is `undefined` then:
|
|
|
|
* If the `urlObject.hostname` is a string, it is appended to `result`.
|
|
|
|
* Otherwise, if `urlObject.hostname` is not `undefined` and is not a string,
|
|
|
|
an [`Error`][] is thrown.
|
|
|
|
* If the `urlObject.port` property value is truthy, and `urlObject.hostname`
|
|
|
|
is not `undefined`:
|
|
|
|
* The literal string `:` is appended to `result`, and
|
|
|
|
* The value of `urlObject.port` is coerced to a string and appended to
|
|
|
|
`result`.
|
|
|
|
* Otherwise, if the `urlObject.host` property value is truthy, the value of
|
|
|
|
`urlObject.host` is coerced to a string and appended to `result`.
|
|
|
|
* If the `urlObject.pathname` property is a string that is not an empty string:
|
2021-10-10 21:55:04 -07:00
|
|
|
* If the `urlObject.pathname` _does not start_ with an ASCII forward slash
|
2018-04-29 20:46:41 +03:00
|
|
|
(`/`), then the literal string `'/'` is appended to `result`.
|
2017-04-28 14:00:50 -07:00
|
|
|
* The value of `urlObject.pathname` is appended to `result`.
|
|
|
|
* Otherwise, if `urlObject.pathname` is not `undefined` and is not a string, an
|
|
|
|
[`Error`][] is thrown.
|
|
|
|
* 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 [`querystring`][] module's `stringify()`
|
|
|
|
method passing the value of `urlObject.query`.
|
|
|
|
* Otherwise, if `urlObject.search` is a string:
|
2021-10-10 21:55:04 -07:00
|
|
|
* If the value of `urlObject.search` _does not start_ with the ASCII question
|
2017-04-28 14:00:50 -07:00
|
|
|
mark (`?`) character, the literal string `?` is appended to `result`.
|
|
|
|
* The value of `urlObject.search` is appended to `result`.
|
|
|
|
* Otherwise, if `urlObject.search` is not `undefined` and is not a string, an
|
|
|
|
[`Error`][] is thrown.
|
|
|
|
* If the `urlObject.hash` property is a string:
|
2021-10-10 21:55:04 -07:00
|
|
|
* If the value of `urlObject.hash` _does not start_ with the ASCII hash (`#`)
|
2017-04-28 14:00:50 -07:00
|
|
|
character, the literal string `#` is appended to `result`.
|
|
|
|
* The value of `urlObject.hash` is appended to `result`.
|
|
|
|
* Otherwise, if the `urlObject.hash` property is not `undefined` and is not a
|
|
|
|
string, an [`Error`][] is thrown.
|
|
|
|
* `result` is returned.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
### `url.parse(urlString[, parseQueryString[, slashesDenoteHost]])`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.1.25
|
2018-02-09 14:14:28 -05:00
|
|
|
changes:
|
2023-01-05, Version 18.13.0 'Hydrogen' (LTS)
Notable changes:
Add support for externally shared js builtins:
By default Node.js is built so that all dependencies are bundled into the
Node.js binary itself. Some Node.js distributions prefer to manage dependencies
externally. There are existing build options that allow dependencies with
native code to be externalized. This commit adds additional options so that
dependencies with JavaScript code (including WASM) can also be externalized.
This addition does not affect binaries shipped by the Node.js project but
will allow other distributions to externalize additional dependencies when
needed.
Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376
Introduce `File`:
The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/).
It can be used anywhere a Blob can, for example in `URL.createObjectURL`
and `FormData`. It contains two properties that Blobs do not have: `lastModified`,
the last time the file was modified in ms, and `name`, the name of the file.
Contributed by Khafra in https://github.com/nodejs/node/pull/45139
Support function mocking on Node.js test runner:
The `node:test` module supports mocking during testing via a top-level `mock`
object.
```js
test('spies on an object method', (t) => {
const number = {
value: 5,
add(a) {
return this.value + a;
},
};
t.mock.method(number, 'add');
assert.strictEqual(number.add(3), 8);
assert.strictEqual(number.add.mock.calls.length, 1);
});
```
Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326
Other notable changes:
build:
* disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716
crypto:
* update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490
deps:
* update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068
doc:
* add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697
* add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691
* deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576
* add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180
* add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002
* deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919
lib:
* drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287
net:
* (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731
* src:
* (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639
* (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869
test_runner:
* (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792
* (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792
tls:
* (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935
* remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776
tools:
* update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490
util:
* add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412
* improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294
* (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128
PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
|
|
|
- version:
|
|
|
|
- v19.0.0
|
|
|
|
- v18.13.0
|
2022-10-11 15:35:52 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/44919
|
|
|
|
description: Documentation-only deprecation.
|
2021-05-11, Version 14.17.0 'Fermium' (LTS)
Notable Changes:
Diagnostics channel (experimental module):
`diagnostics_channel` is a new experimental module that provides an API
to create named channels to report arbitrary message data for
diagnostics purposes.
The module was initially introduced in Node.js v15.1.0 and is
backported to v14.17.0 to enable testing it at a larger scale.
With `diagnostics_channel`, Node.js core and module authors can publish
contextual data about what they are doing at a given time. This could
be the hostname and query string of a mysql query, for example. Just
create a named channel with `dc.channel(name)` and call
`channel.publish(data)` to send the data to any listeners to that
channel.
```js
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
MySQL.prototype.query = function query(queryString, values, callback) {
// Broadcast query information whenever a query is made
channel.publish({
query: queryString,
host: this.hostname,
});
this.doQuery(queryString, values, callback);
};
```
Channels are like one big global event emitter but are split into
separate objects to ensure they get the best performance. If nothing is
listening to the channel, the publishing overhead should be as close to
zero as possible. Consuming channel data is as easy as using
`channel.subscribe(listener)` to run a function whenever a message is
published to that channel.
```js
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
channel.subscribe(({ query, host }) => {
console.log(`mysql query to ${host}: ${query}`);
});
```
The data captured can be used to provide context for what an app is
doing at a given time. This can be used for things like augmenting
tracing data, tracking network and filesystem activity, logging
queries, and many other things. It's also a very useful data source
for diagnostics tools to provide a clearer picture of exactly what the
application is doing at a given point in the data they are presenting.
Contributed by Stephen Belanger (https://github.com/nodejs/node/pull/34895).
UUID support in the crypto module:
The new `crypto.randomUUID()` method now allows to generate random
[RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) Version 4
UUID strings:
```js
const { randomUUID } = require('crypto');
console.log(randomUUID());
// 'aa7c91a1-f8fc-4339-b9db-f93fc7233429'
```
Contributed by James M Snell (https://github.com/nodejs/node/pull/36729).
Experimental support for `AbortController` and `AbortSignal`:
Node.js 14.17.0 adds experimental partial support for `AbortController`
and `AbortSignal`.
Both constructors can be enabled globally using the
`--experimental-abortcontroller` flag.
Additionally, several Node.js APIs have been updated to support
`AbortSignal` for cancellation.
It is not mandatory to use the built-in constructors with them. Any
spec-compliant third-party alternatives should be compatible.
`AbortSignal` support was added to the following methods:
* `child_process.exec`
* `child_process.execFile`
* `child_process.fork`
* `child_process.spawn`
* `dgram.createSocket`
* `events.on`
* `events.once`
* `fs.readFile`
* `fs.watch`
* `fs.writeFile`
* `http.request`
* `https.request`
* `http2Session.request`
* The promisified variants of `setImmediate` and `setTimeout`
Other notable changes:
* doc:
* revoke deprecation of legacy url, change status to legacy (James M Snell) (https://github.com/nodejs/node/pull/37784)
* add legacy status to stability index (James M Snell) (https://github.com/nodejs/node/pull/37784)
* upgrade stability status of report API (Gireesh Punathil) (https://github.com/nodejs/node/pull/35654)
* deps:
* V8: Backport various patches for Apple Silicon support (BoHong Li) (https://github.com/nodejs/node/pull/38051)
* update ICU to 68.1 (Michaël Zasso) (https://github.com/nodejs/node/pull/36187)
* upgrade to libuv 1.41.0 (Colin Ihrig) (https://github.com/nodejs/node/pull/37360)
* http:
* add http.ClientRequest.getRawHeaderNames() (simov) (https://github.com/nodejs/node/pull/37660)
* report request start and end with diagnostics\_channel (Stephen Belanger) (https://github.com/nodejs/node/pull/34895)
* util:
* add getSystemErrorMap() impl (eladkeyshawn) (https://github.com/nodejs/node/pull/38101)
PR-URL: https://github.com/nodejs/node/pull/38507
2021-05-02 23:12:18 -04:00
|
|
|
- version:
|
|
|
|
- v15.13.0
|
|
|
|
- v14.17.0
|
2021-03-17 12:40:58 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/37784
|
|
|
|
description: Deprecation revoked. Status changed to "Legacy".
|
2019-11-10 09:10:14 +01:00
|
|
|
- version: v11.14.0
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/26941
|
|
|
|
description: The `pathname` property on the returned URL object is now `/`
|
|
|
|
when there is no path and the protocol scheme is `ws:` or
|
|
|
|
`wss:`.
|
2018-10-02 16:01:19 -07:00
|
|
|
- version: v11.0.0
|
2018-09-05 11:33:20 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/22715
|
|
|
|
description: The Legacy URL API is deprecated. Use the WHATWG URL API.
|
2018-02-09 14:14:28 -05:00
|
|
|
- version: v9.0.0
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/13606
|
|
|
|
description: The `search` property on the returned URL object is now `null`
|
|
|
|
when no query string is present.
|
2017-04-28 14:00:50 -07:00
|
|
|
-->
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2022-10-11 15:35:52 -07:00
|
|
|
> Stability: 0 - Deprecated: Use the WHATWG URL API instead.
|
2020-08-26 13:03:41 +02:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
* `urlString` {string} The URL string to parse.
|
|
|
|
* `parseQueryString` {boolean} If `true`, the `query` property will always
|
|
|
|
be set to an object returned by the [`querystring`][] module's `parse()`
|
|
|
|
method. If `false`, the `query` property on the returned URL object will be an
|
2018-04-02 04:44:32 +03:00
|
|
|
unparsed, undecoded string. **Default:** `false`.
|
2017-04-28 14:00:50 -07:00
|
|
|
* `slashesDenoteHost` {boolean} 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 result would be
|
|
|
|
`{host: 'foo', pathname: '/bar'}` rather than `{pathname: '//foo/bar'}`.
|
2018-04-02 04:44:32 +03:00
|
|
|
**Default:** `false`.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
The `url.parse()` method takes a URL string, parses it, and returns a URL
|
|
|
|
object.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
A `TypeError` is thrown if `urlString` is not a string.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
A `URIError` is thrown if the `auth` property is present but cannot be decoded.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2022-03-14 10:40:08 +05:30
|
|
|
`url.parse()` uses a lenient, non-standard algorithm for parsing URL
|
|
|
|
strings. It is prone to security issues such as [host name spoofing][]
|
2022-10-11 15:35:52 -07:00
|
|
|
and incorrect handling of usernames and passwords. Do not use with untrusted
|
|
|
|
input. CVEs are not issued for `url.parse()` vulnerabilities. Use the
|
|
|
|
[WHATWG URL][] API instead.
|
2020-07-06 12:59:12 -07:00
|
|
|
|
2019-12-24 15:21:27 -08:00
|
|
|
### `url.resolve(from, to)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2017-04-28 14:00:50 -07:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.1.25
|
|
|
|
changes:
|
2021-05-11, Version 14.17.0 'Fermium' (LTS)
Notable Changes:
Diagnostics channel (experimental module):
`diagnostics_channel` is a new experimental module that provides an API
to create named channels to report arbitrary message data for
diagnostics purposes.
The module was initially introduced in Node.js v15.1.0 and is
backported to v14.17.0 to enable testing it at a larger scale.
With `diagnostics_channel`, Node.js core and module authors can publish
contextual data about what they are doing at a given time. This could
be the hostname and query string of a mysql query, for example. Just
create a named channel with `dc.channel(name)` and call
`channel.publish(data)` to send the data to any listeners to that
channel.
```js
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
MySQL.prototype.query = function query(queryString, values, callback) {
// Broadcast query information whenever a query is made
channel.publish({
query: queryString,
host: this.hostname,
});
this.doQuery(queryString, values, callback);
};
```
Channels are like one big global event emitter but are split into
separate objects to ensure they get the best performance. If nothing is
listening to the channel, the publishing overhead should be as close to
zero as possible. Consuming channel data is as easy as using
`channel.subscribe(listener)` to run a function whenever a message is
published to that channel.
```js
const dc = require('diagnostics_channel');
const channel = dc.channel('mysql.query');
channel.subscribe(({ query, host }) => {
console.log(`mysql query to ${host}: ${query}`);
});
```
The data captured can be used to provide context for what an app is
doing at a given time. This can be used for things like augmenting
tracing data, tracking network and filesystem activity, logging
queries, and many other things. It's also a very useful data source
for diagnostics tools to provide a clearer picture of exactly what the
application is doing at a given point in the data they are presenting.
Contributed by Stephen Belanger (https://github.com/nodejs/node/pull/34895).
UUID support in the crypto module:
The new `crypto.randomUUID()` method now allows to generate random
[RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) Version 4
UUID strings:
```js
const { randomUUID } = require('crypto');
console.log(randomUUID());
// 'aa7c91a1-f8fc-4339-b9db-f93fc7233429'
```
Contributed by James M Snell (https://github.com/nodejs/node/pull/36729).
Experimental support for `AbortController` and `AbortSignal`:
Node.js 14.17.0 adds experimental partial support for `AbortController`
and `AbortSignal`.
Both constructors can be enabled globally using the
`--experimental-abortcontroller` flag.
Additionally, several Node.js APIs have been updated to support
`AbortSignal` for cancellation.
It is not mandatory to use the built-in constructors with them. Any
spec-compliant third-party alternatives should be compatible.
`AbortSignal` support was added to the following methods:
* `child_process.exec`
* `child_process.execFile`
* `child_process.fork`
* `child_process.spawn`
* `dgram.createSocket`
* `events.on`
* `events.once`
* `fs.readFile`
* `fs.watch`
* `fs.writeFile`
* `http.request`
* `https.request`
* `http2Session.request`
* The promisified variants of `setImmediate` and `setTimeout`
Other notable changes:
* doc:
* revoke deprecation of legacy url, change status to legacy (James M Snell) (https://github.com/nodejs/node/pull/37784)
* add legacy status to stability index (James M Snell) (https://github.com/nodejs/node/pull/37784)
* upgrade stability status of report API (Gireesh Punathil) (https://github.com/nodejs/node/pull/35654)
* deps:
* V8: Backport various patches for Apple Silicon support (BoHong Li) (https://github.com/nodejs/node/pull/38051)
* update ICU to 68.1 (Michaël Zasso) (https://github.com/nodejs/node/pull/36187)
* upgrade to libuv 1.41.0 (Colin Ihrig) (https://github.com/nodejs/node/pull/37360)
* http:
* add http.ClientRequest.getRawHeaderNames() (simov) (https://github.com/nodejs/node/pull/37660)
* report request start and end with diagnostics\_channel (Stephen Belanger) (https://github.com/nodejs/node/pull/34895)
* util:
* add getSystemErrorMap() impl (eladkeyshawn) (https://github.com/nodejs/node/pull/38101)
PR-URL: https://github.com/nodejs/node/pull/38507
2021-05-02 23:12:18 -04:00
|
|
|
- version:
|
|
|
|
- v15.13.0
|
|
|
|
- v14.17.0
|
2021-03-17 12:40:58 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/37784
|
|
|
|
description: Deprecation revoked. Status changed to "Legacy".
|
2018-10-02 16:01:19 -07:00
|
|
|
- version: v11.0.0
|
2018-09-05 11:33:20 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/22715
|
|
|
|
description: The Legacy URL API is deprecated. Use the WHATWG URL API.
|
2017-04-28 14:00:50 -07:00
|
|
|
- version: v6.6.0
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/8215
|
|
|
|
description: The `auth` fields are now kept intact when `from` and `to`
|
|
|
|
refer to the same host.
|
2020-10-01 20:23:33 +02:00
|
|
|
- version:
|
|
|
|
- v6.5.0
|
|
|
|
- v4.6.2
|
2017-04-28 14:00:50 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/8214
|
|
|
|
description: The `port` field is copied correctly now.
|
|
|
|
- version: v6.0.0
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/1480
|
|
|
|
description: The `auth` fields is cleared now the `to` parameter
|
|
|
|
contains a hostname.
|
|
|
|
-->
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2022-01-24 19:43:55 -08:00
|
|
|
* `from` {string} The base URL to use if `to` is a relative URL.
|
|
|
|
* `to` {string} The target URL to resolve.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
|
|
|
The `url.resolve()` method resolves a target URL relative to a base URL in a
|
2022-01-24 19:43:55 -08:00
|
|
|
manner similar to that of a web browser resolving an anchor tag.
|
2017-04-28 14:00:50 -07:00
|
|
|
|
2017-02-12 12:17:03 -08:00
|
|
|
```js
|
2022-04-20 10:23:41 +02:00
|
|
|
const url = require('node:url');
|
2017-04-28 14:00:50 -07:00
|
|
|
url.resolve('/one/two/three', 'four'); // '/one/two/four'
|
|
|
|
url.resolve('http://example.com/', '/one'); // 'http://example.com/one'
|
|
|
|
url.resolve('http://example.com/one', '/two'); // 'http://example.com/two'
|
2021-02-24 13:53:59 +01:00
|
|
|
```
|
|
|
|
|
2022-01-24 19:43:55 -08:00
|
|
|
To achieve the same result using the WHATWG URL API:
|
2021-02-24 13:53:59 +01:00
|
|
|
|
|
|
|
```js
|
|
|
|
function resolve(from, to) {
|
|
|
|
const resolvedUrl = new URL(to, new URL(from, 'resolve://'));
|
|
|
|
if (resolvedUrl.protocol === 'resolve:') {
|
|
|
|
// `from` is a relative URL.
|
|
|
|
const { pathname, search, hash } = resolvedUrl;
|
|
|
|
return pathname + search + hash;
|
|
|
|
}
|
|
|
|
return resolvedUrl.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve('/one/two/three', 'four'); // '/one/two/four'
|
|
|
|
resolve('http://example.com/', '/one'); // 'http://example.com/one'
|
|
|
|
resolve('http://example.com/one', '/two'); // 'http://example.com/two'
|
2017-02-12 12:17:03 -08:00
|
|
|
```
|
2017-01-04 15:41:09 -08:00
|
|
|
|
|
|
|
<a id="whatwg-percent-encoding"></a>
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2020-06-14 14:49:34 -07:00
|
|
|
## Percent-encoding in URLs
|
2017-01-04 15:41:09 -08:00
|
|
|
|
|
|
|
URLs are permitted to only contain a certain range of characters. Any character
|
|
|
|
falling outside of that range must be encoded. How such characters are encoded,
|
|
|
|
and which characters to encode depends entirely on where the character is
|
2017-04-28 14:00:50 -07:00
|
|
|
located within the structure of the URL.
|
|
|
|
|
|
|
|
### Legacy API
|
|
|
|
|
|
|
|
Within the Legacy API, spaces (`' '`) and the following characters will be
|
|
|
|
automatically escaped in the properties of URL objects:
|
|
|
|
|
2020-04-23 11:01:52 -07:00
|
|
|
```text
|
2017-04-28 14:00:50 -07:00
|
|
|
< > " ` \r \n \t { } | \ ^ '
|
|
|
|
```
|
|
|
|
|
|
|
|
For example, the ASCII space character (`' '`) is encoded as `%20`. The ASCII
|
|
|
|
forward slash (`/`) character is encoded as `%3C`.
|
|
|
|
|
|
|
|
### WHATWG API
|
|
|
|
|
|
|
|
The [WHATWG URL Standard][] uses a more selective and fine grained approach to
|
|
|
|
selecting encoded characters than that used by the Legacy API.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2017-12-08 14:07:14 -08:00
|
|
|
The WHATWG algorithm defines four "percent-encode sets" that describe ranges
|
2017-04-19 11:34:35 -07:00
|
|
|
of characters that must be percent-encoded:
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2021-10-10 21:55:04 -07:00
|
|
|
* The _C0 control percent-encode set_ includes code points in range U+0000 to
|
2023-08-23 10:13:46 +09:00
|
|
|
U+001F (inclusive) and all code points greater than U+007E (\~).
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2021-10-10 21:55:04 -07:00
|
|
|
* The _fragment percent-encode set_ includes the _C0 control percent-encode set_
|
2023-08-23 10:13:46 +09:00
|
|
|
and code points U+0020 SPACE, U+0022 ("), U+003C (<), U+003E (>),
|
|
|
|
and U+0060 (\`).
|
2017-12-08 14:07:14 -08:00
|
|
|
|
2021-10-10 21:55:04 -07:00
|
|
|
* The _path percent-encode set_ includes the _C0 control percent-encode set_
|
2023-08-23 10:13:46 +09:00
|
|
|
and code points U+0020 SPACE, U+0022 ("), U+0023 (#), U+003C (<), U+003E (>),
|
|
|
|
U+003F (?), U+0060 (\`), U+007B ({), and U+007D (}).
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2021-10-10 21:55:04 -07:00
|
|
|
* The _userinfo encode set_ includes the _path percent-encode set_ and code
|
2023-08-23 10:13:46 +09:00
|
|
|
points U+002F (/), U+003A (:), U+003B (;), U+003D (=), U+0040 (@),
|
|
|
|
U+005B (\[) to U+005E(^), and U+007C (|).
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2021-10-10 21:55:04 -07:00
|
|
|
The _userinfo percent-encode set_ is used exclusively for username and
|
|
|
|
passwords encoded within the URL. The _path percent-encode set_ is used for the
|
|
|
|
path of most URLs. The _fragment percent-encode set_ is used for URL fragments.
|
|
|
|
The _C0 control percent-encode set_ is used for host and path under certain
|
2017-12-08 14:07:14 -08:00
|
|
|
specific conditions, in addition to all other cases.
|
2017-01-04 15:41:09 -08:00
|
|
|
|
2020-01-12 08:09:26 -08:00
|
|
|
When non-ASCII characters appear within a host name, the host name is encoded
|
2021-10-10 21:55:04 -07:00
|
|
|
using the [Punycode][] algorithm. Note, however, that a host name _may_ contain
|
|
|
|
_both_ Punycode encoded and percent-encoded characters:
|
2017-01-04 15:41:09 -08:00
|
|
|
|
|
|
|
```js
|
2018-09-02 15:45:53 +03:00
|
|
|
const myURL = new URL('https://%CF%80.example.com/foo');
|
2017-01-04 15:41:09 -08:00
|
|
|
console.log(myURL.href);
|
2018-09-02 15:45:53 +03:00
|
|
|
// Prints https://xn--1xa.example.com/foo
|
2017-01-04 15:41:09 -08:00
|
|
|
console.log(myURL.origin);
|
2018-10-10 03:05:16 +03:00
|
|
|
// Prints https://xn--1xa.example.com
|
2017-01-04 15:41:09 -08:00
|
|
|
```
|
|
|
|
|
2020-09-17 18:53:37 +02:00
|
|
|
[Punycode]: https://tools.ietf.org/html/rfc5891#section-4.4
|
2021-07-04 20:39:17 -07:00
|
|
|
[WHATWG URL]: #the-whatwg-url-api
|
2021-06-27 14:25:47 +02:00
|
|
|
[WHATWG URL Standard]: https://url.spec.whatwg.org/
|
2021-07-04 20:39:17 -07:00
|
|
|
[`Error`]: errors.md#class-error
|
2018-02-07 23:55:37 +02:00
|
|
|
[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
|
2021-07-04 20:39:17 -07:00
|
|
|
[`TypeError`]: errors.md#class-typeerror
|
|
|
|
[`URLSearchParams`]: #class-urlsearchparams
|
2017-05-08 09:30:13 -07:00
|
|
|
[`array.toString()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString
|
2021-07-04 20:39:17 -07:00
|
|
|
[`http.request()`]: http.md#httprequestoptions-callback
|
|
|
|
[`https.request()`]: https.md#httpsrequestoptions-callback
|
|
|
|
[`new URL()`]: #new-urlinput-base
|
2020-09-14 17:09:13 +02:00
|
|
|
[`querystring`]: querystring.md
|
2021-07-04 20:39:17 -07:00
|
|
|
[`url.domainToASCII()`]: #urldomaintoasciidomain
|
|
|
|
[`url.domainToUnicode()`]: #urldomaintounicodedomain
|
|
|
|
[`url.format()`]: #urlformaturlobject
|
|
|
|
[`url.href`]: #urlhref
|
|
|
|
[`url.parse()`]: #urlparseurlstring-parsequerystring-slashesdenotehost
|
|
|
|
[`url.search`]: #urlsearch
|
|
|
|
[`url.toJSON()`]: #urltojson
|
|
|
|
[`url.toString()`]: #urltostring
|
|
|
|
[`urlSearchParams.entries()`]: #urlsearchparamsentries
|
|
|
|
[`urlSearchParams@@iterator()`]: #urlsearchparamssymboliterator
|
2022-01-24 18:04:22 -08:00
|
|
|
[converted to a string]: https://tc39.es/ecma262/#sec-tostring
|
2017-05-08 09:30:13 -07:00
|
|
|
[examples of parsed URLs]: https://url.spec.whatwg.org/#example-url-parsing
|
2020-07-06 12:59:12 -07:00
|
|
|
[host name spoofing]: https://hackerone.com/reports/678487
|
2021-07-04 20:39:17 -07:00
|
|
|
[legacy `urlObject`]: #legacy-urlobject
|
|
|
|
[percent-encoded]: #percent-encoding-in-urls
|
2017-01-28 13:59:13 -08:00
|
|
|
[stable sorting algorithm]: https://en.wikipedia.org/wiki/Sorting_algorithm#Stability
|