url.username


获取和设置网址的用户名部分。

¥Gets and sets the username portion of the URL.

const myURL = new URL('https://abc:xyz@example.com');
console.log(myURL.username);
// Prints abc

myURL.username = '123';
console.log(myURL.href);
// Prints https://123:xyz@example.com/ 

分配给 username 属性的值中出现的任何无效 URL 字符都将为 percent-encoded。选择要进行百分比编码的字符可能与 url.parse()url.format() 方法产生的结果有所不同。

¥Any invalid URL characters appearing in the value assigned the username property will be percent-encoded. The selection of which characters to percent-encode may vary somewhat from what the url.parse() and url.format() methods would produce.