Hàm tạo mô-đun javascript

Chuỗi URL là một chuỗi có cấu trúc chứa nhiều thành phần có nghĩa. Khi được phân tích cú pháp, một đối tượng URL được trả về có chứa các thuộc tính cho từng thành phần này

Mô-đun

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
55 cung cấp hai API để làm việc với các URL. một API kế thừa là Node. js cụ thể và một API mới hơn triển khai cùng một Tiêu chuẩn URL WHATWG được trình duyệt web sử dụng

So sánh giữa WHATWG và API kế thừa được cung cấp bên dưới. Phía trên URL

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
56, các thuộc tính của một đối tượng được trả về bởi
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
0 kế thừa được hiển thị. Bên dưới nó là các thuộc tính của đối tượng WHATWG
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1

Thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
2 của URL WHATWG bao gồm
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
3 và
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
4, nhưng không bao gồm
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
5 hoặc
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
6

┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                              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                                              │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)

Phân tích cú pháp chuỗi URL bằng WHATWG API

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');

Phân tích cú pháp chuỗi URL bằng API kế thừa

import url from 'node:url';
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');

Xây dựng một URL từ các bộ phận thành phần và nhận chuỗi # đã xây dựng

Có thể xây dựng URL WHATWG từ các bộ phận cấu thành bằng cách sử dụng trình thiết lập thuộc tính hoặc chuỗi ký tự mẫu

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
0
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1

Để lấy chuỗi URL đã tạo, hãy sử dụng trình truy cập thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
7

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
3

API URL WHATWG #

Lớp.
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1#

Lịch sửPhiên bảnChangesv10. 0. 0

Lớp hiện có sẵn trên đối tượng toàn cầu

v7. 0. 0, v6. 13. 0

Đã thêm vào. v7. 0. 0, v6. 13. 0

Lớp

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 tương thích với trình duyệt, được triển khai bằng cách tuân theo Tiêu chuẩn URL WHATWG. Ví dụ về các URL được phân tích cú pháp có thể được tìm thấy trong chính Tiêu chuẩn. Lớp
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 cũng có sẵn trên đối tượng toàn cầu

Theo quy ước của trình duyệt, tất cả các thuộc tính của đối tượng

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 được triển khai dưới dạng getters và setters trên nguyên mẫu lớp, thay vì dưới dạng thuộc tính dữ liệu trên chính đối tượng. Do đó, không giống như các
import url from 'node:url';
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
2 kế thừa, việc sử dụng từ khóa
import url from 'node:url';
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
3 trên bất kỳ thuộc tính nào của các đối tượng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 (e. g.
import url from 'node:url';
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
5,
import url from 'node:url';
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
6, v.v.) không có hiệu lực nhưng vẫn sẽ trả về
import url from 'node:url';
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
7

import url from 'node:url';
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
8#
  • import url from 'node:url';
    const myURL =
      url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
    const myURL =
      url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    9 URL đầu vào tuyệt đối hoặc tương đối để phân tích cú pháp. Nếu
    import url from 'node:url';
    const myURL =
      url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
    const myURL =
      url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    9 là tương đối, thì bắt buộc phải có
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    01. Nếu
    import url from 'node:url';
    const myURL =
      url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
    const myURL =
      url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    9 là tuyệt đối, thì
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    01 bị bỏ qua. Nếu
    import url from 'node:url';
    const myURL =
      url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
    const myURL =
      url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    9 không phải là một chuỗi, nó sẽ được chuyển đổi thành một chuỗi trước
  • const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    01 URL cơ sở để giải quyết nếu
    import url from 'node:url';
    const myURL =
      url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
    const myURL =
      url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    9 không phải là tuyệt đối. Nếu
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    01 không phải là một chuỗi, nó sẽ được chuyển đổi thành một chuỗi trước

Tạo một đối tượng

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 mới bằng cách phân tích cú pháp của
import url from 'node:url';
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
9 so với
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
01. Nếu
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
01 được truyền dưới dạng chuỗi, nó sẽ được phân tích cú pháp tương đương với
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
12

Trình tạo URL có thể truy cập dưới dạng thuộc tính trên đối tượng chung. Nó cũng có thể được nhập từ mô-đun url tích hợp

Một

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
13 sẽ bị ném nếu
import url from 'node:url';
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
9 hoặc
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
01 không phải là URL hợp lệ. Lưu ý rằng một nỗ lực sẽ được thực hiện để ép buộc các giá trị đã cho thành các chuỗi. Ví dụ

Các ký tự Unicode xuất hiện trong tên máy chủ của

import url from 'node:url';
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
9 sẽ được tự động chuyển đổi sang ASCII bằng thuật toán Punycode

Tính năng này chỉ khả dụng nếu tệp thực thi

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
17 được biên dịch với ICU được bật. Nếu không, các tên miền được chuyển qua không thay đổi

Trong trường hợp không biết trước liệu

import url from 'node:url';
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
const myURL =
  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
