Skip to content

Commit

Permalink
Update 将一段 url 字符串解析为 Object.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Rain120 authored May 22, 2018
1 parent 50e2bc0 commit 78dffff
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions 将一段 url 字符串解析为 Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ function parseUrl(url) {
host: a.hostname,
port: a.port,
query: a.search,
params: (function(){
var ret = {},
seg = a.search.replace(/^\?/,'').split('&'),
len = seg.length, i = 0, s;
for (;i<len;i++) {
if (!seg[i]) { continue; }
s = seg[i].split('=');
ret[s[0]] = s[1];
params: (() => {
var ret = {}, querys = [];
var searchQuery = a.search.replace(/^\?/,'').split('&');
for ( var i = 0;i < searchQuery.length; i++) {
if (searchQuery[i]) {
querys = searchQuery[i].split('=');
ret[querys[0]] = querys[1];
}
}
return ret;
})(),
})(),
file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
hash: a.hash.replace('#',''),
path: a.pathname.replace(/^([^\/])/,'/$1'),
Expand Down

0 comments on commit 78dffff

Please sign in to comment.