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 node:url
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 '//user:[email protected]:8080/p/a/t/h?query=string#hash'
, các thuộc tính của một đối tượng được trả về bởi kế thừa
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
0 đượ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 cấu thành và lấy 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['//example.org'];
myURL.pathname = '/a/b/c';
myURL.search = '?d=e';
myURL.hash = '#fgh';
const pathname = '/a/b/c';
const search = '?d=e';
const hash = '#fgh';
const myURL = new URL[`//example.org${pathname}${search}${hash}`];
Để 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'];
7console.log[myURL.href];
API URL WHATWG
Tầng 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ảnThay đổiv10. 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. 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 các 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ư s, sử dụng từ khóa 3 trên bất kỳ thuộc tính nào của đố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ẽ quay trở lạ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'];
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'];
8import 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à họ hàng, thì bắt buộc phải có ____10_______1. 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à 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'];
1 bị bỏ qua. Nếuconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
9 không phải là một chuỗi, nó là đầu tiê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'];
1 URL cơ sở để giải quyết nếuconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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'];
1 không phải là một chuỗi, nó là đầu tiênconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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['//example.org'];
myURL.pathname = '/a/b/c';
myURL.search = '?d=e';
myURL.hash = '#fgh';
1. Nếu const myURL = new URL['//example.org'];
myURL.pathname = '/a/b/c';
myURL.search = '?d=e';
myURL.hash = '#fgh';
1 đượ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 pathname = '/a/b/c';
const search = '?d=e';
const hash = '#fgh';
const myURL = new URL[`//example.org${pathname}${search}${hash}`];
2Trì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 pathname = '/a/b/c';
const search = '?d=e';
const hash = '#fgh';
const myURL = new URL[`//example.org${pathname}${search}${hash}`];
3 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['//example.org'];
myURL.pathname = '/a/b/c';
myURL.search = '?d=e';
myURL.hash = '#fgh';
1 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 thành ASCII bằng thuật toá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'];
Tính năng này chỉ khả dụng nếu tệp thực thi
const pathname = '/a/b/c';
const search = '?d=e';
const hash = '#fgh';
const myURL = new URL[`//example.org${pathname}${search}${hash}`];
7 được biên dịch với kích hoạ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['//example.org'];
myURL.pathname = '/a/b/c';
myURL.search = '?d=e';
myURL.hash = '#fgh';
1 đượ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 đợiconsole.log[myURL.href];
2Nhận và đặt phần phân đoạn 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
console.log[myURL.href];
3 là. 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ì phương thức và sẽ tạo raconsole.log[myURL.href];
6Nhậ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ỏ quaconsole.log[myURL.href];
8Nhận và đặt phần tên máy chủ của URL. Sự khác biệt chính giữa
console.log[myURL.href];
6 và console.log[myURL.href];
8 là console.log[myURL.href];
8 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
< > " ` \r \n \t { } | \ ^ '
2 bị bỏ qua< > " ` \r \n \t { } | \ ^ '
3Nhậ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Đặ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. 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 pathname = '/a/b/c';
const search = '?d=e';
const hash = '#fgh';
const myURL = new URL[`//example.org${pathname}${search}${hash}`];
3 sẽ được đưa ranode:url
1Lịch sửPhiên bảnThay đổiv15. 0. 0
Lược đồ "gopher" không còn đặc biệt nữa và node:url
1 hiện trả về node:url
3 cho nó
Nhận tuần tự hóa chỉ đọc của nguồn gốc của URL
node:url
4Nhậ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 là. 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ì phương thức và sẽ tạo ranode:url
8Nhậ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 node:url
9 là. 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ì phương thức và sẽ tạo ra
node:url
2Lị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 node:url
3 đến node:url
4 [bao gồm]. Đặt giá trị thành cổng mặc định của đối tượng
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
1 được cung cấp const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
3 sẽ dẫn đến giá trị node:url
7 trở thành chuỗi trống [node:url
8]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 một giá trị cho cổng, trước tiên giá trị đó sẽ được chuyển đổi thành một chuỗi bằng cách sử dụng node:url
9
Nếu chuỗi đó không hợp lệ nhưng nó bắt đầu bằng một số, thì số ở đầu được gán cho node:url
7. 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ệ
'//user:[email protected]:8080/p/a/t/h?query=string#hash'
1Nhậ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ệtLị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 các giao thức đặc biệt này, thuộc tính '//user:[email protected]:8080/p/a/t/h?query=string#hash'
1 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ừ '//user:[email protected]:8080/p/a/t/h?query=string#hash'
4 thành '//user:[email protected]:8080/p/a/t/h?query=string#hash'
5 hoạt động
Tuy nhiên, việc thay đổi từ giao thức '//user:[email protected]:8080/p/a/t/h?query=string#hash'
4 sang giao thức '//user:[email protected]:8080/p/a/t/h?query=string#hash'
7 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 lược đồ giao thức đặc biệt là '//user:[email protected]:8080/p/a/t/h?query=string#hash'
8, '//user:[email protected]:8080/p/a/t/h?query=string#hash'
9, '//user:[email protected]:8080/p/a/t/h?query=string#hash'
4, '//user:[email protected]:8080/p/a/t/h?query=string#hash'
5,
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'];
04Nhậ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. 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ì phương thức và sẽ tạo raconst myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
08Nhận đối tượng đạ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 để 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'];
19Nhậ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 gán cho thuộc tính
const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
5 sẽ được. 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ì phương thức và sẽ tạo ra< > " ` \r \n \t { } | \ ^ '
5Phươ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 vàconst myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
27Phươ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 vàPhươ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'];
35Tạ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 dữ liệu đó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 Worker Threads, const myURL =
new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
37 đối tượng được đăng ký trong một Worker sẽ không có sẵn cho các worker khác hoặc luồng 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
Tầng 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ảnThay đổiv10. 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'];
55Khở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'];
57Phâ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'];
67const 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ỉ tạo một bản sao củaconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
09 đã 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
77const 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
78const 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'];
80const 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
88const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
89 giờ đây 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 mỗi 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
96const 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'];
02import 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'];
04import 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'];
07import 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 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'];
09import 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'];
15import 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. Sắp xếp được thực hiện với một , do đó, 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
16import 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
17import 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'];
19import 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
27import 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 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ệ, thì chuỗi trống đượ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 để
Tính năng này chỉ khả dụng nếu tệp thực thi
7 được biên dịch với kích hoạt. Nếu không, các tên miền được chuyển qua không thay đổiconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
32import 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ệ, thì chuỗi trống đượ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 để
Tính năng này chỉ khả dụng nếu tệp thực thi
7 được biên dịch với kích hoạt. Nếu không, các tên miền được chuyển qua không thay đổiconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
37import 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
39import 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ượngconst 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 đánh số tự động 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. Vỡ nợ.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. Vỡ nợ.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. Vỡ nợ.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. Vỡ nợ.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 URL
57 đại diện cho một đố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'];
Đố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'];
61import 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 một 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'];
64import 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 để chuyển 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'];
2 Một tên miền hoặc địa chỉ IP của máy chủ để gửi yêu cầu tới< > " ` \r \n \t { } | \ ^ '
3 Phần đoạn của URLconsole.log[myURL.href];
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'];
node:url
9 Phần đường dẫn của URL
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'];
node:url
7 Cổng của máy chủ từ xa
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 muốn của và API
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
Di sản
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'];
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'];
84import 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 của chuỗi này theo sau dấu gạch chéo 3 và dấu gạch chéo kép [nếu có] và trướ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'];
4, được phân định bởiconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
88. Chuỗi có thể 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'];
91import 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
3 là phần định danh phân đoạn của URL bao gồm ký tựconsole.log[myURL.href];
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'];
95import 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 thường của URL, bao gồm cảconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
node:url
7 nếu được chỉ địnhVí 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'];
99import 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
2 là phần tên máy chủ viết thường của thành phần< > " ` \r \n \t { } | \ ^ '
4 không bao gồmconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
node:url
7Ví dụ.
03const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
04const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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ụ.
08const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
09const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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'];
node:url
9 và
05const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
13const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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'];
15const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
Thuộc tính
node:url
9 bao gồm toàn bộ phần đường dẫn của URL. Đây là tất cả những gì theo sau
4 [bao gồm cảconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
node:url
7] và trước khi bắt đầu các thành phần
19 hoặcconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
3, được phân định bằng dấu chấm hỏi ASCII [console.log[myURL.href];
21] hoặc dấu thăng [const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
93] 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'];
Ví dụ.
23const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
Không thực hiện giải mã chuỗi đường dẫn
24const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
Thuộc tính
node:url
7 là phần cổng số của thành phần
4const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
27const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
28const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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ụ.
30const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
31const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
Thuộc tính
19 là chuỗi truy vấn không có dấu chấm hỏi ASCII ở đầu [const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
21] hoặc một đối tượng được trả về bởi phương thứcconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
35 của mô-đun ________0____51. Cho dù thuộc tínhconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
19 là một chuỗi hay đối tượng được xác định bởi đối sốconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
37 được truyền choconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
0const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
39 hoặcconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
40const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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ã
41const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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 [_______10____21] ở đầuconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
Ví dụ.
44const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
Không giải mã chuỗi truy vấn nào được thực hiện
45const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
Thuộc tính
46 là mộtconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
47 với giá trị làconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
7 nếu hai ký tự gạch chéo chuyển tiếp 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'];
49] được yêu cầu sau dấu hai chấm trongconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
3const myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
51const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
Lịch sửPhiên bảnThay đổiv17. 0. 0
Bây giờ đưa ra một ngoại lệ
52 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['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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 đồ
53 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['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
46. Tùy chọnconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
46 giả mạo không có giao thức hiện cũng được tôn trọng mọi lúcv0. 1. 25const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
Đã 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
5 trả về một chuỗi URL được định dạng bắt nguồn từconsole.log[myURL.href];
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'];
5 sẽ ném mộtconsole.log[myURL.href];
Quá trình định dạng hoạt động như sau
- Một chuỗi trống mới
64 được tạoconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Nếu
28 là một chuỗi, thì nó được thêm nguyên trạng vàoconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Mặt khác, nếu
28 không phải làconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
68 và không phải là một chuỗi, an sẽ bị némconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Đối với tất cả các giá trị chuỗi của
28 không kết thúc bằng ký tự dấu hai chấm ASCII [const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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'];
64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Nếu một trong các điều kiện sau là đúng, thì chuỗi ký tự
74 sẽ được thêm vàoconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Tài sản
45 là đúng;const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
28 bắt đầu bằngconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
'//user:[email protected]:8080/p/a/t/h?query=string#hash'
4,'//user:[email protected]:8080/p/a/t/h?query=string#hash'
5,'//user:[email protected]:8080/p/a/t/h?query=string#hash'
8,
81 hoặcconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
'//user:[email protected]:8080/p/a/t/h?query=string#hash'
9;
- 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'];
68, thì giá trị củaconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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'];
64 theo sau là chuỗi ký tựconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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'];
68 thìconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- 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'];
64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- 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'];
68 và không phải là một chuỗi, an sẽ bị némconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Nếu giá trị tài sản
24 là trung thực, vàconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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'];
68const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- 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'];
64, vàconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Giá trị của
24 được buộc vào một chuỗi và được thêm vàoconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Chuỗi ký tự
- Nếu
- Mặt khác, nếu giá trị thuộc tính
95 là trung thực, 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'];
64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Nếu thuộc tính
15 là một chuỗi không phải là chuỗi rỗngconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Nếu
15 không bắt đầu bằng dấu gạch chéo ASCII [const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
49], thì chuỗi ký tự ___11_______10 được thêm vào ____10_______64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Giá trị của
15 được thêm vàoconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Nếu
- Mặt khác, nếu
15 không phải làconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
68 và không phải là một chuỗi, an sẽ bị némconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Nếu thuộc tính
41 làconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
68 và nếu thuộc tínhconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
31 là mộtconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
20, thì chuỗi ký tự ___10_______21 được thêm vàoconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
64 theo sau là đầu ra của việc gọi phương thứcconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
24 của mô-đunconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
51 chuyển giá trị củaconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
31const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Ngược lại, nếu
41 là một chuỗiconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Nếu giá trị của
41 không bắt đầu bằng ký tự dấu chấm hỏi ASCII [const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
21], thì chuỗi ký tự ___10_______21 được thêm vào ____10_______64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Giá trị của
41 được thêm vàoconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- Nếu giá trị của
- Mặt khác, nếu
41 không phải làconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
68 và không phải là một chuỗi, an sẽ bị némconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- 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'];
64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- 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'];
64const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
- 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'];
68 và không phải là một chuỗi, an sẽ bị némconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
64 được trả lạiconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
47const pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${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
node:url
9 trên đối tượng URL được trả về hiện là
49 khi không có đường dẫn và lược đồ giao thức làconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
50 hoặcconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
51v11. 0. 0const pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${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
54 Chuỗi URL để phân tích cú phápconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
37 Nếuconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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'];
19 sẽ luôn được đặt thành một đối tượng được trả về bởi phương thứcconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
35 của mô-đun ________0____51. Nếuconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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'];
19 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. Vỡ nợ.const myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
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'];
63 Nếuconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${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'];
74 và trướcconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
49 tiếp theo sẽ được hiểu làconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
4. Ví dụ, cho trướcconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
68, kết quả sẽ làconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
69 chứ không phải làconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
70. Vỡ nợ.const pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${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
3 được ném ra nếuconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
54 không phải là một chuỗiconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
Một
75 được ném ra nếu thuộc tínhconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
42 xuất hiện 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 thuật toán nhẹ nhàng, không 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. Sử dụng API thay thếconst myURL = new URL['//user:[email protected]:8080/p/a/t/h?query=string#hash'];
79const pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${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'];
81 vàconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
82 đề cập đến cùng một máy chủv6. 0. 0const pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${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'];
82 chứa tên máy chủv6. 5. 0, v4. 6. 2const pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
Trường
v0. 1. 25node:url
7 hiện đã được sao chép chính xácĐã thêm vào. v0. 1. 25
81 URL cơ sở để sử dụng nếuconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
82 là một URL tương đốiconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
82 URL mục tiêu để giải quyếtconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
Phương pháp
89 giải quyết URL mục tiêu liên quan đến URL cơ sở theo cách tương tự như cách trình duyệt web giải quyết thẻ neoconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
Để đạt được kết quả tương tự bằng cách sử dụng API URL WHATWG
Phần trăm mã hóa 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 [
90] và các ký tự sau sẽ tự động được thoát trong thuộc tính của đối tượng URLconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
< > " ` \r \n \t { } | \ ^ '
Ví dụ: ký tự khoảng trắng ASCII [
90] được mã hóa thànhconst pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
92. Ký tự dấu gạch chéo về phía trước ASCII [const pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${hash}`];
49] được mã hóa thànhconst myURL = new URL['//example.org']; myURL.pathname = '/a/b/c'; myURL.search = '?d=e'; myURL.hash = '#fgh';
94const pathname = '/a/b/c'; const search = '?d=e'; const hash = '#fgh'; const myURL = new URL[`//example.org${pathname}${search}${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. 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