9 có phải là một URL tuyệt đối và một
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
01 được cung cấp hay không, bạn nên xác thực rằng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
2 của đối tượng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 là những gì được mong đợi

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
32#

Nhận và đặt phần phân đoạn của URL

Các ký tự URL không hợp lệ có trong giá trị được gán cho thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
33 được mã hóa theo phần trăm. Việc lựa chọn ký tự nào để mã hóa theo phần trăm có thể khác một chút so với những gì mà phương thức
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
0 và
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
35 sẽ tạo ra

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
36#

Nhận và đặt phần máy chủ của URL

Các giá trị máy chủ không hợp lệ được gán cho thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
4 bị bỏ qua

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
38#

Nhận và đặt phần tên máy chủ của URL. Sự khác biệt chính giữa

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
36 và
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
38 là
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
38 không bao gồm cổng

Các giá trị tên máy chủ không hợp lệ được gán cho thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
82 bị bỏ qua

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
83#

Nhận và đặt URL được tuần tự hóa

Lấy giá trị của thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
7 tương đương với việc gọi
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
85

Đặt giá trị của thuộc tính này thành một giá trị mới tương đương với việc tạo một đối tượng

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 mới bằng cách sử dụng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
87. Mỗi thuộc tính của đối tượng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 sẽ được sửa đổi

Nếu giá trị được gán cho thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
7 không phải là một URL hợp lệ, thì một
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
13 sẽ bị ném ra

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
551#

Lịch sửPhiên bảnThay đổiv15. 0. 0

Lược đồ "gopher" không còn đặc biệt nữa và

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
551 hiện trả về
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
553 cho nó

Nhận tuần tự hóa chỉ đọc của nguồn gốc của URL

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
554#

Nhận và đặt phần mật khẩu của URL

Các ký tự URL không hợp lệ được bao gồm trong giá trị được gán cho thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
6 được mã hóa theo phần trăm. Việc lựa chọn ký tự nào để mã hóa phần trăm có thể khác một chút so với những gì mà phương thức
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
0 và
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
35 sẽ tạo ra

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
558#

Nhận và đặt phần đường dẫn của URL

Các ký tự URL không hợp lệ có trong giá trị được gán cho thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
559 được mã hóa theo phần trăm. Việc lựa chọn ký tự nào để mã hóa phần trăm có thể khác một chút so với những gì mà phương thức
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
0 và
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
35 sẽ tạo ra

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
552#

Lịch sửPhiên bảnThay đổiv15. 0. 0

Đề án "gopher" không còn đặc biệt

Nhận và đặt phần cổng của URL

Giá trị cổng có thể là một số hoặc một chuỗi chứa một số trong phạm vi

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
553 đến
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
554 (bao gồm). Đặt giá trị thành cổng mặc định của các đối tượng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 được cung cấp cho
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
3 sẽ dẫn đến giá trị
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
557 trở thành chuỗi rỗng (
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
558)

Giá trị cổng có thể là một chuỗi rỗng trong trường hợp đó cổng phụ thuộc vào giao thức/lược đồ

giao thức cổng"ftp"21"tệp""http"80"https"443"ws"80"wss"443

Khi gán giá trị cho cổng, trước tiên giá trị đó sẽ được chuyển đổi thành chuỗi bằng cách sử dụng

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
559

Nếu chuỗi đó không hợp lệ nhưng bắt đầu bằng một số, thì số ở đầu được gán cho

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
557. Nếu số nằm ngoài phạm vi được biểu thị ở trên, nó sẽ bị bỏ qua

Các số chứa dấu thập phân, chẳng hạn như số dấu phẩy động hoặc số trong ký hiệu khoa học, không phải là ngoại lệ đối với quy tắc này. Các số ở đầu cho đến dấu thập phân sẽ được đặt làm cổng của URL, giả sử chúng hợp lệ

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
561#

Nhận và đặt phần giao thức của URL

Các giá trị giao thức URL không hợp lệ được gán cho thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
3 bị bỏ qua

Chương trình đặc biệt#

Lịch sửPhiên bảnThay đổiv15. 0. 0

Đề án "gopher" không còn đặc biệt

Tiêu chuẩn URL WHATWG coi một số sơ đồ giao thức URL là đặc biệt về cách chúng được phân tích cú pháp và tuần tự hóa. Khi một URL được phân tích cú pháp bằng một trong những giao thức đặc biệt này, thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
561 có thể được thay đổi thành một giao thức đặc biệt khác nhưng không thể thay đổi thành một giao thức không đặc biệt và ngược lại

Chẳng hạn, thay đổi từ

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
564 thành
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
565 hoạt động

Tuy nhiên, việc thay đổi từ giao thức

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
564 sang giao thức
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
567 giả định không phải vì giao thức mới không đặc biệt

Tương tự như vậy, việc thay đổi từ một giao thức không đặc biệt sang một giao thức đặc biệt cũng không được phép

