3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
getURLProps.js 842 Bytes
一键复制 编辑 原始数据 按行查看 历史
import _getURLPattern from './_getURLPattern'
/**
* 解析 URL 地址中的相关属性,返回解析后的对象数据
* @method getURLProps
* @since 1.4.0
* @param {String} url
* @return {Object}
*/
const getURLProps = (url = location.href) => {
const pattern = _getURLPattern()
const matches = pattern.exec(url)
const protocol = matches[1] ? matches[1].replace(':', '') : ''
const host = matches[5]
return {
protocol,
username: matches[3] || '',
password: matches[4] || '',
hostname: matches[6],
port: matches[13] ? matches[13].replace(':', '') : '',
host: matches[5],
pathname: matches[15],
search: matches[17] || '',
path: matches[14],
hash: matches[18] || '',
href: url,
origin: protocol + '://' + host
}
}
export default getURLProps
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助