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['//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ụngSo 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['//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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
1Thuộc tính
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
2 của URL WHATWG bao gồm const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
3 và const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
4, nhưng không bao gồm const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
5 hoặc const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
6┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ href │
├──────────┬──┬─────────────────────┬────────────────────────┬───────────────────────────┬───────┤
│ protocol │ │ auth │ host │ path │ hash │
│ │ │ ├─────────────────┬──────┼──────────┬────────────────┤ │
│ │ │ │ hostname │ port │ pathname │ search │ │
│ │ │ │ │ │ ├─┬──────────────┤ │
│ │ │ │ │ │ │ │ query │ │
" // 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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
0const myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
7const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
3API URL WHATWG #
Lớp. const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
1#
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
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['//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['//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ầuTheo 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['//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 2 kế thừa, việc sử dụng từ khóaimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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ượngimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
1 [e. g. 5,import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
7import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
8#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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ếuimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
9 là tương đối, thì bắt buộc phải cóimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
01. Nếuconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
9 là tuyệt đối, thìimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
01 bị bỏ qua. Nếuconst myURL = new URL['//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ướcimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
01 URL cơ sở để giải quyết nếuconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
9 không phải là tuyệt đối. Nếuimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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ướcconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Tạo một đối tượng
const myURL =
new URL['//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 9 so vớiimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
01. Nếu const myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
12Trì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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
13 sẽ bị ném nếu 9 hoặcimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const myURL =
new URL['//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
9 sẽ được tự động chuyển đổi sang ASCII bằng thuật toán Punycodeimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Tính năng này chỉ khả dụng nếu tệp thực thi
const myURL =
new URL['//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 đổiTrong trường hợp không biết trước liệu
9 có phải là một URL tuyệt đối và mộtimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
2 của đối tượng const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
1 là những gì được mong đợiconst myURL =
new URL['//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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
0 và const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
35 sẽ tạo raconst myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
4 bị bỏ quaconst myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
36 và const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
38 là const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
38 không bao gồm cổngCá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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
82 bị bỏ quaconst myURL =
new URL['//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['//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['//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['//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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
1 sẽ được sửa đổiNếu giá trị được gán cho thuộc tính
const myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
13 sẽ bị ném raconst myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
551 hiện trả về const myURL =
new URL['//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['//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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
0 và const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
35 sẽ tạo raconst myURL =
new URL['//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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
0 và const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
35 sẽ tạo raconst myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
553 đến const myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
1 được cung cấp cho const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
3 sẽ dẫn đến giá trị const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
557 trở thành chuỗi rỗng [const myURL =
new URL['//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"443Khi 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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
559Nế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['//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ỏ quaCá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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
3 bị bỏ quaChươ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['//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ạiChẳng hạn, thay đổi từ
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
564 thành const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
565 hoạt độngTuy nhiên, việc thay đổi từ giao thức
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
564 sang giao thức const myURL =
new URL['//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ệtTươ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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
568, const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
569, const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
564, const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
565, const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
02 và const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
03const myURL =
new URL['//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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
0 và const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
35 sẽ tạo raconst myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
08#Nhận đối tượng
const myURL =
new URL['//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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
09 để biết chi tiếtHãy cẩn thận khi sử dụng
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
13 để sửa đổi const myURL =
new URL['//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['//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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
17], trong khi const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
09 sẽ luôn mã hóa nóconst myURL =
new URL['//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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
0 và const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
35 sẽ tạo raconst myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
85#Phương thức
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
24 trên đối tượng const myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
83 và const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
27const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
27#Phương thức
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
29 trên đối tượng const myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
83 và const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
85Phương thức này được gọi tự động khi một đối tượng
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
1 được đánh số thứ tự với const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
34const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
35#Tạo chuỗi URL
const myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
37 sau nàyDữ 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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
38 được gọi để xóa nóconst myURL =
new URL['//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['//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ínhconst myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
41#
42 Một chuỗi URLconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
43 được trả về bởi lệnh gọi trước đó tớiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
44const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
09#
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
1. Lớp const myURL =
new URL['//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['//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ầuGiao diện WHATWG
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
09 và mô-đun const myURL =
new URL['//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['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
53 và const myURL =
new URL['//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 URLconst myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
09 trống mớiconst myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
57#Phân tích cú pháp
const myURL =
new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
09 mới. Một const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
60 hàng đầu, nếu có, sẽ bị bỏ quaconst myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
61#Đã thêm vào. v7. 10. 0, v6. 13. 0
62 Một đối tượng đại diện cho một tập hợp các cặp khóa-giá trịconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Khởi tạo đối tượng
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ủaconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
62 luôn bị ép buộc vào các chuỗiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Không giống như mô-đun
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ụngconst myURL = new URL['//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ẩyconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
67#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Đã thêm vào. v7. 10. 0, v6. 13. 0
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ịconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Khởi tạo một đối tượng
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ủaconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
70.const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
68 có thể là mộtconst myURL = new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
68 có thể là mộtconst myURL = new URL['//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ủaconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
09 được cung cấp. Các phần tử củaconst myURL = new URL['//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àoconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Khóa trùng lặp được cho phép
77#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Nối một cặp tên-giá trị mới vào chuỗi truy vấn
78#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Xóa tất cả các cặp tên-giá trị có tên là
79const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
80#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Trả về một ES6
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 JavaScriptconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
72. Mục đầu tiên củaconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
72 làconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
79, mục thứ hai củaconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
72 làconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
86const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Bí danh cho
87const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
88#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
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ố
89 giờ sẽ némconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
90 thay vìconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
91const myURL = new URL['//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ấnconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
93 Được sử dụng làm giá trịconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
94 khiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
89 được gọiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Lặp lại từng cặp tên-giá trị trong truy vấn và gọi hàm đã cho
96#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
79const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- trả lại. hoặc
98 nếu không có cặp tên-giá trị vớiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
79 đã choconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Trả về giá trị của cặp tên-giá trị đầu tiên có tên là
79. Nếu không có cặp nào như vậy, thì trả vềconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
98const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
02#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Trả về giá trị của tất cả các cặp tên-giá trị có tên là
79. Nếu không có cặp nào như vậy, một mảng trống sẽ được trả vềconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
04#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Trả về
7 nếu có ít nhất một cặp tên-giá trị có tên làimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
79const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
07#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Trả về ES6
81 trên tên của mỗi cặp tên-giá trịconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
09#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Đặt giá trị trong đối tượng
09 được liên kết vớiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
79 thànhconst myURL = new URL['//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['//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ànhconst myURL = new URL['//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ấnconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
15#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Đã 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
16#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
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
17#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Trả về một ES6
81 trên các giá trị của mỗi cặp tên-giá trịconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
19#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Trả về một ES6
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 JavaScriptconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
72. Mục đầu tiên củaconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
72 làconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
79, mục thứ hai củaconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
72 làconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
86const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Bí danh cho
80const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
27#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Đã thêm vào. v7. 4. 0, v6. 13. 0
Trả về tuần tự hóa Punycode ASCII của
28. Nếuimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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ềimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Nó thực hiện thao tác nghịch đảo với
30import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Tính năng này chỉ khả dụng nếu tệp thực thi
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 đổiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
32#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Đã thêm vào. v7. 4. 0, v6. 13. 0
Trả về tuần tự hóa Unicode của
28. Nếuimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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ềimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Nó thực hiện thao tác nghịch đảo với
35import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Tính năng này chỉ khả dụng nếu tệp thực thi
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 đổiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
37#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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ẫnimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- 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
39#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
1 Một đối tượng URL WHATWGconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
41import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
42import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
44. Mặc định.import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
7import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
46import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
44. Mặc định.import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
7import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
05const myURL = new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
44. Mặc định.import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
7import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
54import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
44import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- 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
57 của một đối tượng URL WHATWGimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Đối tượng URL có cả phương thức
24 và thuộc tínhconst myURL = new URL['//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ápconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
39 cho phép tùy chỉnh cơ bản đầu raimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
61#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
62 Đường dẫn chuyển đổi sang File URLimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- trả lại. Đối tượng URL tệp
Chức năng này đảm bảo rằng
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ệpimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
64#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Đã thêm vào. v15. 7. 0, v14. 18. 0
38 Đối tượng URL WHATWG để chuyển đổi thành đối tượng tùy chọnimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- trả lại. đối tượng tùy chọn
3 Giao thức sử dụngconst myURL = new URL['//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ớiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
33 Phần đoạn của URLconst myURL = new URL['//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 URLconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
559 Phần đường dẫn của URLconst myURL = new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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 laiimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
7 URL được đăng nhiều kỳconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
557 Cổng của máy chủ từ xaconst myURL = new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
76 để tính tiêu đề Ủy quyềnimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
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
77 vàimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
78import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
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. 0API này không được dùng nữa
Kế thừa
2#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
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. 0API URL kế thừa không được dùng nữa. Sử dụng API URL WHATWG
Di sản
2 [import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
81 hoặcimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
82] được tạo và trả về bởi hàmimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
0const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
84#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
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àimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
3 [nếu có] và đứng trước thành phầnconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
4, được phân định bởiconst myURL = new URL['//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ằngimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
89import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
90import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
91#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
33 là phần định danh phân đoạn của URL bao gồm ký tựconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
93 ở đầuimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
94import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
95#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
557 nếu được chỉ địnhconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
98import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
99#import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
82 là phần tên máy chủ viết thường của thành phầnconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
4 không bao gồmconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
557const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
003const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
004#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
7 là chuỗi URL đầy đủ đã được phân tích cú pháp bằng cả hai thành phầnconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
3 vàconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
4 được chuyển đổi thành chữ thườngconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
008const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
009#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
62 là sự kết hợp của các thành phầnimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
559 vàconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
05const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
013const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Không có giải mã của
62 được thực hiệnimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
015#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
559 bao gồm toàn bộ phần đường dẫn của URL. Đây là mọi thứ sauconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
4 [bao gồm cảconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
557] và trước khi bắt đầu các thành phầnconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
019 hoặcconst myURL = new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
021] hoặc ký tự băm [const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
93]import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
023const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Không thực hiện giải mã chuỗi đường dẫn
024#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
557 là phần cổng số của thành phầnconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
4const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
027const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
028#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
3 xác định sơ đồ giao thức chữ thường của URLconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
030const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
031#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
019 là chuỗi truy vấn không có dấu chấm hỏi ASCII ở đầu [const myURL = new URL['//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ứcconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
035 của mô-đunconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
51. Cho dù thuộc tínhconst myURL = new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
037 được truyền choconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
0const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
039 hoặcconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
040const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
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ã
041#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
021] ở đầuconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
044const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Không giải mã chuỗi truy vấn nào được thực hiện
045#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Thuộc tính
046 là mộtconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
047 với giá trị làconst myURL = new URL['//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 [import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
049] được yêu cầu sau dấu hai chấm trongconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
3const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
051#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Lịch sửPhiên bảnThay đổiv17. 0. 0
Bây giờ đưa ra một ngoại lệ
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ácv15. 13. 0, v14. 17. 0const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
thu hồi khấu hao. Trạng thái đã thay đổi thành "Di sản"
v11. 0. 0API URL kế thừa không được dùng nữa. Sử dụng API URL WHATWG
v7. 0. 0Giờ đây, các URL có lược đồ
053 sẽ luôn sử dụng đúng số lượng dấu gạch chéo bất kể tùy chọnconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
046. Tùy chọnconst myURL = new URL['//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úcv0. 1. 25const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Đã thêm vào. v0. 1. 25
2. Một đối tượng URL [như được trả về bởiimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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ớiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
0const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Phương thức
35 trả về một chuỗi URL được định dạng bắt nguồn từconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
2import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Nếu
2 không phải là một đối tượng hoặc một chuỗi, thìimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
35 sẽ ném mộtconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
13const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Quá trình định dạng hoạt động như sau
- Một chuỗi trống mới
064 được tạoconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu
028 là một chuỗi, thì nó được thêm nguyên trạng vàoconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Mặt khác, nếu
028 không phải làconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
068 và không phải là một chuỗi, thì mộtconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
069 sẽ bị némconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Đối với tất cả các giá trị chuỗi của
028 không kết thúc bằng ký tự dấu hai chấm ASCII [const myURL = new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
89 sẽ được thêm vàoimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu một trong các điều kiện sau là đúng, thì chuỗi ký tự
074 sẽ được thêm vàoconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Tài sản
045 là đúng;const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
028 bắt đầu bằngconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
564,const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
565,const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
568,const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
081 hoặcconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
569;const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Tài sản
- Nếu giá trị của thuộc tính
84 là trung thực vàimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
95 hoặcimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
99 không phải làimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
068, thì giá trị củaconst myURL = new URL['//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àoimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064 theo sau là chuỗi ký tựconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
88import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu tài sản
95 làimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
068 thìconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu
99 là một chuỗi, nó sẽ được thêm vàoimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Mặt khác, nếu
99 không phải làimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
068 và không phải là một chuỗi, thì mộtconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
069 sẽ bị némconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu giá trị tài sản
024 là trung thực vàconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
99 không phải làimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
068const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Chuỗi ký tự
89 được thêm vàoimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064 vàconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Giá trị của
024 được buộc vào một chuỗi và được thêm vàoconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Chuỗi ký tự
- Nếu
- Mặt khác, nếu giá trị thuộc tính
95 là đúng, thì giá trị củaimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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àoimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu thuộc tính
015 là một chuỗi không phải là chuỗi rỗngconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu
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 _______ 1064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Giá trị của
015 được thêm vàoconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu
- Mặt khác, nếu
015 không phải làconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
068 và không phải là một chuỗi, thì mộtconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
069 sẽ bị némconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu thuộc tính
041 làconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
068 và nếu thuộc tínhconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
031 là mộtconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
120, thì chuỗi ký tựconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
021 được thêm vàoconst myURL = new URL['//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ứcconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
124 của mô-đunconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
51 chuyển giá trị củaconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
031const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Ngược lại, nếu
041 là một chuỗiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu giá trị của
041 không bắt đầu bằng ký tự dấu chấm hỏi ASCII [const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
021], thì chuỗi ký tự ____1021 được thêm vào ____1064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Giá trị của
041 được thêm vàoconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu giá trị của
- Mặt khác, nếu
041 không phải làconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
068 và không phải là một chuỗi, thì mộtconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
069 sẽ bị némconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu thuộc tính
91 là một chuỗiimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu giá trị của
91 không bắt đầu bằng ký tự mã băm ASCII [import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
93 được thêm vàoimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Giá trị của
91 được thêm vàoimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
- Nếu giá trị của
- Mặt khác, nếu thuộc tính
91 không phải làimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
068 và không phải là một chuỗi, thì mộtconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
069 sẽ bị némconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
064 được trả vềconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
147#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
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. 0thu hồi khấu hao. Trạng thái đã thay đổi thành "Di sản"
v11. 14. 0Thuộc tính
559 trên đối tượng URL được trả về hiện làconst myURL = new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
150 hoặcconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
151v11. 0. 0const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
API URL kế thừa không được dùng nữa. Sử dụng API URL WHATWG
v9. 0. 0Thuộc tính
05 trên đối tượng URL được trả về hiện làconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
98 khi không có chuỗi truy vấn nàov0. 1. 25const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Đã thêm vào. v0. 1. 25
154 Chuỗi URL để phân tích cú phápconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
037 Nếuconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
7, thuộc tínhimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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ứcconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
035 của mô-đunconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
51. Nếuconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
44, thuộc tínhimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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.const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
44import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
163 Nếuconst myURL = new URL['//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ựimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
074 và trướcconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
049 tiếp theo sẽ được hiểu làconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
4. Chẳng hạn, cho trướcconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
168, kết quả sẽ làconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
169 thay vìconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
170. Mặc định.const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
44import url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Phương thức
0 lấy một chuỗi URL, phân tích cú pháp và trả về một đối tượng URLconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Một
13 được ném ra nếuconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
154 không phải là một chuỗiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Một
175 được ném ra nếu có thuộc tínhconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
42 nhưng không thể giải mã đượcimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//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 choconst myURL = new URL['//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 WHATWGconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
179#const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
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. 0API URL kế thừa không được dùng nữa. Sử dụng API URL WHATWG
v6. 6. 0Các trường
42 hiện được giữ nguyên khiimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
181 vàconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
182 đề cập đến cùng một máy chủv6. 0. 0const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Các trường
42 hiện đã bị xóa tham sốimport url from 'node:url'; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
const url = require['node:url']; const myURL = url.parse['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
182 chứa tên máy chủv6. 5. 0, v4. 6. 2const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Trường
557 hiện được sao chép chính xácv0. 1. 25const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Đã thêm vào. v0. 1. 25
181 URL cơ sở để sử dụng nếuconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
182 là URL tương đốiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
182 URL mục tiêu để giải quyếtconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Phương thức
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ẻ neoconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Để đạ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 [
190] và các ký tự sau sẽ tự động được thoát khỏi thuộc tính của đối tượng URLconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
8const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ: ký tự khoảng trắng ASCII [
190] được mã hóa thànhconst myURL = new URL['//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['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
049] được mã hóa thànhconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
194const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
# 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
- Một chuỗi trống mới