Theo Tiêu chuẩn URL WHATWG, các sơ đồ giao thức đặc biệt là

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
568,
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
569,
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
564,
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
565,
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
02 và
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
03

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
04#

Nhận và đặt phần truy vấn được tuần tự hóa của URL

Bất kỳ ký tự URL không hợp lệ nào xuất hiện trong giá trị được chỉ định thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
05 sẽ được mã hóa theo phần trăm. Việc lựa chọn ký tự nào để mã hóa phần trăm có thể khác một chút so với những gì mà phương thức
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
0 và
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
35 sẽ tạo ra

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
08#

Nhận đối tượng

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09 đại diện cho các tham số truy vấn của URL. Thuộc tính này là chỉ đọc nhưng đối tượng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09 mà nó cung cấp có thể được sử dụng để thay đổi thể hiện URL; . Xem tài liệu
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09 để biết chi tiết

Hãy cẩn thận khi sử dụng

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
13 để sửa đổi
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 bởi vì, theo thông số kỹ thuật WHATWG, đối tượng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09 sử dụng các quy tắc khác nhau để xác định ký tự nào cần mã hóa phần trăm. Chẳng hạn, đối tượng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 sẽ không mã hóa phần trăm ký tự dấu ngã ASCII (
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
17), trong khi
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09 sẽ luôn mã hóa nó

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
19#

Nhận và đặt phần tên người dùng của URL

Bất kỳ ký tự URL không hợp lệ nào xuất hiện trong giá trị được chỉ định thuộc tính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
5 sẽ được mã hóa theo phần trăm. Việc lựa chọn ký tự nào để mã hóa phần trăm có thể khác một chút so với những gì mà phương thức
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
0 và
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
35 sẽ tạo ra

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
85#

Phương thức

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
24 trên đối tượng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 trả về URL được tuần tự hóa. Giá trị trả về tương đương với giá trị của
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
83 và
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
27

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
27#

Phương thức

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
29 trên đối tượng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 trả về URL được tuần tự hóa. Giá trị trả về tương đương với giá trị của
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
83 và
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
85

Phương thức này được gọi tự động khi một đối tượng

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1 được đánh số thứ tự với
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
34

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
35#

Tạo chuỗi URL

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
36 đại diện cho đối tượng đã cho và có thể được sử dụng để truy xuất
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
37 sau này

Dữ liệu được lưu trữ bởi đăng ký sẽ được giữ lại trong bộ nhớ cho đến khi

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
38 được gọi để xóa nó

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
37 đối tượng được đăng ký trong chủ đề hiện tại. Nếu sử dụng Chuỗi công nhân, các đối tượng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
37 được đăng ký trong một Công nhân sẽ không khả dụng cho các công nhân khác hoặc chuỗi chính

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
41#
  • const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    42 Một chuỗi URL
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    43 được trả về bởi lệnh gọi trước đó tới
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    44

Xóa lưu trữ được xác định bởi ID đã cho. Cố gắng thu hồi ID chưa được đăng ký sẽ âm thầm thất bại

Lớp.
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09#

Lịch sửPhiên bảnChangesv10. 0. 0

Lớp hiện có sẵn trên đối tượng toàn cầu

v7. 5. 0, v6. 13. 0

Đã thêm vào. v7. 5. 0, v6. 13. 0

API

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09 cung cấp quyền truy cập đọc và ghi vào truy vấn của một
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
1. Lớp
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09 cũng có thể được sử dụng độc lập với một trong bốn hàm tạo sau. Lớp
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09 cũng có sẵn trên đối tượng toàn cầu

Giao diện WHATWG

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09 và mô-đun
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
51 có mục đích tương tự, nhưng mục đích của mô-đun
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
51 tổng quát hơn, vì nó cho phép tùy chỉnh các ký tự phân cách (
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
53 và
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
54). Mặt khác, API này được thiết kế hoàn toàn cho các chuỗi truy vấn URL

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
55#

Khởi tạo một đối tượng

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09 trống mới

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
57#

Phân tích cú pháp

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
58 dưới dạng chuỗi truy vấn và sử dụng nó để khởi tạo một đối tượng
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
09 mới. Một
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
60 hàng đầu, nếu có, sẽ bị bỏ qua

const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
61#

