-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
132 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,39 @@ | ||
let bom = { | ||
queryString: { | ||
get: function(name){ | ||
let getAll = (searchString)=>{ | ||
get: function(name) { | ||
let getAll = searchString => { | ||
let query = searchString.replace(/^\?/, '') | ||
let queryObject = {} | ||
let queryArray = query.split('&').filter((i)=>i) | ||
.forEach((string,index)=>{ | ||
let parts = string.split('=') | ||
queryObject[parts[0]] = decodeURIComponent(parts[1]) | ||
}) | ||
let queryObject = {} | ||
let queryArray = query.split('&').filter(i => i).forEach((string, index) => { | ||
let parts = string.split('=') | ||
queryObject[parts[0]] = decodeURIComponent(parts[1]) | ||
}) | ||
return queryObject | ||
} | ||
if(arguments.length === 0){ | ||
if (arguments.length === 0) { | ||
return getAll(location.search) | ||
}else{ | ||
} else { | ||
return getAll(location.search)[name] | ||
} | ||
}, | ||
set: function(name, value){ | ||
let set = (search, name,value)=>{ | ||
let regex = new RegExp(`(${encodeURIComponent(name)})=([^&]*)`,'') | ||
if(regex.test(search)){ | ||
return search.replace(regex, (match,c1, c2)=> `${c1}=${encodeURIComponent(value)}`) | ||
}else{ | ||
set: function(name, value) { | ||
let set = (search, name, value) => { | ||
let regex = new RegExp(`(${encodeURIComponent(name)})=([^&]*)`, '') | ||
if (regex.test(search)) { | ||
return search.replace(regex, (match, c1, c2) => `${c1}=${encodeURIComponent(value)}`) | ||
} else { | ||
return search.replace(/&?$/, `&${encodeURIComponent(name)}=${encodeURIComponent(value)}`) | ||
} | ||
} | ||
if(arguments.length === 1 && typeof name === 'object' && name !== null){ | ||
if (arguments.length === 1 && typeof name === 'object' && name !== null) { | ||
let search = location.search | ||
for(let key in arguments[0]){ | ||
for (let key in arguments[0]) { | ||
search = set(search, key, arguments[0][key]) | ||
} | ||
location.search = search | ||
}else{ | ||
location.search = set(location.search, name,value) | ||
} else { | ||
location.search = set(location.search, name, value) | ||
} | ||
}, | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.