Appearance
@longmo-utils/common / IURL
urlParse 解析返回类型
hash?
string
const urlStr = 'https://www.baidu.com/path1/path2?foo=1&bar=a/#/hashpath1/hashpath2?hashfoo=1&hashbar=a' const url = urlParse(urlStr) console.log(url.hash); // Logs: '#/hashpath1/hashpath2?hashfoo=1&hashbar=a'
hashSearchObject?
Record
undefined
const urlStr = 'https://www.baidu.com/path1/path2?foo=1&bar=a/#/hashpath1/hashpath2?hashfoo=1&hashbar=a' const url = urlParse(urlStr) console.log(url.hashSearchObject); // Logs: { // hashfoo: '1', // hashbar: 'a' // }
host?
const urlStr = 'https://www.baidu.com/path1/path2?foo=1&bar=a/#/hashpath1/hashpath2?hashfoo=1&hashbar=a' const url = urlParse(urlStr) console.log(url.host); // Logs: 'www.baidu.com'
hostname?
const urlStr = 'https://www.baidu.com/path1/path2?foo=1&bar=a/#/hashpath1/hashpath2?hashfoo=1&hashbar=a' const url = urlParse(urlStr) console.log(url.hostname); // Logs: 'www.baidu.com'
href?
const urlStr = 'https://www.baidu.com/path1/path2?foo=1&bar=a/#/hashpath1/hashpath2?hashfoo=1&hashbar=a' const url = urlParse(urlStr) console.log(url.href); // Logs: 'https://www.baidu.com/path1/path2?foo=1&bar=a/#/hashpath1/hashpath2?hashfoo=1&hashbar=a'
origin?
const urlStr = 'https://www.baidu.com/path1/path2?foo=1&bar=a/#/hashpath1/hashpath2?hashfoo=1&hashbar=a' const url = urlParse(urlStr) console.log(url.origin); // Logs: 'https://www.baidu.com'
password?
const urlStr = 'https://anonymous:flabada@developer.mozilla.org/en-US/docs/Web/API/URL/username' const url = urlParse(urlStr) console.log(url.password) // Logs "flabada"
pathname?
const urlStr = 'https://www.baidu.com/path1/path2?foo=1&bar=a/#/hashpath1/hashpath2?hashfoo=1&hashbar=a' const url = urlParse(urlStr) console.log(url.pathname); // Logs: '/path1/path2'
port?
const urlStr = 'https://mydomain.com:80/svn/Repos/' const url = urlParse(urlStr) console.log(url.port); // Logs: '80'
protocol?
const urlStr = 'https://mydomain.com:80/svn/Repos/' const url = urlParse(urlStr) console.log(url.protocol); // Logs: 'https'
search?
{ search: "?foo=1&bar=a/" }
searchObject?
username?
const urlStr = 'https://anonymous:flabada@developer.mozilla.org/en-US/docs/Web/API/URL/username' const url = urlParse(urlStr) console.log(url.username) // Logs: { // foo: '1', // bar: 'a' // }