Đã thêm vào. v7. 10. 0, v6. 13. 0

  • const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    62 Một đối tượng đại diện cho một tập hợp các cặp khóa-giá trị

    Khởi tạo đối tượng

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    09 mới bằng bản đồ băm truy vấn. Khóa và giá trị của từng thuộc tính của
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    62 luôn bị ép buộc vào các chuỗi

    Không giống như mô-đun

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    51, các khóa trùng lặp ở dạng giá trị mảng không được phép. Mảng được xâu chuỗi bằng cách sử dụng
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    66, chỉ cần nối tất cả các phần tử mảng bằng dấu phẩy

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    67#

    Đã thêm vào. v7. 10. 0, v6. 13. 0

    • const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      68 Một đối tượng có thể lặp lại có các phần tử là cặp khóa-giá trị

    Khởi tạo một đối tượng

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    09 mới với một bản đồ có thể lặp lại theo cách tương tự như hàm tạo của
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    70.
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    68 có thể là một
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    72 hoặc bất kỳ đối tượng lặp nào. Điều đó có nghĩa là
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    68 có thể là một
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    09 khác, trong trường hợp đó, hàm tạo sẽ chỉ cần tạo một bản sao của
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    09 được cung cấp. Các phần tử của
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    68 là các cặp khóa-giá trị và bản thân chúng có thể là bất kỳ đối tượng có thể lặp lại nào

    Khóa trùng lặp được cho phép

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    77#

    Nối một cặp tên-giá trị mới vào chuỗi truy vấn

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    78#

    Xóa tất cả các cặp tên-giá trị có tên là

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    79

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    80#

    Trả về một ES6

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    81 trên mỗi cặp tên-giá trị trong truy vấn. Mỗi mục của iterator là một JavaScript
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    72. Mục đầu tiên của
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    72 là
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    79, mục thứ hai của
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    72 là
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    86

    Bí danh cho

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    87

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    88#

    Lịch sửPhiên bảnChangesv18. 0. 0

    Chuyển một cuộc gọi lại không hợp lệ cho đối số

    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    89 giờ sẽ ném
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    90 thay vì
    const myURL =
      new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
    91

    • const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      89 Được gọi cho từng cặp tên-giá trị trong truy vấn
    • const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      93 Được sử dụng làm giá trị
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      94 khi
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      89 được gọi

      Lặp lại từng cặp tên-giá trị trong truy vấn và gọi hàm đã cho

      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      96#
      • const myURL =
          new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        79
      • trả lại. hoặc
        const myURL =
          new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        98 nếu không có cặp tên-giá trị với
        const myURL =
          new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        79 đã cho

      Trả về giá trị của cặp tên-giá trị đầu tiên có tên là

      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      79. Nếu không có cặp nào như vậy, thì trả về
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      98

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      02#

      Trả về giá trị của tất cả các cặp tên-giá trị có tên là

      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      79. Nếu không có cặp nào như vậy, một mảng trống sẽ được trả về

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      04#

      Trả về

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      7 nếu có ít nhất một cặp tên-giá trị có tên là
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      79

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      07#

      Trả về ES6

      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      81 trên tên của mỗi cặp tên-giá trị

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      09#

      Đặt giá trị trong đối tượng

      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      09 được liên kết với
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      79 thành
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      86. Nếu có bất kỳ cặp tên-giá trị tồn tại trước nào có tên là
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      79, hãy đặt giá trị của cặp đầu tiên đó thành
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      86 và xóa tất cả các cặp khác. Nếu không, hãy nối cặp tên-giá trị vào chuỗi truy vấn

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      15#

      Đã thêm vào. v7. 7. 0, v6. 13. 0

      Sắp xếp tại chỗ tất cả các cặp tên-giá trị hiện có theo tên của chúng. Việc sắp xếp được thực hiện bằng thuật toán sắp xếp ổn định, vì vậy thứ tự tương đối giữa các cặp tên-giá trị có cùng tên được giữ nguyên

      Đặc biệt, phương pháp này có thể được sử dụng để tăng số lần truy cập bộ đệm

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      16#

      Trả về các tham số tìm kiếm được tuần tự hóa dưới dạng chuỗi, với các ký tự được mã hóa theo phần trăm khi cần thiết

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      17#

      Trả về một ES6

      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      81 trên các giá trị của mỗi cặp tên-giá trị

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      19#

      Trả về một ES6

      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      81 trên mỗi cặp tên-giá trị trong chuỗi truy vấn. Mỗi mục của iterator là một JavaScript
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      72. Mục đầu tiên của
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      72 là
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      79, mục thứ hai của
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      72 là
      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      86

      Bí danh cho

      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      80

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      27#

      Đã thêm vào. v7. 4. 0, v6. 13. 0

      Trả về tuần tự hóa Punycode ASCII của

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      28. Nếu
      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      28 là miền không hợp lệ, chuỗi trống sẽ được trả về

      Nó thực hiện thao tác nghịch đảo với

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      30

      Tính năng này chỉ khả dụng nếu tệp thực thi

      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      17 được biên dịch với ICU được bật. Nếu không, các tên miền được chuyển qua không thay đổi

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      32#

      Đã thêm vào. v7. 4. 0, v6. 13. 0

      Trả về tuần tự hóa Unicode của

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      28. Nếu
      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      28 là miền không hợp lệ, chuỗi trống sẽ được trả về

      Nó thực hiện thao tác nghịch đảo với

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      35

      Tính năng này chỉ khả dụng nếu tệp thực thi

      const myURL =
        new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      17 được biên dịch với ICU được bật. Nếu không, các tên miền được chuyển qua không thay đổi

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      37#

      • import url from 'node:url';
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        38. Chuỗi URL tệp hoặc đối tượng URL để chuyển đổi thành đường dẫn
      • trả lại. Nút dành riêng cho nền tảng được giải quyết đầy đủ. đường dẫn tệp js

      Chức năng này đảm bảo giải mã chính xác các ký tự được mã hóa phần trăm cũng như đảm bảo chuỗi đường dẫn tuyệt đối hợp lệ trên nhiều nền tảng

      import url from 'node:url';
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
      const myURL =
        url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
      39#

      • const myURL =
          new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        1 Một đối tượng URL WHATWG
      • import url from 'node:url';
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        41
        • import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          42
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          7 nếu chuỗi URL được xê-ri hóa phải bao gồm tên người dùng và mật khẩu, nếu không thì
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          44. Mặc định.
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          7
        • import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          46
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          7 nếu chuỗi URL được đăng nhiều kỳ phải bao gồm đoạn, nếu không thì
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          44. Mặc định.
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          7
        • const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          05
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          7 nếu chuỗi URL được đánh số tự động phải bao gồm truy vấn tìm kiếm, nếu không thì
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          44. Mặc định.
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          7
        • import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          54
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          7 nếu các ký tự Unicode xuất hiện trong thành phần máy chủ của chuỗi URL phải được mã hóa trực tiếp thay vì được mã hóa bằng Punycode. Mặc định.
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          44
      • trả lại.
      • Trả về một tuần tự hóa có thể tùy chỉnh của một đại diện URL

        import url from 'node:url';
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        57 của một đối tượng URL WHATWG

        Đối tượng URL có cả phương thức

        const myURL =
          new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        24 và thuộc tính
        const myURL =
          new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        7 trả về chuỗi tuần tự hóa của URL. Tuy nhiên, chúng không thể tùy chỉnh theo bất kỳ cách nào. Phương pháp
        import url from 'node:url';
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        39 cho phép tùy chỉnh cơ bản đầu ra

        import url from 'node:url';
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        61#

        • import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          62 Đường dẫn chuyển đổi sang File URL
        • trả lại. Đối tượng URL tệp

        Chức năng này đảm bảo rằng

        import url from 'node:url';
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        62 được giải quyết tuyệt đối và các ký tự điều khiển URL được mã hóa chính xác khi chuyển đổi thành URL tệp

        import url from 'node:url';
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
        const myURL =
          url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
        64#

        Đã thêm vào. v15. 7. 0, v14. 18. 0

        • import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          38 Đối tượng URL WHATWG để chuyển đổi thành đối tượng tùy chọn
        • trả lại. đối tượng tùy chọn
          • const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            3 Giao thức sử dụng
          • const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            82 Một tên miền hoặc địa chỉ IP của máy chủ để gửi yêu cầu tới
          • const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            33 Phần đoạn của URL
          • const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            05 Phần truy vấn được tuần tự hóa của URL
          • const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            559 Phần đường dẫn của URL
          • import url from 'node:url';
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            62 Đường dẫn yêu cầu. Nên bao gồm chuỗi truy vấn nếu có. e. G.
            import url from 'node:url';
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            72. Một ngoại lệ được đưa ra khi đường dẫn yêu cầu chứa các ký tự không hợp lệ. Hiện tại, chỉ có không gian bị từ chối nhưng điều đó có thể thay đổi trong tương lai
          • const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            7 URL được đăng nhiều kỳ
          • const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            557 Cổng của máy chủ từ xa
          • import url from 'node:url';
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            42 Xác thực cơ bản i. e.
            import url from 'node:url';
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            76 để tính tiêu đề Ủy quyền

          Chức năng tiện ích này chuyển đổi một đối tượng URL thành một đối tượng tùy chọn thông thường như mong đợi của API

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          77 và
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          78

          API URL kế thừa#

          Lịch sửPhiên bảnThay đổiv15. 13. 0, v14. 17. 0

          thu hồi khấu hao. Trạng thái đã thay đổi thành "Di sản"

          v11. 0. 0

          API này không được dùng nữa

          Kế thừa
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          2#

          Lịch sửPhiên bảnThay đổiv15. 13. 0, v14. 17. 0

          thu hồi khấu hao. Trạng thái đã thay đổi thành "Di sản"

          v11. 0. 0

          API URL kế thừa không được dùng nữa. Sử dụng API URL WHATWG

          Di sản

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          2 (
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          81 hoặc
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          82) được tạo và trả về bởi hàm
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          0

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          84#

          Thuộc tính

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          42 là phần tên người dùng và mật khẩu của URL, còn được gọi là thông tin người dùng. Tập hợp con chuỗi này theo sau dấu gạch chéo kép và
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          3 (nếu có) và đứng trước thành phần
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          4, được phân định bởi
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          88. Chuỗi là tên người dùng hoặc đó là tên người dùng và mật khẩu được phân tách bằng
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          89

          Ví dụ.

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          90

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          91#

          Thuộc tính

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          33 là phần định danh phân đoạn của URL bao gồm ký tự
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          93 ở đầu

          Ví dụ.

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          94

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          95#

          Thuộc tính

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          4 là toàn bộ phần máy chủ viết hoa thường của URL, bao gồm cả
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          557 nếu được chỉ định

          Ví dụ.

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          98

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          99#

          Thuộc tính

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          82 là phần tên máy chủ viết thường của thành phần
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          4 không bao gồm
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          557

          Ví dụ.

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          003

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          004#

          Thuộc tính

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          7 là chuỗi URL đầy đủ đã được phân tích cú pháp bằng cả hai thành phần
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          3 và
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          4 được chuyển đổi thành chữ thường

          Ví dụ.

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          008

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          009#

          Thuộc tính

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          62 là sự kết hợp của các thành phần
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          559 và
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          05

          Ví dụ.

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          013

          Không có giải mã của

          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          62 được thực hiện

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          015#

          Thuộc tính

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          559 bao gồm toàn bộ phần đường dẫn của URL. Đây là mọi thứ sau
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          4 (bao gồm cả
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          557) và trước khi bắt đầu các thành phần
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          019 hoặc
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          33, được phân định bằng dấu chấm hỏi ASCII (
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          021) hoặc ký tự băm (
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          93)

          Ví dụ.

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          023

          Không thực hiện giải mã chuỗi đường dẫn

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          024#

          Thuộc tính

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          557 là phần cổng số của thành phần
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          4

          Ví dụ.

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          027

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          028#

          Thuộc tính

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          3 xác định sơ đồ giao thức chữ thường của URL

          Ví dụ.

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          030

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          031#

          Thuộc tính

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          019 là chuỗi truy vấn không có dấu chấm hỏi ASCII ở đầu (
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          021) hoặc một đối tượng được trả về bởi phương thức
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          035 của mô-đun
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          51. Cho dù thuộc tính
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          019 là một chuỗi hay đối tượng được xác định bởi đối số
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          037 được truyền cho
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          0

          Ví dụ.

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          039 hoặc
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          040

          Nếu được trả về dưới dạng chuỗi, không có quá trình giải mã chuỗi truy vấn nào được thực hiện. Nếu được trả về dưới dạng một đối tượng, cả khóa và giá trị đều được giải mã

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          041#

          Thuộc tính

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          05 bao gồm toàn bộ phần "chuỗi truy vấn" của URL, bao gồm ký tự dấu chấm hỏi ASCII (
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          021) ở đầu

          Ví dụ.

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          044

          Không giải mã chuỗi truy vấn nào được thực hiện

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          045#

          Thuộc tính

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          046 là một
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          047 với giá trị là
          import url from 'node:url';
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
          const myURL =
            url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          7 nếu hai ký tự dấu gạch chéo lên ASCII (
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          049) được yêu cầu sau dấu hai chấm trong
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          3

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          051#

          Lịch sửPhiên bảnThay đổiv17. 0. 0

          Bây giờ đưa ra một ngoại lệ

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          052 khi chuyển đổi Punycode của tên máy chủ đưa ra các thay đổi có thể khiến URL được phân tích cú pháp lại theo cách khác

          v15. 13. 0, v14. 17. 0

          thu hồi khấu hao. Trạng thái đã thay đổi thành "Di sản"

          v11. 0. 0

          API URL kế thừa không được dùng nữa. Sử dụng API URL WHATWG

          v7. 0. 0

          Giờ đây, các URL có lược đồ

          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          053 sẽ luôn sử dụng đúng số lượng dấu gạch chéo bất kể tùy chọn
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          046. Tùy chọn
          const myURL =
            new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
          046 giả không có giao thức hiện cũng được tôn trọng mọi lúc

          v0. 1. 25

          Đã thêm vào. v0. 1. 25

          • import url from 'node:url';
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            2. Một đối tượng URL (như được trả về bởi
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            0 hoặc được xây dựng theo cách khác). Nếu là một chuỗi, nó sẽ được chuyển đổi thành một đối tượng bằng cách chuyển nó tới
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            0

            Phương thức

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            35 trả về một chuỗi URL được định dạng bắt nguồn từ
            import url from 'node:url';
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            2

            Nếu

            import url from 'node:url';
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            2 không phải là một đối tượng hoặc một chuỗi, thì
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            35 sẽ ném một
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            13

            Quá trình định dạng hoạt động như sau

            • Một chuỗi trống mới
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              064 được tạo
            • Nếu
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              028 là một chuỗi, thì nó được thêm nguyên trạng vào
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              064
            • Mặt khác, nếu
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              028 không phải là
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              068 và không phải là một chuỗi, thì một
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              069 sẽ bị ném
            • Đối với tất cả các giá trị chuỗi của
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              028 không kết thúc bằng ký tự dấu hai chấm ASCII (
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              89), chuỗi ký tự
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              89 sẽ được thêm vào
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              064
            • Nếu một trong các điều kiện sau là đúng, thì chuỗi ký tự
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              074 sẽ được thêm vào
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              064
              • Tài sản
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                045 là đúng;
              • const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                028 bắt đầu bằng
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                564,
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                565,
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                568,
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                081 hoặc
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                569;
            • Nếu giá trị của thuộc tính
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              84 là trung thực và
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              95 hoặc
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              99 không phải là
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              068, thì giá trị của
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              84 sẽ được ép thành một chuỗi và được thêm vào
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              064 theo sau là chuỗi ký tự
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              88
            • Nếu tài sản
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              95 là
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              068 thì
              • Nếu
                import url from 'node:url';
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                99 là một chuỗi, nó sẽ được thêm vào
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                064
              • Mặt khác, nếu
                import url from 'node:url';
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                99 không phải là
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                068 và không phải là một chuỗi, thì một
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                069 sẽ bị ném
              • Nếu giá trị tài sản
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                024 là trung thực và
                import url from 'node:url';
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                99 không phải là
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                068
                • Chuỗi ký tự
                  import url from 'node:url';
                  const myURL =
                    url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
                  const myURL =
                    url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                  89 được thêm vào
                  const myURL =
                    new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                  064 và
                • Giá trị của
                  const myURL =
                    new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                  024 được buộc vào một chuỗi và được thêm vào
                  const myURL =
                    new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                  064
            • Mặt khác, nếu giá trị thuộc tính
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              95 là đúng, thì giá trị của
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              95 được buộc vào một chuỗi và được thêm vào
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              064
            • Nếu thuộc tính
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              015 là một chuỗi không phải là chuỗi rỗng
              • Nếu
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                015 không bắt đầu bằng dấu gạch chéo ASCII (________ 1049), thì chuỗi ký tự ________ 1110 được thêm vào _______ 1064
              • Giá trị của
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                015 được thêm vào
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                064
            • Mặt khác, nếu
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              015 không phải là
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              068 và không phải là một chuỗi, thì một
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              069 sẽ bị ném
            • Nếu thuộc tính
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              041 là
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              068 và nếu thuộc tính
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              031 là một
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              120, thì chuỗi ký tự
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              021 được thêm vào
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              064 theo sau là đầu ra của việc gọi phương thức
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              124 của mô-đun
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              51 chuyển giá trị của
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              031
            • Ngược lại, nếu
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              041 là một chuỗi
              • Nếu giá trị của
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                041 không bắt đầu bằng ký tự dấu chấm hỏi ASCII (
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                021), thì chuỗi ký tự ____1021 được thêm vào ____1064
              • Giá trị của
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                041 được thêm vào
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                064
            • Mặt khác, nếu
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              041 không phải là
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              068 và không phải là một chuỗi, thì một
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              069 sẽ bị ném
            • Nếu thuộc tính
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              91 là một chuỗi
              • Nếu giá trị của
                import url from 'node:url';
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                91 không bắt đầu bằng ký tự mã băm ASCII (
                import url from 'node:url';
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                93), thì chuỗi ký tự
                import url from 'node:url';
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                93 được thêm vào
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                064
              • Giá trị của
                import url from 'node:url';
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
                const myURL =
                  url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                91 được thêm vào
                const myURL =
                  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
                064
            • Mặt khác, nếu thuộc tính
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              91 không phải là
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              068 và không phải là một chuỗi, thì một
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              069 sẽ bị ném
            • const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              064 được trả về

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            147#

            Lịch sửPhiên bảnThay đổiv19. 0. 0

            Ngừng sử dụng tài liệu chỉ

            v15. 13. 0, v14. 17. 0

            thu hồi khấu hao. Trạng thái đã thay đổi thành "Di sản"

            v11. 14. 0

            Thuộc tính

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            559 trên đối tượng URL được trả về hiện là
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            049 khi không có đường dẫn và sơ đồ giao thức là
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            150 hoặc
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            151

            v11. 0. 0

            API URL kế thừa không được dùng nữa. Sử dụng API URL WHATWG

            v9. 0. 0

            Thuộc tính

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            05 trên đối tượng URL được trả về hiện là
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            98 khi không có chuỗi truy vấn nào

            v0. 1. 25

            Đã thêm vào. v0. 1. 25

            • const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              154 Chuỗi URL để phân tích cú pháp
            • const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              037 Nếu
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              7, thuộc tính
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              019 sẽ luôn được đặt thành một đối tượng được trả về bởi phương thức
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              035 của mô-đun
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              51. Nếu
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              44, thuộc tính
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              019 trên đối tượng URL được trả về sẽ là một chuỗi chưa được giải mã, chưa được phân tích cú pháp. Mặc định.
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              44
            • const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              163 Nếu
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              7, mã thông báo đầu tiên sau chuỗi ký tự
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              074 và trước
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              049 tiếp theo sẽ được hiểu là
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              4. Chẳng hạn, cho trước
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              168, kết quả sẽ là
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              169 thay vì
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              170. Mặc định.
              import url from 'node:url';
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
              const myURL =
                url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              44

            Phương thức

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            0 lấy một chuỗi URL, phân tích cú pháp và trả về một đối tượng URL

            Một

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            13 được ném ra nếu
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            154 không phải là một chuỗi

            Một

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            175 được ném ra nếu có thuộc tính
            import url from 'node:url';
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            42 nhưng không thể giải mã được

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            0 sử dụng một thuật toán đơn giản, không theo tiêu chuẩn để phân tích chuỗi URL. Nó dễ gặp các vấn đề bảo mật như giả mạo tên máy chủ và xử lý sai tên người dùng và mật khẩu. Không sử dụng với đầu vào không đáng tin cậy. CVE không được cấp cho
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            0 lỗ hổng. Thay vào đó, hãy sử dụng API URL WHATWG

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            179#

            Lịch sửPhiên bảnThay đổiv15. 13. 0, v14. 17. 0

            thu hồi khấu hao. Trạng thái đã thay đổi thành "Di sản"

            v11. 0. 0

            API URL kế thừa không được dùng nữa. Sử dụng API URL WHATWG

            v6. 6. 0

            Các trường

            import url from 'node:url';
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            42 hiện được giữ nguyên khi
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            181 và
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            182 đề cập đến cùng một máy chủ

            v6. 0. 0

            Các trường

            import url from 'node:url';
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');const url = require('node:url');
            const myURL =
              url.parse('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            42 hiện đã bị xóa tham số
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            182 chứa tên máy chủ

            v6. 5. 0, v4. 6. 2

            Trường

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            557 hiện được sao chép chính xác

            v0. 1. 25

            Đã thêm vào. v0. 1. 25

            • const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              181 URL cơ sở để sử dụng nếu
              const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              182 là URL tương đối
            • const myURL =
                new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
              182 URL mục tiêu để giải quyết

            Phương thức

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            189 phân giải URL mục tiêu so với URL cơ sở theo cách tương tự như cách trình duyệt web phân giải thẻ neo

            Để đạt được kết quả tương tự bằng cách sử dụng API URL WHATWG

            Mã hóa phần trăm trong URL#

            URL chỉ được phép chứa một phạm vi ký tự nhất định. Bất kỳ ký tự nào nằm ngoài phạm vi đó đều phải được mã hóa. Cách các ký tự đó được mã hóa và ký tự nào được mã hóa hoàn toàn phụ thuộc vào vị trí của ký tự đó trong cấu trúc của URL

            API kế thừa#

            Trong Legacy API, dấu cách (

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            190) và các ký tự sau sẽ tự động được thoát khỏi thuộc tính của đối tượng URL

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            8

            Ví dụ: ký tự khoảng trắng ASCII (

            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            190) được mã hóa thành
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            192. Ký tự dấu gạch chéo về phía trước ASCII (
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            049) được mã hóa thành
            const myURL =
              new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
            194

            # API WHATWG

            Tiêu chuẩn URL WHATWG sử dụng cách tiếp cận chi tiết và chọn lọc hơn để chọn các ký tự được mã hóa so với cách được sử dụng bởi API kế thừa

            Thuật toán WHATWG xác định bốn "bộ mã hóa phần trăm" mô tả các phạm vi ký tự phải được mã hóa phần trăm

            • Bộ mã hóa phần trăm kiểm soát C0 bao gồm các điểm mã trong phạm vi U+0000 đến U+001F (bao gồm) và tất cả các điểm mã lớn hơn U+007E

            • Bộ mã hóa phần trăm đoạn bao gồm bộ mã hóa phần trăm kiểm soát C0 và các điểm mã U+0020, U+0022, U+003C, U+003E và U+0060

            • Bộ mã hóa phần trăm đường dẫn bao gồm bộ mã hóa phần trăm kiểm soát C0 và các điểm mã U+0020, U+0022, U+0023, U+003C, U+003E, U+003F, U+0060, U+007B và

            • Bộ mã hóa thông tin người dùng bao gồm bộ mã hóa phần trăm đường dẫn và các điểm mã U+002F, U+003A, U+003B, U+003D, U+0040, U+005B, U+005C, U+005D, U+005E,

            Bộ mã hóa phần trăm thông tin người dùng được sử dụng riêng cho tên người dùng và mật khẩu được mã hóa trong URL. Bộ mã hóa phần trăm đường dẫn được sử dụng cho đường dẫn của hầu hết các URL. Bộ mã hóa phần trăm đoạn được sử dụng cho các đoạn URL. Bộ mã hóa phần trăm kiểm soát C0 được sử dụng cho máy chủ và đường dẫn trong một số điều kiện cụ thể, ngoài tất cả các trường hợp khác

            Khi các ký tự không phải ASCII xuất hiện trong tên máy chủ, tên máy chủ được mã hóa bằng thuật toán Punycode. Tuy nhiên, xin lưu ý rằng tên máy chủ có thể chứa cả ký tự được mã hóa bằng Punycode và ký tự được mã hóa theo phần trăm