Skip to content

@longmo-utils/common / IURL

Interface: IURL

urlParse 解析返回类型

Properties

PropertyTypeDescription
hash?stringhash字符串 Example 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<string, string | undefined>hash的查询字符串对象 Example 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?stringhost Example 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?stringhostname Example 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?stringhref Example 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?stringorigin Example 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?stringpassword Example 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?stringpathname Example 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?stringport Example const urlStr = 'https://mydomain.com:80/svn/Repos/' const url = urlParse(urlStr) console.log(url.port); // Logs: '80'
protocol?stringprotocol Example const urlStr = 'https://mydomain.com:80/svn/Repos/' const url = urlParse(urlStr) console.log(url.protocol); // Logs: 'https'
search?string查询字符串 Example { search: "?foo=1&bar=a/" }
searchObject?Record<string, string | undefined>searchObject Example 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'
username?stringorigin Example 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' // }

Released under the MIT License.